Persist the show-type filter in the path via a /series prefix: movies keep bare URLs, series use /series across random, popular, top, favorites and watchlist. The path is the single source of truth - the jotai atom is removed and the toggle navigates with router.replace so the server prefetches the target variant. Legacy ?type=tv deep links redirect to the prefixed URLs. Trending and similar/recommendations queries are now paginated and feed useInfiniteList like the main lists. Gallery wires fetchNextPage to a new ScrollNavigation onEndReached callback (fires within two slides of the end, once per approach), so all gallery tabs load more on scroll. The show page prefetches the first similar page with prefetchInfiniteQuery, and trending/similar/recommendations are added to the analytics ListName.
58 lines
1.9 KiB
TypeScript
58 lines
1.9 KiB
TypeScript
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
import { Metadata } from 'next';
|
|
import Link from 'next/link';
|
|
import { redirect } from 'next/navigation';
|
|
|
|
import JsonLd from '@/components/JsonLd';
|
|
import randomQuery, { generatePage } from '@/data/queries/random';
|
|
import { SITE_URL, TITLE } from '@/env';
|
|
import getQueryClient from '@/lib/queryClient';
|
|
|
|
import Container from './container';
|
|
|
|
interface SearchParams {
|
|
type?: string;
|
|
}
|
|
|
|
export const metadata: Metadata = {
|
|
alternates: { canonical: '/' }
|
|
};
|
|
|
|
const Random = async ({ searchParams }: { searchParams: SearchParams }) => {
|
|
if (searchParams.type === 'tv') redirect('/series');
|
|
|
|
const queryClient = getQueryClient();
|
|
|
|
const page = generatePage('movie');
|
|
|
|
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type: 'movie' }));
|
|
|
|
return (
|
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
|
<JsonLd data={{ '@context': 'https://schema.org', '@type': 'WebSite', name: TITLE, url: SITE_URL }} />
|
|
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
|
|
<Container page={page} type='movie' />
|
|
<section className='sr-only'>
|
|
<h2>Discover your next favorite movie</h2>
|
|
<p>
|
|
{TITLE} helps you decide what to watch: spin through random movie and series recommendations right on this
|
|
page, browse the{' '}
|
|
<Link className='underline underline-offset-2' href='/popular'>
|
|
most popular movies
|
|
</Link>{' '}
|
|
everyone is talking about, or dive into the{' '}
|
|
<Link className='underline underline-offset-2' href='/top'>
|
|
top-rated films
|
|
</Link>{' '}
|
|
of all time. Open any title to see its rating, overview, cast, and similar shows — and keep favorites and a
|
|
watchlist so you never lose track of what to watch next.
|
|
</p>
|
|
</section>
|
|
</HydrationBoundary>
|
|
);
|
|
};
|
|
|
|
export const revalidate = 1;
|
|
|
|
export default Random;
|