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,26 +1,24 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
|
|
||||||
import List from '@/components/List';
|
import List from '@/components/List';
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import useUsersShows from '@/hooks/useUsersShows';
|
import useUsersShows from '@/hooks/useUsersShows';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
list: 'favorite' | 'watchlist';
|
list: 'favorite' | 'watchlist';
|
||||||
label: string;
|
label: string;
|
||||||
|
type: Show['type'];
|
||||||
session?: string;
|
session?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UsersList: FC<Props> = ({ list, label, session }) => {
|
const UsersList: FC<Props> = ({ list, label, type, session }) => {
|
||||||
const showType = useAtomValue(showTypeAtom);
|
const { shows, fetchNextPage, isFetched } = useUsersShows({ list, showType: type, session, mode: 'default' });
|
||||||
const { shows, fetchNextPage, isFetched } = useUsersShows({ list, showType, session, mode: 'default' });
|
|
||||||
|
|
||||||
if (isFetched && !shows.length) {
|
if (isFetched && !shows.length) {
|
||||||
return (
|
return (
|
||||||
<div className='flex h-40 w-full items-center justify-center text-center text-xl text-muted-foreground'>
|
<div className='flex h-40 w-full items-center justify-center text-center text-xl text-muted-foreground'>
|
||||||
There are no {showType === 'tv' ? 'series' : 'movies'} in your {label}
|
There are no {type === 'tv' ? 'series' : 'movies'} in your {label}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { TITLE } from '@/env';
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
@@ -10,11 +11,17 @@ export const metadata: Metadata = {
|
|||||||
robots: { index: false }
|
robots: { index: false }
|
||||||
};
|
};
|
||||||
|
|
||||||
const Favorites = () => {
|
interface SearchParams {
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Favorites = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||||
|
if (searchParams.type === 'tv') redirect('/series/favorites');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className='sr-only'>My Favorite Shows</h1>
|
<h1 className='sr-only'>My Favorite Shows</h1>
|
||||||
<UsersList list='favorite' label='favorites' />
|
<UsersList list='favorite' label='favorites' type='movie' />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { TITLE } from '@/env';
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
@@ -10,11 +11,17 @@ export const metadata: Metadata = {
|
|||||||
robots: { index: false }
|
robots: { index: false }
|
||||||
};
|
};
|
||||||
|
|
||||||
const WatchList = async () => {
|
interface SearchParams {
|
||||||
|
type?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const WatchList = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||||
|
if (searchParams.type === 'tv') redirect('/series/watchlist');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1 className='sr-only'>My Watchlist</h1>
|
<h1 className='sr-only'>My Watchlist</h1>
|
||||||
<UsersList list='watchlist' label='watchlist' />
|
<UsersList list='watchlist' label='watchlist' type='movie' />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, useRef } from 'react';
|
import { FC } from 'react';
|
||||||
import { useAtom } from 'jotai';
|
|
||||||
|
|
||||||
import Preview from '@/components/Preview';
|
import Preview from '@/components/Preview';
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import Trending from '@/components/Trending';
|
import Trending from '@/components/Trending';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { generatePage } from '@/data/queries/random';
|
|
||||||
|
|
||||||
import Carousel from './components/Carousel';
|
import Carousel from './components/Carousel';
|
||||||
import useRandomMovie from './useRandomMovie';
|
import useRandomMovie from './useRandomMovie';
|
||||||
@@ -18,20 +15,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Container: FC<Props> = ({ page, type }) => {
|
const Container: FC<Props> = ({ page, type }) => {
|
||||||
const [showType] = useAtom(showTypeAtom);
|
const { show, shows, onIndexChange, fetchNextPage } = useRandomMovie({ page, type });
|
||||||
const pagesRef = useRef<Record<Show['type'], number>>();
|
|
||||||
|
|
||||||
if (!pagesRef.current) {
|
|
||||||
pagesRef.current = {
|
|
||||||
movie: type === 'movie' ? page : generatePage('movie'),
|
|
||||||
tv: type === 'tv' ? page : generatePage('tv')
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const { show, shows, onIndexChange, fetchNextPage, isLoading } = useRandomMovie({
|
|
||||||
page: pagesRef.current[showType],
|
|
||||||
type: showType
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex flex-1 flex-col'>
|
<div className='flex flex-1 flex-col'>
|
||||||
@@ -40,9 +24,7 @@ const Container: FC<Props> = ({ page, type }) => {
|
|||||||
<Preview
|
<Preview
|
||||||
show={show}
|
show={show}
|
||||||
className='rounded-md bg-background'
|
className='rounded-md bg-background'
|
||||||
poster={
|
poster={<Carousel key={type} shows={shows} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||||
<Carousel key={showType} shows={shows} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Skeleton className='card-aspect-ratio static-aspect-ratio mx-auto rounded-lg' />
|
<Skeleton className='card-aspect-ratio static-aspect-ratio mx-auto rounded-lg' />
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||||
import { Metadata } from 'next';
|
import { Metadata } from 'next';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import JsonLd from '@/components/JsonLd';
|
import JsonLd from '@/components/JsonLd';
|
||||||
import randomQuery, { generatePage } from '@/data/queries/random';
|
import randomQuery, { generatePage } from '@/data/queries/random';
|
||||||
import { SITE_URL, TITLE } from '@/env';
|
import { SITE_URL, TITLE } from '@/env';
|
||||||
import getQueryClient from '@/lib/queryClient';
|
import getQueryClient from '@/lib/queryClient';
|
||||||
import { parseShowType } from '@/lib/showType';
|
|
||||||
|
|
||||||
import Container from './container';
|
import Container from './container';
|
||||||
|
|
||||||
@@ -19,18 +19,19 @@ export const metadata: Metadata = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Random = async ({ searchParams }: { searchParams: SearchParams }) => {
|
const Random = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||||
|
if (searchParams.type === 'tv') redirect('/series');
|
||||||
|
|
||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
const type = parseShowType(searchParams.type);
|
const page = generatePage('movie');
|
||||||
const page = generatePage(type);
|
|
||||||
|
|
||||||
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type }));
|
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type: 'movie' }));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
<JsonLd data={{ '@context': 'https://schema.org', '@type': 'WebSite', name: TITLE, url: SITE_URL }} />
|
<JsonLd data={{ '@context': 'https://schema.org', '@type': 'WebSite', name: TITLE, url: SITE_URL }} />
|
||||||
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
|
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
|
||||||
<Container page={page} type={type} />
|
<Container page={page} type='movie' />
|
||||||
<section className='sr-only'>
|
<section className='sr-only'>
|
||||||
<h2>Discover your next favorite movie</h2>
|
<h2>Discover your next favorite movie</h2>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export const createShowPage = (showType: Show['type']) => {
|
|||||||
|
|
||||||
if (decodeURIComponent(`/${showType}/${id}`) !== path) permanentRedirect(path);
|
if (decodeURIComponent(`/${showType}/${id}`) !== path) permanentRedirect(path);
|
||||||
|
|
||||||
await queryClient.prefetchQuery(similarQuery({ showId, showType, type: 'similar' }));
|
await queryClient.prefetchInfiniteQuery(similarQuery({ showId, showType, type: 'similar' }));
|
||||||
|
|
||||||
const jsonLd = {
|
const jsonLd = {
|
||||||
'@context': 'https://schema.org',
|
'@context': 'https://schema.org',
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
import List from '@/components/List';
|
import List from '@/components/List';
|
||||||
import NoResults from '@/components/NoResults';
|
import NoResults from '@/components/NoResults';
|
||||||
|
|
||||||
import usePopular from './usePopular';
|
import usePopular from './usePopular';
|
||||||
|
|
||||||
const Container = () => {
|
const Container: FC<{ type: Show['type'] }> = ({ type }) => {
|
||||||
const { shows, fetchNextPage, isFetched } = usePopular();
|
const { shows, fetchNextPage, isFetched } = usePopular(type);
|
||||||
|
|
||||||
if (isFetched && !shows.length) return <NoResults />;
|
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 PopularContent = async ({ type }: { type: Show['type'] }) => {
|
||||||
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
|
const query = popularQuery({ 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' ? 'Popular Series' : 'Popular Movies'}</h1>
|
||||||
|
<Container type={type} />
|
||||||
|
</HydrationBoundary>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PopularContent;
|
||||||
+25
-54
@@ -1,68 +1,39 @@
|
|||||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
|
||||||
import { Metadata } from 'next';
|
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 { TITLE } from '@/env';
|
||||||
import { itemList } from '@/lib/jsonLd';
|
|
||||||
import getQueryClient from '@/lib/queryClient';
|
|
||||||
import { parseShowType } from '@/lib/showType';
|
|
||||||
|
|
||||||
import Container from './container';
|
import PopularContent from './content';
|
||||||
|
|
||||||
|
const HEADING = 'Popular Movies';
|
||||||
|
|
||||||
|
const DESCRIPTION = `Check out the most popular movies right now on ${TITLE}. See what’s trending and don’t miss out on the latest hits.`;
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: `${HEADING} | ${TITLE}`,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
alternates: { canonical: '/popular' },
|
||||||
|
openGraph: {
|
||||||
|
type: 'website',
|
||||||
|
siteName: TITLE,
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
url: '/popular'
|
||||||
|
},
|
||||||
|
twitter: {
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
interface SearchParams {
|
interface SearchParams {
|
||||||
type?: string;
|
type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const heading = (type: Show['type']) => (type === 'tv' ? 'Popular Series' : 'Popular Movies');
|
|
||||||
|
|
||||||
const description = (type: Show['type']) =>
|
|
||||||
type === 'tv'
|
|
||||||
? `Check out the most popular series right now on ${TITLE}. See what’s trending and don’t miss out on the latest hits.`
|
|
||||||
: `Check out the most popular movies right now on ${TITLE}. See what’s trending and don’t miss out on the latest hits.`;
|
|
||||||
|
|
||||||
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: '/popular' },
|
|
||||||
openGraph: {
|
|
||||||
type: 'website',
|
|
||||||
siteName: TITLE,
|
|
||||||
title,
|
|
||||||
description: text,
|
|
||||||
url: '/popular'
|
|
||||||
},
|
|
||||||
twitter: {
|
|
||||||
title,
|
|
||||||
description: text
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const Popular = async ({ searchParams }: { searchParams: SearchParams }) => {
|
const Popular = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||||
const queryClient = getQueryClient();
|
if (searchParams.type === 'tv') redirect('/series/popular');
|
||||||
|
|
||||||
const type = parseShowType(searchParams.type);
|
return <PopularContent type='movie' />;
|
||||||
const query = popularQuery({ 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>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const revalidate = 3600;
|
export const revalidate = 3600;
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
|
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import popularQuery from '@/data/queries/popular';
|
import popularQuery from '@/data/queries/popular';
|
||||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||||
|
|
||||||
const usePopular = () => {
|
const usePopular = (type: Show['type']) =>
|
||||||
const showType = useAtomValue(showTypeAtom);
|
useInfiniteList({ ...popularQuery({ type }), mode: 'default', list: 'popular' });
|
||||||
|
|
||||||
return useInfiniteList({ ...popularQuery({ type: showType }), mode: 'default', list: 'popular' });
|
|
||||||
};
|
|
||||||
|
|
||||||
export default usePopular;
|
export default usePopular;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import UsersList from '@/app/(site)/(favorites)/components/UsersLists';
|
||||||
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: `My Favorite Shows | ${TITLE}`,
|
||||||
|
description: `View your favorite shows on ${TITLE}. Keep track of films you’ve added and revisit your top picks anytime.`,
|
||||||
|
robots: { index: false }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Favorites = () => (
|
||||||
|
<>
|
||||||
|
<h1 className='sr-only'>My Favorite Shows</h1>
|
||||||
|
<UsersList list='favorite' label='favorites' type='tv' />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default Favorites;
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import Container from '@/app/(site)/(root)/container';
|
||||||
|
import randomQuery, { generatePage } from '@/data/queries/random';
|
||||||
|
import { TITLE } from '@/env';
|
||||||
|
import getQueryClient from '@/lib/queryClient';
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
alternates: { canonical: '/series' }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Series = async () => {
|
||||||
|
const queryClient = getQueryClient();
|
||||||
|
|
||||||
|
const page = generatePage('tv');
|
||||||
|
|
||||||
|
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type: 'tv' }));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||||
|
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Series</h1>
|
||||||
|
<Container page={page} type='tv' />
|
||||||
|
</HydrationBoundary>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const revalidate = 1;
|
||||||
|
|
||||||
|
export default Series;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import PopularContent from '@/app/(site)/popular/content';
|
||||||
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
|
const HEADING = 'Popular Series';
|
||||||
|
|
||||||
|
const DESCRIPTION = `Check out the most popular series right now on ${TITLE}. See what’s trending and don’t miss out on the latest hits.`;
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: `${HEADING} | ${TITLE}`,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
alternates: { canonical: '/series/popular' },
|
||||||
|
openGraph: {
|
||||||
|
type: 'website',
|
||||||
|
siteName: TITLE,
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
url: '/series/popular'
|
||||||
|
},
|
||||||
|
twitter: {
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Popular = () => <PopularContent type='tv' />;
|
||||||
|
|
||||||
|
export const revalidate = 3600;
|
||||||
|
|
||||||
|
export default Popular;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import TopContent from '@/app/(site)/top/content';
|
||||||
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
|
const HEADING = 'Top Rated Series';
|
||||||
|
|
||||||
|
const DESCRIPTION = `Discover the top-rated series on ${TITLE}. Find the highest-rated shows and make informed viewing choices.`;
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: `${HEADING} | ${TITLE}`,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
alternates: { canonical: '/series/top' },
|
||||||
|
openGraph: {
|
||||||
|
type: 'website',
|
||||||
|
siteName: TITLE,
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION,
|
||||||
|
url: '/series/top'
|
||||||
|
},
|
||||||
|
twitter: {
|
||||||
|
title: HEADING,
|
||||||
|
description: DESCRIPTION
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Top = () => <TopContent type='tv' />;
|
||||||
|
|
||||||
|
export const revalidate = 3600;
|
||||||
|
|
||||||
|
export default Top;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
import UsersList from '@/app/(site)/(favorites)/components/UsersLists';
|
||||||
|
import { TITLE } from '@/env';
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: `My watchlist | ${TITLE}`,
|
||||||
|
description: `View your favorite shows on ${TITLE}. Keep track of films you’ve added and revisit your top picks anytime.`,
|
||||||
|
robots: { index: false }
|
||||||
|
};
|
||||||
|
|
||||||
|
const WatchList = () => (
|
||||||
|
<>
|
||||||
|
<h1 className='sr-only'>My Watchlist</h1>
|
||||||
|
<UsersList list='watchlist' label='watchlist' type='tv' />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
export default WatchList;
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
import List from '@/components/List';
|
import List from '@/components/List';
|
||||||
import NoResults from '@/components/NoResults';
|
import NoResults from '@/components/NoResults';
|
||||||
|
|
||||||
import useTop from './useTop';
|
import useTop from './useTop';
|
||||||
|
|
||||||
const Container = () => {
|
const Container: FC<{ type: Show['type'] }> = ({ type }) => {
|
||||||
const { shows, fetchNextPage, isFetched } = useTop();
|
const { shows, fetchNextPage, isFetched } = useTop(type);
|
||||||
|
|
||||||
if (isFetched && !shows.length) return <NoResults />;
|
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 { Metadata } from 'next';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import JsonLd from '@/components/JsonLd';
|
|
||||||
import popularQuery from '@/data/queries/popular';
|
|
||||||
import { TITLE } from '@/env';
|
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 {
|
interface SearchParams {
|
||||||
type?: string;
|
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 Top = async ({ searchParams }: { searchParams: SearchParams }) => {
|
||||||
const queryClient = getQueryClient();
|
if (searchParams.type === 'tv') redirect('/series/top');
|
||||||
|
|
||||||
const type = parseShowType(searchParams.type);
|
return <TopContent type='movie' />;
|
||||||
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>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const revalidate = 3600;
|
export const revalidate = 3600;
|
||||||
|
|||||||
@@ -1,19 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
|
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import popularQuery from '@/data/queries/popular';
|
import popularQuery from '@/data/queries/popular';
|
||||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||||
|
|
||||||
const useTop = () => {
|
const useTop = (type: Show['type']) =>
|
||||||
const showType = useAtomValue(showTypeAtom);
|
useInfiniteList({ ...popularQuery({ sortBy: 'vote_average.desc', type }), mode: 'default', list: 'top' });
|
||||||
|
|
||||||
return useInfiniteList({
|
|
||||||
...popularQuery({ sortBy: 'vote_average.desc', type: showType }),
|
|
||||||
mode: 'default',
|
|
||||||
list: 'top'
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default useTop;
|
export default useTop;
|
||||||
@@ -1,27 +1,21 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
|
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
import { Menu } from 'lucide-react';
|
import { Menu } from 'lucide-react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
|
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||||
import Nav from '@/components/ui/nav';
|
import Nav from '@/components/ui/nav';
|
||||||
|
import { showTypeFromPath, toShowTypePath } from '@/lib/showType';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import { paths } from './constants';
|
import { paths } from './constants';
|
||||||
|
|
||||||
const TYPE_AWARE_PATHS = ['/', '/popular', '/top', '/favorites', '/watchlist'];
|
|
||||||
|
|
||||||
const withShowType = (path: string, type: Show['type']) =>
|
|
||||||
type === 'tv' && TYPE_AWARE_PATHS.includes(path) ? `${path}?type=tv` : path;
|
|
||||||
|
|
||||||
export const MobileNavigation = () => {
|
export const MobileNavigation = () => {
|
||||||
const currentPath = usePathname();
|
const currentPath = usePathname();
|
||||||
const showType = useAtomValue(showTypeAtom);
|
const showType = showTypeFromPath(currentPath);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex md:hidden'>
|
<div className='flex md:hidden'>
|
||||||
@@ -34,9 +28,12 @@ export const MobileNavigation = () => {
|
|||||||
<DropdownMenuContent className='flex w-44 flex-col gap-2 rounded-none rounded-bl-lg border-none p-2'>
|
<DropdownMenuContent className='flex w-44 flex-col gap-2 rounded-none rounded-bl-lg border-none p-2'>
|
||||||
{paths.map(({ path, title }) => (
|
{paths.map(({ path, title }) => (
|
||||||
<DropdownMenuItem key={path} asChild>
|
<DropdownMenuItem key={path} asChild>
|
||||||
<Link href={withShowType(path, showType)} prefetch={path !== '/'}>
|
<Link href={toShowTypePath(path, showType)} prefetch={path !== '/'}>
|
||||||
<div>
|
<div>
|
||||||
<Button className='relative w-full' variant={currentPath === path ? 'default' : 'outline'}>
|
<Button
|
||||||
|
className='relative w-full'
|
||||||
|
variant={toShowTypePath(path, showType) === currentPath ? 'default' : 'outline'}
|
||||||
|
>
|
||||||
{title}
|
{title}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -51,13 +48,13 @@ export const MobileNavigation = () => {
|
|||||||
|
|
||||||
export const DesktopNavigation = () => {
|
export const DesktopNavigation = () => {
|
||||||
const currentPath = usePathname();
|
const currentPath = usePathname();
|
||||||
const showType = useAtomValue(showTypeAtom);
|
const showType = showTypeFromPath(currentPath);
|
||||||
const active = paths.find(({ path }) => path === currentPath);
|
const active = paths.find(({ path }) => toShowTypePath(path, showType) === currentPath);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Nav tabs={paths} active={active}>
|
<Nav tabs={paths} active={active}>
|
||||||
{({ path, title }) => (
|
{({ path, title }) => (
|
||||||
<Link href={withShowType(path, showType)} prefetch={path !== '/'}>
|
<Link href={toShowTypePath(path, showType)} prefetch={path !== '/'}>
|
||||||
<div>{title}</div>
|
<div>{title}</div>
|
||||||
</Link>
|
</Link>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
import { ChangeEvent, MutableRefObject, useRef, useState } from 'react';
|
import { ChangeEvent, MutableRefObject, useRef, useState } from 'react';
|
||||||
import { create } from 'react-modal-promise';
|
import { create } from 'react-modal-promise';
|
||||||
import { useAtomValue } from 'jotai';
|
|
||||||
import { Search as SearchIcon, X } from 'lucide-react';
|
import { Search as SearchIcon, X } from 'lucide-react';
|
||||||
|
import { usePathname } from 'next/navigation';
|
||||||
|
|
||||||
import List from '@/components/List';
|
import List from '@/components/List';
|
||||||
import { showTypeAtom } from '@/components/ShowTypeToggle';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import ButtonsGroup from '@/components/ui/buttons-group';
|
import ButtonsGroup from '@/components/ui/buttons-group';
|
||||||
import { Modal } from '@/components/ui/dialog';
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import useDistinctUntilChanged from '@/hooks/useDistinctUntilChanged';
|
import useDistinctUntilChanged from '@/hooks/useDistinctUntilChanged';
|
||||||
|
import { showTypeFromPath } from '@/lib/showType';
|
||||||
|
|
||||||
import useSearch from './useSearch';
|
import useSearch from './useSearch';
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
|||||||
const scrollRef = useRef<HTMLDivElement>(null) as MutableRefObject<HTMLDivElement>;
|
const scrollRef = useRef<HTMLDivElement>(null) as MutableRefObject<HTMLDivElement>;
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
const isFetchedRef = useRef(false);
|
const isFetchedRef = useRef(false);
|
||||||
const showType = useAtomValue(showTypeAtom);
|
const showType = showTypeFromPath(usePathname());
|
||||||
|
|
||||||
const query = useDistinctUntilChanged(title);
|
const query = useDistinctUntilChanged(title);
|
||||||
const settledTitle = useDistinctUntilChanged(title, 1000);
|
const settledTitle = useDistinctUntilChanged(title, 1000);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ReactNode, useEffect, useState } from 'react';
|
import { ReactNode, useEffect, useRef, useState } from 'react';
|
||||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
@@ -11,6 +11,7 @@ interface Props<E extends HTMLElement> {
|
|||||||
iconClassName?: string;
|
iconClassName?: string;
|
||||||
slideWidth?: number;
|
slideWidth?: number;
|
||||||
gap?: number;
|
gap?: number;
|
||||||
|
onEndReached?: () => void;
|
||||||
children: ({
|
children: ({
|
||||||
setScrollElement,
|
setScrollElement,
|
||||||
isArrowHovered
|
isArrowHovered
|
||||||
@@ -28,9 +29,14 @@ function ScrollNavigation<E extends HTMLElement>({
|
|||||||
iconClassName,
|
iconClassName,
|
||||||
slideWidth: initialSlideWidth,
|
slideWidth: initialSlideWidth,
|
||||||
gap = 0,
|
gap = 0,
|
||||||
|
onEndReached,
|
||||||
children
|
children
|
||||||
}: Props<E>) {
|
}: Props<E>) {
|
||||||
const [scrollElement, setScrollElement] = useState<E | null>(null);
|
const [scrollElement, setScrollElement] = useState<E | null>(null);
|
||||||
|
const onEndReachedRef = useRef(onEndReached);
|
||||||
|
const endReachedFiredRef = useRef(false);
|
||||||
|
|
||||||
|
onEndReachedRef.current = onEndReached;
|
||||||
|
|
||||||
const [isShowBack, setIsShowBack] = useState(true);
|
const [isShowBack, setIsShowBack] = useState(true);
|
||||||
const [isShowNext, setIsShowNext] = useState(true);
|
const [isShowNext, setIsShowNext] = useState(true);
|
||||||
@@ -58,8 +64,22 @@ function ScrollNavigation<E extends HTMLElement>({
|
|||||||
const DELAY = 50;
|
const DELAY = 50;
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
|
const remaining = scrollElement.scrollWidth - (scrollElement.clientWidth + scrollElement.scrollLeft);
|
||||||
|
|
||||||
setIsShowBack(Boolean(scrollElement.scrollLeft));
|
setIsShowBack(Boolean(scrollElement.scrollLeft));
|
||||||
setIsShowNext(Boolean(scrollElement.scrollWidth - (scrollElement.clientWidth + scrollElement.scrollLeft)));
|
setIsShowNext(Boolean(remaining));
|
||||||
|
|
||||||
|
if (onEndReachedRef.current) {
|
||||||
|
const slide = scrollElement.firstChild as HTMLElement;
|
||||||
|
const threshold = (slide?.clientWidth ?? 0) * 2 || 300;
|
||||||
|
|
||||||
|
if (remaining <= threshold && !endReachedFiredRef.current) {
|
||||||
|
endReachedFiredRef.current = true;
|
||||||
|
onEndReachedRef.current();
|
||||||
|
} else if (remaining > threshold) {
|
||||||
|
endReachedFiredRef.current = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}, DELAY);
|
}, DELAY);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, useEffect } from 'react';
|
import { FC } from 'react';
|
||||||
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
||||||
import { atom, useAtom } from 'jotai';
|
|
||||||
import { Check, ChevronDown, Clapperboard, LucideIcon, Tv } from 'lucide-react';
|
import { Check, ChevronDown, Clapperboard, LucideIcon, Tv } from 'lucide-react';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { usePathname, useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import analytics from '@/lib/analytics';
|
import analytics from '@/lib/analytics';
|
||||||
import { parseShowType } from '@/lib/showType';
|
import { showTypeFromPath, toShowTypePath } from '@/lib/showType';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
export const showTypeAtom = atom<Show['type']>('movie');
|
|
||||||
|
|
||||||
interface Option {
|
interface Option {
|
||||||
value: Show['type'];
|
value: Show['type'];
|
||||||
label: string;
|
label: string;
|
||||||
@@ -28,24 +26,17 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ShowTypeToggle: FC<Props> = ({ className }) => {
|
const ShowTypeToggle: FC<Props> = ({ className }) => {
|
||||||
const [value, setValue] = useAtom(showTypeAtom);
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
useEffect(() => {
|
const value = showTypeFromPath(pathname);
|
||||||
const urlType = parseShowType(new URLSearchParams(window.location.search).get('type'));
|
|
||||||
|
|
||||||
if (urlType !== value) setValue(urlType);
|
|
||||||
}, [value, setValue]);
|
|
||||||
|
|
||||||
const current = options.find(({ value: optionValue }) => optionValue === value) ?? options[0];
|
const current = options.find(({ value: optionValue }) => optionValue === value) ?? options[0];
|
||||||
|
|
||||||
const handleChange = (next: Show['type']) => {
|
const handleChange = (next: Show['type']) => {
|
||||||
analytics.randomTypeChanged({ type: next });
|
if (next === value) return;
|
||||||
setValue(next);
|
|
||||||
|
|
||||||
const url = new URL(window.location.href);
|
analytics.randomTypeChanged({ type: next });
|
||||||
if (next === 'tv') url.searchParams.set('type', 'tv');
|
router.replace(toShowTypePath(pathname, next), { scroll: false });
|
||||||
else url.searchParams.delete('type');
|
|
||||||
window.history.replaceState(null, '', url);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -59,7 +50,7 @@ const ShowTypeToggle: FC<Props> = ({ className }) => {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Link
|
<Link
|
||||||
href={value === 'tv' ? '/?type=tv' : '/'}
|
href={toShowTypePath('/', value)}
|
||||||
onPointerDown={(event) => event.stopPropagation()}
|
onPointerDown={(event) => event.stopPropagation()}
|
||||||
onClick={(event) => event.stopPropagation()}
|
onClick={(event) => event.stopPropagation()}
|
||||||
className='pl-2.5 pr-1.5 text-[15px] font-normal leading-[18px]'
|
className='pl-2.5 pr-1.5 text-[15px] font-normal leading-[18px]'
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import { showPath } from '@/lib/utils';
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
shows: Show[];
|
shows: Show[];
|
||||||
|
onEndReached?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Gallery: FC<Props> = ({ shows }) => (
|
const Gallery: FC<Props> = ({ shows, onEndReached }) => (
|
||||||
<ScrollNavigation<HTMLUListElement>>
|
<ScrollNavigation<HTMLUListElement> onEndReached={onEndReached}>
|
||||||
{({ setScrollElement }) => (
|
{({ setScrollElement }) => (
|
||||||
<ul
|
<ul
|
||||||
ref={setScrollElement}
|
ref={setScrollElement}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ const Trending: FC<Props> = ({ showId, showType, preview }) => {
|
|||||||
}}
|
}}
|
||||||
className='mb-3'
|
className='mb-3'
|
||||||
/>
|
/>
|
||||||
{!tab.isPending && <Gallery key={active.type} shows={tab.data || []} />}
|
{tab.isFetched && <Gallery key={active.type} shows={tab.shows} onEndReached={tab.fetchNextPage} />}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import similarQuery from '@/data/queries/similar';
|
import similarQuery from '@/data/queries/similar';
|
||||||
|
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
showId: Show['id'];
|
showId: Show['id'];
|
||||||
@@ -12,6 +11,6 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const useSimilar = ({ showId, showType = 'movie', type = 'similar', enabled }: Props) =>
|
const useSimilar = ({ showId, showType = 'movie', type = 'similar', enabled }: Props) =>
|
||||||
useQuery({ ...similarQuery({ showId, showType, type }), enabled });
|
useInfiniteList({ ...similarQuery({ showId, showType, type }), mode: 'default', list: type, enabled });
|
||||||
|
|
||||||
export default useSimilar;
|
export default useSimilar;
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import trendingQuery, { TrendingQueryProps } from '@/data/queries/trending';
|
import trendingQuery, { TrendingQueryProps } from '@/data/queries/trending';
|
||||||
|
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||||
|
|
||||||
const useTrending = ({ type, enabled }: TrendingQueryProps) => useQuery(trendingQuery({ type, enabled }));
|
const useTrending = ({ type, enabled }: TrendingQueryProps) =>
|
||||||
|
useInfiniteList({ ...trendingQuery({ type, enabled }), mode: 'default', list: 'trending' });
|
||||||
|
|
||||||
export default useTrending;
|
export default useTrending;
|
||||||
@@ -9,14 +9,15 @@ export type SimilarQueryProps = {
|
|||||||
|
|
||||||
const similarQuery = ({ showId, showType, type }: SimilarQueryProps) => ({
|
const similarQuery = ({ showId, showType, type }: SimilarQueryProps) => ({
|
||||||
queryKey: [type, showId, showType],
|
queryKey: [type, showId, showType],
|
||||||
queryFn: () =>
|
initialPageParam: '1',
|
||||||
|
queryFn: ({ pageParam = '1' }: { pageParam?: string }) =>
|
||||||
movieAdvisor
|
movieAdvisor
|
||||||
.get<TMDBPagination<Movie> | TMDBPagination<Series>>(`/${showType}/${showId}/${type}`, {
|
.get<TMDBPagination<Movie> | TMDBPagination<Series>>(`/${showType}/${showId}/${type}`, {
|
||||||
params: {
|
params: {
|
||||||
page: 1
|
page: pageParam
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((response) => mapMoviesSeriesResponseToShows(response, showType).results)
|
.then((response) => mapMoviesSeriesResponseToShows(response, showType))
|
||||||
});
|
});
|
||||||
|
|
||||||
export default similarQuery;
|
export default similarQuery;
|
||||||
@@ -15,22 +15,26 @@ const TV_WATCH_PROVIDERS: Partial<Record<TrendingQueryProps['type'], number>> =
|
|||||||
const trendingQuery = ({ type, enabled }: TrendingQueryProps) => ({
|
const trendingQuery = ({ type, enabled }: TrendingQueryProps) => ({
|
||||||
enabled,
|
enabled,
|
||||||
queryKey: ['trending', `type-${type}`],
|
queryKey: ['trending', `type-${type}`],
|
||||||
queryFn: () => {
|
initialPageParam: '1',
|
||||||
|
queryFn: ({ pageParam = '1' }: { pageParam?: string }) => {
|
||||||
const provider = TV_WATCH_PROVIDERS[type];
|
const provider = TV_WATCH_PROVIDERS[type];
|
||||||
|
|
||||||
if (provider) {
|
if (provider) {
|
||||||
return movieAdvisor
|
return movieAdvisor
|
||||||
.get<TMDBPagination<Series>>('/discover/tv', {
|
.get<TMDBPagination<Series>>('/discover/tv', {
|
||||||
params: {
|
params: {
|
||||||
|
page: pageParam,
|
||||||
watch_region: 'US',
|
watch_region: 'US',
|
||||||
with_watch_monetization_types: 'flatrate',
|
with_watch_monetization_types: 'flatrate',
|
||||||
with_watch_providers: provider
|
with_watch_providers: provider
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((response) => mapMoviesSeriesResponseToShows(response, 'tv').results);
|
.then((response) => mapMoviesSeriesResponseToShows(response, 'tv'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const params: Record<string, string | number> = {};
|
const params: Record<string, string | number> = {
|
||||||
|
page: pageParam
|
||||||
|
};
|
||||||
|
|
||||||
if (type !== 'trending') {
|
if (type !== 'trending') {
|
||||||
params['watch_region'] = 'US';
|
params['watch_region'] = 'US';
|
||||||
@@ -48,11 +52,7 @@ const trendingQuery = ({ type, enabled }: TrendingQueryProps) => ({
|
|||||||
.get<TMDBPagination<Movie>>(type === 'trending' ? '/trending/movie/day' : '/discover/movie', {
|
.get<TMDBPagination<Movie>>(type === 'trending' ? '/trending/movie/day' : '/discover/movie', {
|
||||||
params
|
params
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => mapMoviesSeriesResponseToShows(response));
|
||||||
const data = mapMoviesSeriesResponseToShows(response);
|
|
||||||
|
|
||||||
return data.results;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -1,6 +1,15 @@
|
|||||||
type ShowRef = { showId: Show['id']; showType: Show['type']; showTitle: string };
|
type ShowRef = { showId: Show['id']; showType: Show['type']; showTitle: string };
|
||||||
|
|
||||||
export type ListName = 'popular' | 'top' | 'search' | 'favorite' | 'watchlist' | 'random';
|
export type ListName =
|
||||||
|
| 'popular'
|
||||||
|
| 'top'
|
||||||
|
| 'search'
|
||||||
|
| 'favorite'
|
||||||
|
| 'watchlist'
|
||||||
|
| 'random'
|
||||||
|
| 'trending'
|
||||||
|
| 'similar'
|
||||||
|
| 'recommendations';
|
||||||
|
|
||||||
export type AnalyticsEvents = {
|
export type AnalyticsEvents = {
|
||||||
show_viewed: ShowRef & { surface: 'page' | 'modal' };
|
show_viewed: ShowRef & { surface: 'page' | 'modal' };
|
||||||
|
|||||||
+12
-2
@@ -1,2 +1,12 @@
|
|||||||
export const parseShowType = (value: string | string[] | null | undefined): Show['type'] =>
|
export const SERIES_PREFIX = '/series';
|
||||||
value === 'tv' ? 'tv' : 'movie';
|
|
||||||
|
export const isSeriesPath = (pathname: string) =>
|
||||||
|
pathname === SERIES_PREFIX || pathname.startsWith(`${SERIES_PREFIX}/`);
|
||||||
|
|
||||||
|
export const showTypeFromPath = (pathname: string): Show['type'] => (isSeriesPath(pathname) ? 'tv' : 'movie');
|
||||||
|
|
||||||
|
export const toShowTypePath = (pathname: string, type: Show['type']) => {
|
||||||
|
const base = isSeriesPath(pathname) ? pathname.slice(SERIES_PREFIX.length) || '/' : pathname;
|
||||||
|
|
||||||
|
return type === 'tv' ? (base === '/' ? SERIES_PREFIX : `${SERIES_PREFIX}${base}`) : base;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user