fix: back to prefetch
This commit is contained in:
1 parent
a268f7c38d
commit
c9ca262da8
14 files changed
+180
-27
No files matched your search
@@ -1,10 +1,16 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import Random from '@/components/Random';
|
||||
import Trending from '@/components/Trending';
|
||||
|
||||
const Container = () => (
|
||||
interface Props {
|
||||
page: number;
|
||||
}
|
||||
|
||||
const Container: FC<Props> = ({ page }) => (
|
||||
<div className='flex flex-1 flex-col'>
|
||||
<div className='xs:mb-4'>
|
||||
<Random />
|
||||
<Random page={page} />
|
||||
<div className='h-2 w-full' />
|
||||
</div>
|
||||
<div className='hidden w-full rounded-lg xs:block'>
|
||||
|
||||
@@ -1,14 +1,32 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import UsersList from '@/components/UsersLists';
|
||||
import { session } from '@/data';
|
||||
import { session as getSession } from '@/data';
|
||||
import usersShowsQuery from '@/data/queries/usersShows';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
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.`
|
||||
};
|
||||
|
||||
const Favorites = async () => <UsersList session={await session()} list='favorite' label='favorites' />;
|
||||
const Favorites = async () => {
|
||||
const session = await getSession();
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const list = 'favorite';
|
||||
|
||||
if (session) {
|
||||
queryClient.prefetchInfiniteQuery(usersShowsQuery({ showType: 'movie', session, list }));
|
||||
}
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<UsersList session={session} list={list} label='favorites' />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Favorites;
|
||||
+18
-1
@@ -1,5 +1,22 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import randomQuery, { generatePage } from '@/data/queries/random';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
const Random = () => <Container />;
|
||||
const Random = () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const page = generatePage();
|
||||
|
||||
queryClient.prefetchInfiniteQuery(randomQuery({ page }));
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container page={page} />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Random;
|
||||
@@ -1,6 +1,9 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -9,6 +12,16 @@ export const metadata: Metadata = {
|
||||
description: `Check out the most popular movies right now on ${TITLE}. See what’s trending and don’t miss out on the latest hits.`
|
||||
};
|
||||
|
||||
const Popular = () => <Container />;
|
||||
const Popular = () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
queryClient.prefetchInfiniteQuery(popularQuery());
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Popular;
|
||||
@@ -1,5 +1,27 @@
|
||||
import { FC } from 'react';
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import similarQuery from '@/data/queries/similar';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
const Similar = () => <Container />;
|
||||
interface Props {
|
||||
searchParams: { id: string; type: Show['type'] };
|
||||
}
|
||||
|
||||
const Similar: FC<Props> = ({ searchParams }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { id, type } = searchParams || {};
|
||||
|
||||
queryClient.prefetchInfiniteQuery(similarQuery({ showId: id, showType: type }));
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Similar;
|
||||
@@ -1,5 +1,32 @@
|
||||
import { FC } from 'react';
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
const Starring = () => <Container />;
|
||||
interface Props {
|
||||
searchParams: Record<string, string>;
|
||||
}
|
||||
|
||||
const Starring: FC<Props> = ({ searchParams }) => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { actorId } = searchParams || {};
|
||||
|
||||
queryClient.prefetchInfiniteQuery(
|
||||
popularQuery({
|
||||
sortBy: 'vote_average.desc',
|
||||
starring: actorId
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Starring;
|
||||
+14
-1
@@ -1,6 +1,9 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import popularQuery from '@/data/queries/popular';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -9,6 +12,16 @@ export const metadata: Metadata = {
|
||||
description: `Discover the top-rated movies on ${TITLE}. Find the highest-rated films and make informed viewing choices.`
|
||||
};
|
||||
|
||||
const Top = () => <Container />;
|
||||
const Top = () => {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
queryClient.prefetchInfiniteQuery(popularQuery({ sortBy: 'vote_average.desc' }));
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Top;
|
||||
@@ -1,14 +1,32 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
|
||||
import UsersList from '@/components/UsersLists';
|
||||
import { session } from '@/data';
|
||||
import { session as getSession, session } from '@/data';
|
||||
import usersShowsQuery from '@/data/queries/usersShows';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: `My watch list - ${TITLE}`,
|
||||
description: `View your favorite shows on ${TITLE}. Keep track of films you’ve added and revisit your top picks anytime.`
|
||||
};
|
||||
|
||||
const WatchList = async () => <UsersList session={await session()} list='watchlist' label='watch' />;
|
||||
const WatchList = async () => {
|
||||
const session = await getSession();
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const list = 'watchlist';
|
||||
|
||||
if (session) {
|
||||
queryClient.prefetchInfiniteQuery(usersShowsQuery({ showType: 'movie', session, list }));
|
||||
}
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<UsersList session={session} list={list} label='watch' />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default WatchList;
|
||||
Reference in new issue
Block a user