fix: prevent slider flickering
This commit is contained in:
1 parent
183c7231a1
commit
af942149af
8 files changed
+53
-26
No files matched your search
@@ -0,0 +1,48 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
import List from '@/components/List';
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||
import useUsersShows from '@/hooks/useUsersShows';
|
||||
|
||||
interface Props {
|
||||
list: 'favorite' | 'watchlist';
|
||||
label: string;
|
||||
session?: string;
|
||||
}
|
||||
|
||||
const UsersList: FC<Props> = ({ list, label, session }) => {
|
||||
const movies = useUsersShows({ list, showType: 'movie', session });
|
||||
const series = useUsersShows({ list, showType: 'tv', session, mode: 'default' });
|
||||
|
||||
const tabs = [
|
||||
{ query: movies, title: 'Movies', key: 'movie' as const },
|
||||
{ query: series, title: 'Series', key: 'tv' as const }
|
||||
];
|
||||
|
||||
return (
|
||||
<Tabs defaultValue='movie' className='flex w-full flex-col items-center'>
|
||||
<TabsList className='grid w-full grid-cols-2 sm:w-[300px]'>
|
||||
{tabs.map(({ title, key }) => (
|
||||
<TabsTrigger key={key} value={key}>
|
||||
{title}
|
||||
</TabsTrigger>
|
||||
))}
|
||||
</TabsList>
|
||||
{tabs.map(({ query, key, title }) => (
|
||||
<TabsContent key={key} value={key} className='w-full'>
|
||||
{query.isFetched && !query.shows.length ? (
|
||||
<div className='flex h-40 w-full items-center justify-center text-center text-xl text-muted-foreground'>
|
||||
There are no {title.toLowerCase()} in your {label} list
|
||||
</div>
|
||||
) : (
|
||||
<List shows={query.shows} fetchNextPage={query.fetchNextPage} />
|
||||
)}
|
||||
</TabsContent>
|
||||
))}
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
|
||||
export default UsersList;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import usersShowsQuery from '@/data/queries/usersShows';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import UsersList from '../components/UsersLists';
|
||||
|
||||
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 () => {
|
||||
const session = cookies().get('session')?.value;
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const list = 'favorite';
|
||||
|
||||
if (session) {
|
||||
await queryClient.prefetchInfiniteQuery(usersShowsQuery({ showType: 'movie', session, list }));
|
||||
}
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<UsersList session={session} list={list} label='favorites' />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
export default Favorites;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import usersShowsQuery from '@/data/queries/usersShows';
|
||||
import { TITLE } from '@/env';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import UsersList from '../components/UsersLists';
|
||||
|
||||
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 () => {
|
||||
const session = cookies().get('session')?.value;
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const list = 'watchlist';
|
||||
|
||||
if (session) {
|
||||
await 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