feat(show-type): path-based /series filter and infinite trending galleries
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.
This commit is contained in:
1 parent
0824090c6d
commit
f22f3c45b4
31 files changed
+372
-229
No files matched your search
@@ -1,12 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import useTop from './useTop';
|
||||
|
||||
const Container = () => {
|
||||
const { shows, fetchNextPage, isFetched } = useTop();
|
||||
const Container: FC<{ type: Show['type'] }> = ({ type }) => {
|
||||
const { shows, fetchNextPage, isFetched } = useTop(type);
|
||||
|
||||
if (isFetched && !shows.length) return <NoResults />;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import JsonLd from '@/components/JsonLd';
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import { itemList } from '@/lib/jsonLd';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
const TopContent = async ({ type }: { type: Show['type'] }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const query = popularQuery({ sortBy: 'vote_average.desc', type });
|
||||
|
||||
await queryClient.prefetchInfiniteQuery(query);
|
||||
|
||||
const shows = queryClient
|
||||
.getQueryData<{ pages: Pagination<Show>[] }>(query.queryKey)
|
||||
?.pages.flatMap(({ results }) => results);
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
{Boolean(shows?.length) && <JsonLd data={itemList(shows!)} />}
|
||||
<h1 className='sr-only'>{type === 'tv' ? 'Top Rated Series' : 'Top Rated Movies'}</h1>
|
||||
<Container type={type} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default TopContent;
|
||||
+25
-54
@@ -1,68 +1,39 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import JsonLd from '@/components/JsonLd';
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import { TITLE } from '@/env';
|
||||
import { itemList } from '@/lib/jsonLd';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
import { parseShowType } from '@/lib/showType';
|
||||
|
||||
import Container from './container';
|
||||
import TopContent from './content';
|
||||
|
||||
const HEADING = 'Top Rated Movies';
|
||||
|
||||
const DESCRIPTION = `Discover the top-rated movies on ${TITLE}. Find the highest-rated films and make informed viewing choices.`;
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `${HEADING} | ${TITLE}`,
|
||||
description: DESCRIPTION,
|
||||
alternates: { canonical: '/top' },
|
||||
openGraph: {
|
||||
type: 'website',
|
||||
siteName: TITLE,
|
||||
title: HEADING,
|
||||
description: DESCRIPTION,
|
||||
url: '/top'
|
||||
},
|
||||
twitter: {
|
||||
title: HEADING,
|
||||
description: DESCRIPTION
|
||||
}
|
||||
};
|
||||
|
||||
interface SearchParams {
|
||||
type?: string;
|
||||
}
|
||||
|
||||
const heading = (type: Show['type']) => (type === 'tv' ? 'Top Rated Series' : 'Top Rated Movies');
|
||||
|
||||
const description = (type: Show['type']) =>
|
||||
type === 'tv'
|
||||
? `Discover the top-rated series on ${TITLE}. Find the highest-rated shows and make informed viewing choices.`
|
||||
: `Discover the top-rated movies on ${TITLE}. Find the highest-rated films and make informed viewing choices.`;
|
||||
|
||||
export const generateMetadata = ({ searchParams }: { searchParams: SearchParams }): Metadata => {
|
||||
const type = parseShowType(searchParams.type);
|
||||
const title = heading(type);
|
||||
const text = description(type);
|
||||
|
||||
return {
|
||||
title: `${title} | ${TITLE}`,
|
||||
description: text,
|
||||
alternates: { canonical: '/top' },
|
||||
openGraph: {
|
||||
type: 'website',
|
||||
siteName: TITLE,
|
||||
title,
|
||||
description: text,
|
||||
url: '/top'
|
||||
},
|
||||
twitter: {
|
||||
title,
|
||||
description: text
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const Top = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||
const queryClient = getQueryClient();
|
||||
if (searchParams.type === 'tv') redirect('/series/top');
|
||||
|
||||
const type = parseShowType(searchParams.type);
|
||||
const query = popularQuery({ sortBy: 'vote_average.desc', type });
|
||||
|
||||
await queryClient.prefetchInfiniteQuery(query);
|
||||
|
||||
const shows = queryClient
|
||||
.getQueryData<{ pages: Pagination<Show>[] }>(query.queryKey)
|
||||
?.pages.flatMap(({ results }) => results);
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
{Boolean(shows?.length) && <JsonLd data={itemList(shows!)} />}
|
||||
<h1 className='sr-only'>{heading(type)}</h1>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
return <TopContent type='movie' />;
|
||||
};
|
||||
|
||||
export const revalidate = 3600;
|
||||
|
||||
@@ -1,19 +1,9 @@
|
||||
'use client';
|
||||
|
||||
import { useAtomValue } from 'jotai';
|
||||
|
||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
const useTop = () => {
|
||||
const showType = useAtomValue(showTypeAtom);
|
||||
|
||||
return useInfiniteList({
|
||||
...popularQuery({ sortBy: 'vote_average.desc', type: showType }),
|
||||
mode: 'default',
|
||||
list: 'top'
|
||||
});
|
||||
};
|
||||
const useTop = (type: Show['type']) =>
|
||||
useInfiniteList({ ...popularQuery({ sortBy: 'vote_average.desc', type }), mode: 'default', list: 'top' });
|
||||
|
||||
export default useTop;
|
||||
Reference in new issue
Block a user