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;
|
||||
@@ -2,11 +2,12 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import UsersList from '@/components/UsersLists';
|
||||
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.`
|
||||
@@ -2,11 +2,12 @@ import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
import { Metadata } from 'next';
|
||||
import { cookies } from 'next/headers';
|
||||
|
||||
import UsersList from '@/components/UsersLists';
|
||||
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.`
|
||||
+29
-4
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { ForwardedRef, forwardRef, memo, useLayoutEffect, useMemo, useRef } from 'react';
|
||||
import { ForwardedRef, forwardRef, memo, startTransition, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Virtuoso, VirtuosoProps } from 'react-virtuoso';
|
||||
|
||||
import Poster from '@/components/Poster';
|
||||
@@ -21,16 +21,34 @@ interface Props extends Context {
|
||||
|
||||
const Carousel = memo(
|
||||
function Carousel({ shows, gap = 8, onIndexChange, onEndReached }: Props) {
|
||||
const initialRef = useRef(true);
|
||||
const index = useSilentIndex();
|
||||
const [loaded, setLoaded] = useState(!index);
|
||||
|
||||
const context = useMemo(() => ({ onIndexChange, gap }), [onIndexChange, gap]);
|
||||
const context = useMemo(
|
||||
() => ({
|
||||
onIndexChange,
|
||||
gap
|
||||
}),
|
||||
[onIndexChange, gap]
|
||||
);
|
||||
|
||||
const handleScroll = () => {
|
||||
if (loaded) return;
|
||||
|
||||
if (initialRef.current) return (initialRef.current = false);
|
||||
|
||||
startTransition(() => setLoaded(true));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='card-aspect-ratio relative mx-auto'>
|
||||
{!loaded && <Poster lazy={false} show={shows![index]} className='pointer-events-none absolute left-0 top-0' />}
|
||||
<Virtuoso
|
||||
onScroll={handleScroll}
|
||||
initialItemCount={1}
|
||||
horizontalDirection
|
||||
skipAnimationFrameInResizeObserver
|
||||
skipAnimationFrameInResizeObserver={true}
|
||||
data={shows}
|
||||
context={context}
|
||||
endReached={onEndReached}
|
||||
@@ -78,7 +96,14 @@ const components: VirtuosoProps<Show, Context>['components'] = {
|
||||
);
|
||||
},
|
||||
List: forwardRef(function List({ context, ...props }, ref) {
|
||||
return <div {...props} ref={ref} style={{ ...props.style, display: 'flex', gap: context?.gap }} />;
|
||||
return (
|
||||
<div
|
||||
{...props}
|
||||
ref={ref}
|
||||
className='bg-background'
|
||||
style={{ ...props.style, display: 'flex', gap: context?.gap }}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
Scroller: forwardRef(function Scroller({ context, ...props }, ref) {
|
||||
const handleRef =
|
||||
@@ -5,7 +5,7 @@ import { FC } from 'react';
|
||||
import Preview from '@/components/Preview';
|
||||
import Trending from '@/components/Trending';
|
||||
|
||||
import Carousel from './(components)/Carousel';
|
||||
import Carousel from './components/Carousel';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
interface Props {
|
||||
|
||||
Reference in new issue
Block a user