feat: aspect-ratio instead of width measurer
This commit is contained in:
1 parent
375ebf93d9
commit
279a61ddcd
15 files changed
+168
-313
No files matched your search
@@ -1,70 +1,33 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { forwardRef, ReactNode, startTransition, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
import { forwardRef, useEffect, useLayoutEffect, useRef } from 'react';
|
||||||
import { Virtuoso, VirtuosoHandle, VirtuosoProps } from 'react-virtuoso';
|
import { StateSnapshot, Virtuoso, VirtuosoHandle, VirtuosoProps } from 'react-virtuoso';
|
||||||
|
|
||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
const components: VirtuosoProps<Movie, number>['components'] = {
|
let snapshot: StateSnapshot;
|
||||||
Item: (props) => <div {...props} className='shrink-0' style={{ ...props.style, width: props.context }} />,
|
|
||||||
List: forwardRef(function List(props, ref) {
|
|
||||||
return (
|
|
||||||
<div {...props} ref={ref} className='gap-2' style={{ ...props.style, display: 'flex', width: props.context }} />
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Scroller: forwardRef(function Scroller(props, ref) {
|
|
||||||
return <div {...props} ref={ref} className='overflow-hidden no-scrollbar snap-mandatory snap-x rounded-lg' />;
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Measurer = ({ children }: { children: (width: number) => ReactNode }) => {
|
const Carousel = ({
|
||||||
const [ref, setRef] = useState<HTMLDivElement | null>(null);
|
|
||||||
const width = ref?.offsetWidth;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<div ref={setRef} />
|
|
||||||
{children(width || 0)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Carousel = ({
|
|
||||||
index,
|
index,
|
||||||
movies,
|
movies,
|
||||||
width: initialWidth,
|
|
||||||
onIndexChange
|
onIndexChange
|
||||||
}: {
|
}: {
|
||||||
index: number;
|
index: number;
|
||||||
movies?: Movie[];
|
movies?: Movie[];
|
||||||
width: number;
|
|
||||||
onIndexChange: (index: number) => void;
|
onIndexChange: (index: number) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const timeout = useRef<NodeJS.Timeout>();
|
|
||||||
const isMobile = matchMedia('(max-width: 500px)').matches;
|
|
||||||
const ref = useRef<VirtuosoHandle>(null);
|
const ref = useRef<VirtuosoHandle>(null);
|
||||||
const initialIndex = useRef(index);
|
|
||||||
const [snap, setSnap] = useState(true);
|
|
||||||
|
|
||||||
const width = isMobile ? initialWidth : 300;
|
useEffect(() => {
|
||||||
const height = isMobile ? (width * 3) / 2 : 450;
|
const virtuoso = ref.current;
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
if (!virtuoso) return;
|
||||||
if (!ref.current) return;
|
|
||||||
|
|
||||||
ref.current.scrollIntoView({ index: initialIndex.current });
|
return () => virtuoso.getState((state) => (snapshot = state));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let pressed = false;
|
|
||||||
|
|
||||||
const scrollTo = ({ key }: globalThis.KeyboardEvent) => {
|
const scrollTo = ({ key }: globalThis.KeyboardEvent) => {
|
||||||
if (['ArrowLeft', 'ArrowRight'].includes(key)) {
|
|
||||||
pressed = true;
|
|
||||||
setSnap(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key === 'ArrowLeft') {
|
if (key === 'ArrowLeft') {
|
||||||
if (index <= 0) return;
|
if (index <= 0) return;
|
||||||
ref.current?.scrollIntoView({ index: index - 1, behavior: 'smooth' });
|
ref.current?.scrollIntoView({ index: index - 1, behavior: 'smooth' });
|
||||||
@@ -80,32 +43,66 @@ export const Carousel = ({
|
|||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener('keydown', scrollTo);
|
document.removeEventListener('keydown', scrollTo);
|
||||||
pressed && setTimeout(() => setSnap(true), 100);
|
|
||||||
};
|
};
|
||||||
}, [index, movies?.length]);
|
}, [index, movies?.length]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Virtuoso
|
<div className='card-aspect-ratio mx-auto'>
|
||||||
ref={ref}
|
<Virtuoso
|
||||||
data={movies}
|
ref={ref}
|
||||||
defaultItemHeight={height}
|
data={movies}
|
||||||
style={{ width, height, flexShrink: 0, margin: '0 auto' }}
|
context={onIndexChange}
|
||||||
totalCount={movies?.length}
|
horizontalDirection
|
||||||
horizontalDirection
|
components={components}
|
||||||
context={width}
|
skipAnimationFrameInResizeObserver
|
||||||
increaseViewportBy={154}
|
increaseViewportBy={1000}
|
||||||
components={components}
|
restoreStateFrom={snapshot}
|
||||||
itemContent={(index) => {
|
/>
|
||||||
clearTimeout(timeout.current);
|
</div>
|
||||||
|
|
||||||
timeout.current = setTimeout(() => {
|
|
||||||
const currentIndex = index - 1;
|
|
||||||
|
|
||||||
startTransition(() => onIndexChange(currentIndex));
|
|
||||||
}, 50);
|
|
||||||
|
|
||||||
return <Card className={cn(snap && 'snap-start')} movie={movies?.[index]} />;
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const components: VirtuosoProps<Movie, (index: number) => void>['components'] = {
|
||||||
|
Item: ({ item, children, context: onIndexChange, ...props }) => {
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const index = props['data-index'];
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const container = ref.current;
|
||||||
|
|
||||||
|
if (!container) return;
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
(entries) =>
|
||||||
|
entries.forEach((entry) => {
|
||||||
|
if (!entry.isIntersecting) return;
|
||||||
|
|
||||||
|
onIndexChange?.(index);
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
threshold: 0.7
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
observer.observe(container);
|
||||||
|
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [onIndexChange, index]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...props} ref={ref} className='snap-start'>
|
||||||
|
<Card movie={item} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
List: forwardRef(function List({ context, ...props }, ref) {
|
||||||
|
return <div {...props} ref={ref} style={{ ...props.style, display: 'flex' }} className='gap-2' />;
|
||||||
|
}),
|
||||||
|
Scroller: forwardRef(function Scroller({ context, ...props }, ref) {
|
||||||
|
return (
|
||||||
|
<div {...props} ref={ref} className='overflow-hidden no-scrollbar snap-mandatory snap-x rounded-lg h-full' />
|
||||||
|
);
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Carousel;
|
||||||
@@ -2,24 +2,20 @@
|
|||||||
|
|
||||||
import Preview from '@/components/Movie/Preview';
|
import Preview from '@/components/Movie/Preview';
|
||||||
|
|
||||||
import { Carousel, Measurer } from './components/Carousel';
|
import Carousel from './components/Carousel';
|
||||||
import useRandomMovie from './useRandomMovie';
|
import useRandomMovie from './useRandomMovie';
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
const { movies, movie, index, onIndexChange } = useRandomMovie();
|
const { movies, movie, index, onIndexChange } = useRandomMovie();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Measurer>
|
<>
|
||||||
{(width) => (
|
<Preview
|
||||||
<>
|
movie={movie}
|
||||||
<Preview
|
className='bg-background rounded-md'
|
||||||
movie={movie}
|
card={<Carousel index={index} movies={movies} onIndexChange={onIndexChange} />}
|
||||||
className='bg-background rounded-md'
|
/>
|
||||||
card={<Carousel index={index} width={width} movies={movies} onIndexChange={onIndexChange} />}
|
<div className='w-full h-2' />
|
||||||
/>
|
</>
|
||||||
<div className='w-full h-2' />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Measurer>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,24 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { startTransition, useCallback, useEffect, useState } from 'react';
|
import { startTransition, useCallback, useState } from 'react';
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
import useFilters from '@/app/(site)/useFilters';
|
|
||||||
import { randomMovies } from '@/lib/api';
|
import { randomMovies } from '@/lib/api';
|
||||||
|
|
||||||
const UPDATE_RATE = 10;
|
const UPDATE_RATE = 10;
|
||||||
|
|
||||||
const previousIndexes: Record<string, number> = {};
|
let previousIndex: number = 0;
|
||||||
|
|
||||||
const useRandomMovie = () => {
|
const useRandomMovie = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { filters } = useFilters();
|
const [index, setIndex] = useState(previousIndex);
|
||||||
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
|
||||||
const [index, setIndex] = useState(indexByFilter);
|
|
||||||
|
|
||||||
const { data: movies, refetch } = useQuery({
|
const { data: movies, refetch } = useQuery({
|
||||||
queryKey: ['random-movie', filters],
|
queryKey: ['random-movie'],
|
||||||
queryFn: () => randomMovies({ filters }),
|
queryFn: () => randomMovies({ filters: {} }),
|
||||||
structuralSharing(_, newData) {
|
structuralSharing(_, newData) {
|
||||||
const uniqueIds: Record<string, number> = {};
|
const uniqueIds: Record<string, number> = {};
|
||||||
const current = queryClient.getQueryData<Movie[]>(['random-movie', filters]) || [];
|
const current = queryClient.getQueryData<Movie[]>(['random-movie']) || [];
|
||||||
const next = Array.isArray(newData) ? newData : [newData];
|
const next = Array.isArray(newData) ? newData : [newData];
|
||||||
|
|
||||||
return [...current, ...next].reduce((unique, movie) => {
|
return [...current, ...next].reduce((unique, movie) => {
|
||||||
@@ -35,10 +32,6 @@ const useRandomMovie = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIndex(indexByFilter || 0);
|
|
||||||
}, [indexByFilter]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
movies,
|
movies,
|
||||||
movie: movies?.[index],
|
movie: movies?.[index],
|
||||||
@@ -48,10 +41,10 @@ const useRandomMovie = () => {
|
|||||||
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
if ((index && index % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
||||||
refetch();
|
refetch();
|
||||||
}
|
}
|
||||||
previousIndexes[JSON.stringify(filters)] = index;
|
previousIndex = index;
|
||||||
startTransition(() => setIndex(index));
|
startTransition(() => setIndex(index));
|
||||||
},
|
},
|
||||||
[movies, filters]
|
[movies]
|
||||||
),
|
),
|
||||||
index
|
index
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-3
@@ -1,8 +1,12 @@
|
|||||||
import React, { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
import type { Metadata, Viewport } from 'next';
|
import type { Metadata, Viewport } from 'next';
|
||||||
|
import { Poppins } from 'next/font/google';
|
||||||
import { cookies } from 'next/headers';
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
|
const poppins = Poppins({ subsets: ['latin'], weight: '400' });
|
||||||
|
|
||||||
import Header from '@/components/Header';
|
import Header from '@/components/Header';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
import Providers from '@/providers';
|
import Providers from '@/providers';
|
||||||
|
|
||||||
import '@/styles/index.css';
|
import '@/styles/index.css';
|
||||||
@@ -28,16 +32,18 @@ export default function RootLayout({ children }: { children: ReactNode }) {
|
|||||||
<html lang='en' className={theme}>
|
<html lang='en' className={theme}>
|
||||||
<head>
|
<head>
|
||||||
<meta name='theme-color' content='black' />
|
<meta name='theme-color' content='black' />
|
||||||
<link rel='preconnect' href='https://fonts.googleapis.com' />
|
{/* <link rel='preconnect' href='https://fonts.googleapis.com' />
|
||||||
<link rel='preconnect' href='https://fonts.gstatic.com' crossOrigin='' />
|
<link rel='preconnect' href='https://fonts.gstatic.com' crossOrigin='' />
|
||||||
<link href='https://fonts.googleapis.com/css2?family=Moderustic&family=Poppins&display=swap' rel='stylesheet' />
|
<link href='https://fonts.googleapis.com/css2?family=Moderustic&family=Poppins&display=swap' rel='stylesheet' /> */}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<Providers theme={theme}>
|
<Providers theme={theme}>
|
||||||
<div className='sticky top-0 z-20'>
|
<div className='sticky top-0 z-20'>
|
||||||
<Header />
|
<Header />
|
||||||
</div>
|
</div>
|
||||||
<main className='px-2 max-w-[1240px] mx-auto'>{children}</main>
|
<main className='px-2 max-w-[1240px] mx-auto' style={poppins.style}>
|
||||||
|
{children}
|
||||||
|
</main>
|
||||||
</Providers>
|
</Providers>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export function MobileNavigation() {
|
|||||||
const currentPath = usePathname();
|
const currentPath = usePathname();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='flex xs:hidden'>
|
<div className='flex md:hidden'>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
<Button variant='ghost' size='icon'>
|
<Button variant='ghost' size='icon'>
|
||||||
@@ -58,7 +58,7 @@ export function DesktopNavigation() {
|
|||||||
}, [currentPath]);
|
}, [currentPath]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className='relative hidden xs:flex items-center whitespace-nowrap text-sm gap-3'>
|
<ul className='relative hidden md:flex items-center whitespace-nowrap text-sm gap-3'>
|
||||||
{paths.map(({ path, title }) => (
|
{paths.map(({ path, title }) => (
|
||||||
<li
|
<li
|
||||||
key={path}
|
key={path}
|
||||||
|
|||||||
+24
-27
@@ -2,7 +2,6 @@ import { FC } from 'react';
|
|||||||
|
|
||||||
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 { AspectRatio } from '@/components/ui/aspect-ratio';
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import Favorite from './components/Favorite';
|
import Favorite from './components/Favorite';
|
||||||
@@ -12,38 +11,36 @@ interface Props {
|
|||||||
movie?: Movie;
|
movie?: Movie;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
containerProps?: unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Card: FC<Props> = ({ movie, onClick, className }) => {
|
const Card: FC<Props> = ({ movie, onClick, className, containerProps }) => {
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='xs:w-[300px] xs:h-[450px] w-full h-full shrink-0'>
|
<div
|
||||||
<AspectRatio ratio={2 / 3}>
|
{...(containerProps || {})}
|
||||||
<div
|
className={cn(
|
||||||
className={cn(
|
'card-aspect-ratio relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg',
|
||||||
'h-full relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg',
|
className
|
||||||
className
|
)}
|
||||||
)}
|
>
|
||||||
>
|
<div className='flex w-full h-full'>
|
||||||
<div className='flex w-full h-full'>
|
<Poster title={movie.name || movie.title} poster={movie.poster_path} />
|
||||||
<Poster title={movie.name || movie.title} poster={movie.poster_path} />
|
</div>
|
||||||
</div>
|
<div className='text-white absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 card-gradient'>
|
||||||
<div className='text-white absolute w-full h-full top-0 left-0 rounded-md flex flex-col justify-between p-2 card-gradient'>
|
<Handlers movie={movie} onClick={onClick} />
|
||||||
<Handlers movie={movie} onClick={onClick} />
|
<div className='grid grid-cols-[1fr_auto] text-lg opacity-75 gap-2'>
|
||||||
<div className='grid grid-cols-[1fr_auto] text-lg opacity-75 gap-2'>
|
<span className='overflow-ellipsis overflow-hidden whitespace-nowrap'>{movie.name || movie.title}</span>
|
||||||
<span className='overflow-ellipsis overflow-hidden whitespace-nowrap'>{movie.name || movie.title}</span>
|
{Boolean(movie.release_date) && <span>{new Date(movie.release_date).getFullYear()}</span>}
|
||||||
{Boolean(movie.release_date) && <span>{new Date(movie.release_date).getFullYear()}</span>}
|
|
||||||
</div>
|
|
||||||
<div className='opacity-75 mb-[-5px]'>
|
|
||||||
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between z-[1]'>
|
|
||||||
<Favorite movie={movie} />
|
|
||||||
<Rating rating={movie.vote_average} />
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</AspectRatio>
|
<div className='opacity-75 mb-[-5px]'>
|
||||||
|
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between z-[1]'>
|
||||||
|
<Favorite movie={movie} />
|
||||||
|
<Rating rating={movie.vote_average} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,14 +49,12 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, ty
|
|||||||
<>
|
<>
|
||||||
<VirtuosoGrid
|
<VirtuosoGrid
|
||||||
useWindowScroll
|
useWindowScroll
|
||||||
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden opacity-0 animate-fade-in-slide-in'
|
|
||||||
customScrollParent={customScrollParent}
|
|
||||||
totalCount={shows.length}
|
|
||||||
overscan={4}
|
|
||||||
endReached={handleFetchMore}
|
|
||||||
data={shows}
|
data={shows}
|
||||||
context={context}
|
context={context}
|
||||||
components={components}
|
components={components}
|
||||||
|
listClassName='flex gap-2 flex-wrap justify-center grow empty:hidden opacity-0 animate-fade-in-slide-in'
|
||||||
|
customScrollParent={customScrollParent}
|
||||||
|
endReached={handleFetchMore}
|
||||||
/>
|
/>
|
||||||
<div className='h-2 w-full' />
|
<div className='h-2 w-full' />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -25,21 +25,19 @@ const Preview: FC<Props> = ({ movie, className, onClose, children, card, type =
|
|||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
<div className={cn('flex flex-col md:flex-row gap-2 rounded-xl', { 'p-2': Boolean(onClose) }, className)}>
|
||||||
<div className='flex flex-col md:flex-row max-w-[100%] gap-2'>
|
{card || <Card className='mx-auto' movie={movie} />}
|
||||||
{card || <Card className='mx-auto' movie={movie} />}
|
<div className='flex flex-col grow'>
|
||||||
<div className='flex flex-col grow'>
|
{children && <div className='flex hover-none:hidden w-full max-sm:mb-0 mb-2 gap-2'>{children}</div>}
|
||||||
{children && <div className='flex hover-none:hidden w-full max-sm:mb-0 mb-2 gap-2'>{children}</div>}
|
<div className='flex w-full gap-2'>
|
||||||
<div className='flex w-full gap-2'>
|
<Actions type={type} movie={movie} onClose={onClose} />
|
||||||
<Actions type={type} movie={movie} onClose={onClose} />
|
</div>
|
||||||
</div>
|
<Separator className='my-2' />
|
||||||
<Separator className='my-2' />
|
<p key={movie.id} className='leading-7 mb-3'>
|
||||||
<p key={movie.id} className='leading-7 mb-3'>
|
{movie.overview}
|
||||||
{movie.overview}
|
</p>
|
||||||
</p>
|
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
||||||
<div className='mt-auto grid grid-cols-1 rounded-lg'>
|
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
||||||
<Credits type={type} movieId={movie.id} onPersonClick={onClose} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -17,10 +17,11 @@ const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey
|
|||||||
if (!trailerKey) return;
|
if (!trailerKey) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9' onClose={onResolve}>
|
<Modal className='block p-0 min-h-[400px] border-none' style={{ aspectRatio: '16/9' }} onClose={onResolve}>
|
||||||
<iframe
|
<iframe
|
||||||
allow='autoplay'
|
allow='autoplay'
|
||||||
className='border-none rounded-lg'
|
className='border-none rounded-lg'
|
||||||
|
style={{ aspectRatio: '16/9' }}
|
||||||
width='100%'
|
width='100%'
|
||||||
height='100%'
|
height='100%'
|
||||||
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
src={`//www.youtube.com/embed/${trailerKey}?autoplay=1`}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import * as AspectRatioPrimitive from '@radix-ui/react-aspect-ratio';
|
|
||||||
|
|
||||||
const AspectRatio = AspectRatioPrimitive.Root;
|
|
||||||
|
|
||||||
export { AspectRatio };
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { useState } from 'react';
|
import { CSSProperties, useState } from 'react';
|
||||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
|
|
||||||
import useScrollDelta from '@/hooks/useScrollDelta';
|
import useScrollDelta from '@/hooks/useScrollDelta';
|
||||||
@@ -157,9 +157,10 @@ DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|||||||
const Modal: React.FC<{
|
const Modal: React.FC<{
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
style?: CSSProperties;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
scrollRef?: React.MutableRefObject<HTMLDivElement>;
|
scrollRef?: React.MutableRefObject<HTMLDivElement>;
|
||||||
}> = ({ children, onClose, className, scrollRef }) => {
|
}> = ({ children, onClose, className, style, scrollRef }) => {
|
||||||
const [open, setOpen] = useState(true);
|
const [open, setOpen] = useState(true);
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
@@ -172,7 +173,7 @@ const Modal: React.FC<{
|
|||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle />
|
<DialogTitle />
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<DialogContent scrollRef={scrollRef} forceMount onClose={handleClose} className={className}>
|
<DialogContent style={style} scrollRef={scrollRef} forceMount onClose={handleClose} className={className}>
|
||||||
{children}
|
{children}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Generated
-141
@@ -8,7 +8,6 @@
|
|||||||
"name": "movie-advisor",
|
"name": "movie-advisor",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
|
||||||
"@radix-ui/react-dialog": "^1.1.1",
|
"@radix-ui/react-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||||
"@radix-ui/react-hover-card": "^1.0.7",
|
"@radix-ui/react-hover-card": "^1.0.7",
|
||||||
@@ -42,7 +41,6 @@
|
|||||||
"node-html-parser": "^6.1.5",
|
"node-html-parser": "^6.1.5",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-fast-marquee": "^1.6.0",
|
|
||||||
"react-modal-promise": "^1.0.2",
|
"react-modal-promise": "^1.0.2",
|
||||||
"react-virtuoso": "^4.10.1",
|
"react-virtuoso": "^4.10.1",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
@@ -51,7 +49,6 @@
|
|||||||
"vaul": "^0.8.9"
|
"vaul": "^0.8.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
||||||
"@types/js-cookie": "^3.0.3",
|
"@types/js-cookie": "^3.0.3",
|
||||||
"@types/node": "20.4.4",
|
"@types/node": "20.4.4",
|
||||||
"@types/react": "18.2.15",
|
"@types/react": "18.2.15",
|
||||||
@@ -590,81 +587,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@radix-ui/react-aspect-ratio": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-aspect-ratio/-/react-aspect-ratio-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-dP87DM/Y7jFlPgUZTlhx6FF5CEzOiaxp2rBCKlaXlpH5Ip/9Fg5zZ9lDOQ5o/MOfUlf36eak14zoWYpgcgGoOg==",
|
|
||||||
"dependencies": {
|
|
||||||
"@radix-ui/react-primitive": "2.0.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/react": "*",
|
|
||||||
"@types/react-dom": "*",
|
|
||||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
|
||||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@types/react": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"@types/react-dom": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@radix-ui/react-aspect-ratio/node_modules/@radix-ui/react-compose-refs": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-b4inOtiaOnYf9KWyO3jAeeCG6FeyfY6ldiEPanbUjWd+xIk5wZeHa8yVwmrJ2vderhu/BQvzCrJI0lHd+wIiqw==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/react": "*",
|
|
||||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@types/react": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@radix-ui/react-aspect-ratio/node_modules/@radix-ui/react-primitive": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-ZSpFm0/uHa8zTvKBDjLFWLo8dkr4MBsiDLz0g3gMUwqgLHz9rTaRRGYDgvZPtBJgYCBKXkS9fzmoySgr8CO6Cw==",
|
|
||||||
"dependencies": {
|
|
||||||
"@radix-ui/react-slot": "1.1.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/react": "*",
|
|
||||||
"@types/react-dom": "*",
|
|
||||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
|
|
||||||
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@types/react": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"@types/react-dom": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@radix-ui/react-aspect-ratio/node_modules/@radix-ui/react-slot": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-FUCf5XMfmW4dtYl69pdS4DbxKy8nj4M7SafBgPllysxmdachynNflAdp/gCsnYWNDnge6tI9onzMp5ARYc1KNw==",
|
|
||||||
"dependencies": {
|
|
||||||
"@radix-ui/react-compose-refs": "1.1.0"
|
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/react": "*",
|
|
||||||
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"@types/react": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@radix-ui/react-collection": {
|
"node_modules/@radix-ui/react-collection": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
|
||||||
@@ -2252,15 +2174,6 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@tailwindcss/aspect-ratio": {
|
|
||||||
"version": "0.4.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tailwindcss/aspect-ratio/-/aspect-ratio-0.4.2.tgz",
|
|
||||||
"integrity": "sha512-8QPrypskfBa7QIMuKHg2TA7BqES6vhBrDLOv8Unb6FcFyd3TjKbc6lcmb9UPQHxfl24sXoJ41ux/H7qQQvfaSQ==",
|
|
||||||
"dev": true,
|
|
||||||
"peerDependencies": {
|
|
||||||
"tailwindcss": ">=2.0.0 || >=3.0.0 || >=3.0.0-alpha.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@tanstack/query-core": {
|
"node_modules/@tanstack/query-core": {
|
||||||
"version": "5.28.4",
|
"version": "5.28.4",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.28.4.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.28.4.tgz",
|
||||||
@@ -6084,15 +5997,6 @@
|
|||||||
"react": "^18.3.1"
|
"react": "^18.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/react-fast-marquee": {
|
|
||||||
"version": "1.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-fast-marquee/-/react-fast-marquee-1.6.0.tgz",
|
|
||||||
"integrity": "sha512-jtuwT9SNjrqxnE7lGZ8mTL1I8Q4+9G4aBta2p+y2Pa3SjR17QROblwrLICyM8rbjQFHgHawTHcaH9HvoVO2NOA==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"react": ">= 16.8.0 || 18.0.0",
|
|
||||||
"react-dom": ">= 16.8.0 || 18.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/react-is": {
|
"node_modules/react-is": {
|
||||||
"version": "16.13.1",
|
"version": "16.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||||
@@ -7739,38 +7643,6 @@
|
|||||||
"@radix-ui/react-primitive": "1.0.3"
|
"@radix-ui/react-primitive": "1.0.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@radix-ui/react-aspect-ratio": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-aspect-ratio/-/react-aspect-ratio-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-dP87DM/Y7jFlPgUZTlhx6FF5CEzOiaxp2rBCKlaXlpH5Ip/9Fg5zZ9lDOQ5o/MOfUlf36eak14zoWYpgcgGoOg==",
|
|
||||||
"requires": {
|
|
||||||
"@radix-ui/react-primitive": "2.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@radix-ui/react-compose-refs": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-compose-refs/-/react-compose-refs-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-b4inOtiaOnYf9KWyO3jAeeCG6FeyfY6ldiEPanbUjWd+xIk5wZeHa8yVwmrJ2vderhu/BQvzCrJI0lHd+wIiqw==",
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"@radix-ui/react-primitive": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-primitive/-/react-primitive-2.0.0.tgz",
|
|
||||||
"integrity": "sha512-ZSpFm0/uHa8zTvKBDjLFWLo8dkr4MBsiDLz0g3gMUwqgLHz9rTaRRGYDgvZPtBJgYCBKXkS9fzmoySgr8CO6Cw==",
|
|
||||||
"requires": {
|
|
||||||
"@radix-ui/react-slot": "1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@radix-ui/react-slot": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-slot/-/react-slot-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-FUCf5XMfmW4dtYl69pdS4DbxKy8nj4M7SafBgPllysxmdachynNflAdp/gCsnYWNDnge6tI9onzMp5ARYc1KNw==",
|
|
||||||
"requires": {
|
|
||||||
"@radix-ui/react-compose-refs": "1.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"@radix-ui/react-collection": {
|
"@radix-ui/react-collection": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.0.3.tgz",
|
||||||
@@ -8587,13 +8459,6 @@
|
|||||||
"tslib": "^2.4.0"
|
"tslib": "^2.4.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@tailwindcss/aspect-ratio": {
|
|
||||||
"version": "0.4.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/@tailwindcss/aspect-ratio/-/aspect-ratio-0.4.2.tgz",
|
|
||||||
"integrity": "sha512-8QPrypskfBa7QIMuKHg2TA7BqES6vhBrDLOv8Unb6FcFyd3TjKbc6lcmb9UPQHxfl24sXoJ41ux/H7qQQvfaSQ==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"@tanstack/query-core": {
|
"@tanstack/query-core": {
|
||||||
"version": "5.28.4",
|
"version": "5.28.4",
|
||||||
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.28.4.tgz",
|
"resolved": "https://registry.npmjs.org/@tanstack/query-core/-/query-core-5.28.4.tgz",
|
||||||
@@ -11193,12 +11058,6 @@
|
|||||||
"scheduler": "^0.23.2"
|
"scheduler": "^0.23.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"react-fast-marquee": {
|
|
||||||
"version": "1.6.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/react-fast-marquee/-/react-fast-marquee-1.6.0.tgz",
|
|
||||||
"integrity": "sha512-jtuwT9SNjrqxnE7lGZ8mTL1I8Q4+9G4aBta2p+y2Pa3SjR17QROblwrLICyM8rbjQFHgHawTHcaH9HvoVO2NOA==",
|
|
||||||
"requires": {}
|
|
||||||
},
|
|
||||||
"react-is": {
|
"react-is": {
|
||||||
"version": "16.13.1",
|
"version": "16.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@radix-ui/react-aspect-ratio": "^1.1.0",
|
|
||||||
"@radix-ui/react-dialog": "^1.1.1",
|
"@radix-ui/react-dialog": "^1.1.1",
|
||||||
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
"@radix-ui/react-dropdown-menu": "^2.0.6",
|
||||||
"@radix-ui/react-hover-card": "^1.0.7",
|
"@radix-ui/react-hover-card": "^1.0.7",
|
||||||
@@ -43,7 +42,6 @@
|
|||||||
"node-html-parser": "^6.1.5",
|
"node-html-parser": "^6.1.5",
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-fast-marquee": "^1.6.0",
|
|
||||||
"react-modal-promise": "^1.0.2",
|
"react-modal-promise": "^1.0.2",
|
||||||
"react-virtuoso": "^4.10.1",
|
"react-virtuoso": "^4.10.1",
|
||||||
"tailwind-merge": "^1.14.0",
|
"tailwind-merge": "^1.14.0",
|
||||||
@@ -52,7 +50,6 @@
|
|||||||
"vaul": "^0.8.9"
|
"vaul": "^0.8.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/aspect-ratio": "^0.4.2",
|
|
||||||
"@types/js-cookie": "^3.0.3",
|
"@types/js-cookie": "^3.0.3",
|
||||||
"@types/node": "20.4.4",
|
"@types/node": "20.4.4",
|
||||||
"@types/react": "18.2.15",
|
"@types/react": "18.2.15",
|
||||||
|
|||||||
+28
-9
@@ -92,15 +92,15 @@
|
|||||||
* {
|
* {
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
-webkit-touch-callout: none;
|
-webkit-touch-callout: none;
|
||||||
-webkit-user-select: none;
|
}
|
||||||
-khtml-user-select: none;
|
|
||||||
-moz-user-select: none;
|
::-moz-selection {
|
||||||
-ms-user-select: none;
|
color: white;
|
||||||
user-select: none;
|
background: black;
|
||||||
font-family: 'Poppins', sans-serif;
|
}
|
||||||
font-optical-sizing: auto;
|
::selection {
|
||||||
font-weight: 400;
|
color: white;
|
||||||
font-style: normal;
|
background: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-gradient {
|
.card-gradient {
|
||||||
@@ -139,3 +139,22 @@
|
|||||||
rgba(0, 0, 0, 0.4) 100%
|
rgba(0, 0, 0, 0.4) 100%
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.card-aspect-ratio {
|
||||||
|
width: 300px;
|
||||||
|
height: 450px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
@media screen and (max-width: 500px) {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
aspect-ratio: 2/3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@supports (hanging-punctuation: first) and (font: -apple-system-body) and (-webkit-appearance: none) {
|
||||||
|
.card-aspect-ratio {
|
||||||
|
@media screen and (max-width: 500px) {
|
||||||
|
aspect-ratio: 2/2.908;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -83,5 +83,5 @@ module.exports = {
|
|||||||
corePlugins: {
|
corePlugins: {
|
||||||
aspectRatio: false
|
aspectRatio: false
|
||||||
},
|
},
|
||||||
plugins: [require('tailwindcss-animate'), require('@tailwindcss/aspect-ratio'), require('tailwindcss-touch')()]
|
plugins: [require('tailwindcss-animate'), require('tailwindcss-touch')()]
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user