fix: improved random filter
This commit is contained in:
1 parent
89e76f5df6
commit
5d7a3464ed
9 files changed
+2921
-73
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
import useFilters from '@/app/(site)/useFilters';
|
import useFilters from '@/app/(site)/useFilters';
|
||||||
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||||
@@ -13,6 +13,7 @@ const UPDATE_RATE = 10;
|
|||||||
const previousIndexes: Record<string, number> = {};
|
const previousIndexes: Record<string, number> = {};
|
||||||
|
|
||||||
const useRandomMovie = () => {
|
const useRandomMovie = () => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const { filters } = useFilters();
|
const { filters } = useFilters();
|
||||||
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
||||||
const [index, setIndex] = useState(indexByFilter || 0);
|
const [index, setIndex] = useState(indexByFilter || 0);
|
||||||
@@ -24,8 +25,9 @@ const useRandomMovie = () => {
|
|||||||
select(movies) {
|
select(movies) {
|
||||||
return filterUnknownMovies(movies);
|
return filterUnknownMovies(movies);
|
||||||
},
|
},
|
||||||
structuralSharing(current, next) {
|
structuralSharing(_, next) {
|
||||||
const uniqueIds: Record<string, number> = {};
|
const uniqueIds: Record<string, number> = {};
|
||||||
|
const current = queryClient.getQueryData<Movie[]>(['random-movie', filters]);
|
||||||
|
|
||||||
return (current || []).concat(next).reduce((unique, movie) => {
|
return (current || []).concat(next).reduce((unique, movie) => {
|
||||||
if (uniqueIds[movie.id]) return unique;
|
if (uniqueIds[movie.id]) return unique;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ const Card: FC<Props> = ({ movie, className }) => {
|
|||||||
<div
|
<div
|
||||||
className={`${className} p-4 rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
className={`${className} p-4 rounded-lg border bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg`}
|
||||||
>
|
>
|
||||||
<div>
|
<div className='max-w-[300px] w-full mx-auto'>
|
||||||
<div className='grid items-center grid-cols-[1fr_50px]'>
|
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||||
<Title title={movie.title} />
|
<Title title={movie.title} />
|
||||||
{movie.release_date && (
|
{movie.release_date && (
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import { FC, useState } from 'react';
|
import { FC, useState } from 'react';
|
||||||
import { Play, Star, User2 } from 'lucide-react';
|
import { Play } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
|
|
||||||
import useFavorites from '@/app/(site)/favorites/useFavorites';
|
|
||||||
import useCredits from '@/app/(site)/useCredits';
|
|
||||||
import useTrailer from '@/app/(site)/useTrailer';
|
import useTrailer from '@/app/(site)/useTrailer';
|
||||||
|
import Credits from '@/components/Movie/components/Credits';
|
||||||
import Poster from '@/components/Movie/components/Poster';
|
import Poster from '@/components/Movie/components/Poster';
|
||||||
import Rating from '@/components/Movie/components/Rating';
|
import Rating from '@/components/Movie/components/Rating';
|
||||||
import Title from '@/components/Movie/components/Title';
|
import Title from '@/components/Movie/components/Title';
|
||||||
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
import Trailer from '@/components/Movie/components/Trailer';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -19,12 +16,8 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
||||||
const { data: credits } = useCredits({ movieId: movie?.id });
|
|
||||||
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
|
||||||
|
|
||||||
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
const [isShowTrailer, setIsShowTrailer] = useState(false);
|
||||||
|
const { data: trailer } = useTrailer({ movieId: movie?.id });
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
@@ -32,8 +25,14 @@ const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
|||||||
<>
|
<>
|
||||||
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
<div className={`p-3 rounded-xl border bg-card text-card-foreground shadow-sm ${className}`}>
|
||||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
<div className='flex flex-col lg:flex-row max-w-[100%] gap-3 overflow-hidden'>
|
||||||
<div className='relative shrink-0'>
|
<Poster
|
||||||
<Poster title={movie.title} width={300} height={350} size={100} poster={movie.poster_path} />
|
className='max-w-[300px]'
|
||||||
|
title={movie.title}
|
||||||
|
width={300}
|
||||||
|
height={450}
|
||||||
|
size={100}
|
||||||
|
poster={movie.poster_path}
|
||||||
|
>
|
||||||
{trailer && (
|
{trailer && (
|
||||||
<div
|
<div
|
||||||
onClick={() => setIsShowTrailer(true)}
|
onClick={() => setIsShowTrailer(true)}
|
||||||
@@ -43,7 +42,7 @@ const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
|||||||
<Play size={100} className='fill-white' />
|
<Play size={100} className='fill-white' />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</Poster>
|
||||||
<div className='flex flex-col grow'>
|
<div className='flex flex-col grow'>
|
||||||
<div className='flex'>
|
<div className='flex'>
|
||||||
<div className='flex flex-row flex-wrap w-full text-lg font-semibold'>
|
<div className='flex flex-row flex-wrap w-full text-lg font-semibold'>
|
||||||
@@ -62,58 +61,9 @@ const Preview: FC<Props> = ({ movie, className, onPersonClick }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{Boolean(credits?.length) && (
|
<Credits movieId={movie.id} onPersonClick={onPersonClick} />
|
||||||
<div className='overflow-auto max-w-[100%] py-3 mb-[-0.75rem]'>
|
|
||||||
<ul className='flex gap-3'>
|
|
||||||
{credits?.map((actor) => (
|
|
||||||
<li
|
|
||||||
key={`${actor.id}_${actor.cast_id}`}
|
|
||||||
title={actor.name}
|
|
||||||
onClick={() => {
|
|
||||||
router.push(`/top?starring=${actor.id}`);
|
|
||||||
onPersonClick?.(actor.id.toString());
|
|
||||||
}}
|
|
||||||
className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg'
|
|
||||||
>
|
|
||||||
{Boolean(actor.character) && (
|
|
||||||
<p className='pb-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
|
||||||
)}
|
|
||||||
<div className='rounded-md overflow-hidden'>
|
|
||||||
{actor.profile_path ? (
|
|
||||||
<Image
|
|
||||||
unoptimized
|
|
||||||
height={225}
|
|
||||||
width={150}
|
|
||||||
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
|
||||||
alt={actor.name}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
|
||||||
<User2 size={120} strokeWidth={1} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{trailer && isShowTrailer && (
|
{isShowTrailer && <Trailer trailerKey={trailer?.key} onClose={() => setIsShowTrailer(false)} />}
|
||||||
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && setIsShowTrailer(false)}>
|
|
||||||
<DialogContent className='block p-0 min-h-[400px] aspect-w-16 aspect-h-9'>
|
|
||||||
<iframe
|
|
||||||
allow='autoplay'
|
|
||||||
className='border-none rounded-lg'
|
|
||||||
width='100%'
|
|
||||||
height='100%'
|
|
||||||
src={`//www.youtube.com/embed/${trailer?.key}?autoplay=1`}
|
|
||||||
allowFullScreen
|
|
||||||
/>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
)}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
import { User2 } from 'lucide-react';
|
||||||
|
import Image from 'next/image';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
|
import useCredits from '@/app/(site)/useCredits';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
movieId: number;
|
||||||
|
onPersonClick?: (id: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
|
||||||
|
const router = useRouter();
|
||||||
|
const { data: credits } = useCredits({ movieId });
|
||||||
|
|
||||||
|
return (
|
||||||
|
Boolean(credits?.length) && (
|
||||||
|
<div className='overflow-auto max-w-[100%] py-3 mb-[-0.75rem]'>
|
||||||
|
<ul className='flex gap-3'>
|
||||||
|
{credits?.map((actor) => (
|
||||||
|
<li
|
||||||
|
key={`${actor.id}_${actor.cast_id}`}
|
||||||
|
title={actor.name}
|
||||||
|
onClick={() => {
|
||||||
|
router.push(`/top?starring=${actor.id}`);
|
||||||
|
onPersonClick?.(actor.id.toString());
|
||||||
|
}}
|
||||||
|
className='p-2 rounded-lg border bg-card text-card-foreground self-end max-w-[150px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg'
|
||||||
|
>
|
||||||
|
{Boolean(actor.character) && (
|
||||||
|
<p className='pb-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||||
|
)}
|
||||||
|
<div className='rounded-md overflow-hidden'>
|
||||||
|
{actor.profile_path ? (
|
||||||
|
<Image
|
||||||
|
unoptimized
|
||||||
|
height={225}
|
||||||
|
width={150}
|
||||||
|
src={`https://image.tmdb.org/t/p/w500/${actor.profile_path}`}
|
||||||
|
alt={actor.name}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className='w-[132px] h-[198px] flex items-center justify-center rounded-lg border'>
|
||||||
|
<User2 size={120} strokeWidth={1} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<p className='pt-2 overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.name}</p>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Credits;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { FC } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
import { ImageOff } from 'lucide-react';
|
import { ImageOff } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
|
|
||||||
@@ -9,9 +9,10 @@ interface Props {
|
|||||||
height: number;
|
height: number;
|
||||||
size: number;
|
size: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
children?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className }) => {
|
const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className, children }) => {
|
||||||
return (
|
return (
|
||||||
<div className={`w-full flex flex-col rounded-lg overflow-hidden shrink-0 lg:m-0 mx-auto relative ${className}`}>
|
<div className={`w-full flex flex-col rounded-lg overflow-hidden shrink-0 lg:m-0 mx-auto relative ${className}`}>
|
||||||
{poster ? (
|
{poster ? (
|
||||||
@@ -28,6 +29,7 @@ const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className
|
|||||||
<ImageOff size={size} strokeWidth={1} />
|
<ImageOff size={size} strokeWidth={1} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
import { Dialog, DialogContent } from '@/components/ui/dialog';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
trailerKey?: string;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Trailer: FC<Props> = ({ trailerKey, onClose }) => {
|
||||||
|
return (
|
||||||
|
trailerKey && (
|
||||||
|
<Dialog defaultOpen={true} onOpenChange={(isOpen) => !isOpen && onClose()}>
|
||||||
|
<DialogContent className='block p-0 min-h-[400px] aspect-w-16 aspect-h-9'>
|
||||||
|
<iframe
|
||||||
|
allow='autoplay'
|
||||||
|
className='border-none rounded-lg'
|
||||||
|
width='100%'
|
||||||
|
height='100%'
|
||||||
|
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||||
|
allowFullScreen
|
||||||
|
/>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Trailer;
|
||||||
@@ -21,7 +21,7 @@ const DialogOverlay = React.forwardRef<
|
|||||||
<DialogPrimitive.Overlay
|
<DialogPrimitive.Overlay
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn(
|
||||||
'fixed inset-0 z-50 bg-background/80 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
'fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
Generated
+2807
-1
File diff suppressed because it is too large.
Load diff
+2
-1
@@ -42,7 +42,8 @@
|
|||||||
"react-fast-marquee": "^1.6.0",
|
"react-fast-marquee": "^1.6.0",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
"tailwindcss-animate": "^1.0.6",
|
"tailwindcss-animate": "^1.0.6",
|
||||||
"typescript": "5.1.6"
|
"typescript": "5.1.6",
|
||||||
|
"webtorrent": "^2.1.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/aspect-ratio": "^0.4.2",
|
"@tailwindcss/aspect-ratio": "^0.4.2",
|
||||||
|
|||||||
Reference in new issue
Block a user