feat: reduced countries list
This commit is contained in:
1 parent
29f6de300b
commit
375ebf93d9
13 files changed
+83
-150
No files matched your search
@@ -31,14 +31,14 @@ export const Measurer = ({ children }: { children: (width: number) => ReactNode
|
||||
};
|
||||
|
||||
export const Carousel = ({
|
||||
index,
|
||||
movies,
|
||||
width: initialWidth,
|
||||
index,
|
||||
onIndexChange
|
||||
}: {
|
||||
index: number;
|
||||
movies?: Movie[];
|
||||
width: number;
|
||||
index: number;
|
||||
onIndexChange: (index: number) => void;
|
||||
}) => {
|
||||
const timeout = useRef<NodeJS.Timeout>();
|
||||
@@ -57,16 +57,21 @@ export const Carousel = ({
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const scrollTo = (event: globalThis.KeyboardEvent) => {
|
||||
if (event.key === 'ArrowLeft') {
|
||||
if (index <= 0) return;
|
||||
let pressed = false;
|
||||
|
||||
const scrollTo = ({ key }: globalThis.KeyboardEvent) => {
|
||||
if (['ArrowLeft', 'ArrowRight'].includes(key)) {
|
||||
pressed = true;
|
||||
setSnap(false);
|
||||
}
|
||||
|
||||
if (key === 'ArrowLeft') {
|
||||
if (index <= 0) return;
|
||||
ref.current?.scrollIntoView({ index: index - 1, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
if (event.key === 'ArrowRight') {
|
||||
if (key === 'ArrowRight') {
|
||||
if (index >= (movies?.length || 0) - 1) return;
|
||||
setSnap(false);
|
||||
ref.current?.scrollIntoView({ index: index + 1, behavior: 'smooth' });
|
||||
}
|
||||
};
|
||||
@@ -75,7 +80,7 @@ export const Carousel = ({
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', scrollTo);
|
||||
setTimeout(() => setSnap(true), 100);
|
||||
pressed && setTimeout(() => setSnap(true), 100);
|
||||
};
|
||||
}, [index, movies?.length]);
|
||||
|
||||
|
||||
@@ -1,37 +1,24 @@
|
||||
'use client';
|
||||
|
||||
import { motion, Variants } from 'framer-motion';
|
||||
|
||||
import Preview from '@/components/Movie/Preview';
|
||||
|
||||
import { Carousel, Measurer } from './components/Carousel';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
|
||||
const container: Variants = {
|
||||
hidden: { y: -20, opacity: 0 },
|
||||
visible: {
|
||||
y: 0,
|
||||
opacity: 1,
|
||||
transition: {
|
||||
delay: 0.1
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default function Container() {
|
||||
const { movies, movie, index, onIndexChange } = useRandomMovie();
|
||||
|
||||
return (
|
||||
<Measurer>
|
||||
{(width) => (
|
||||
<motion.div variants={container} initial='hidden' animate='visible'>
|
||||
<>
|
||||
<Preview
|
||||
movie={movie}
|
||||
className='bg-background rounded-md'
|
||||
card={<Carousel index={index} width={width} movies={movies} onIndexChange={onIndexChange} />}
|
||||
/>
|
||||
<div className='w-full h-2 max-sm:h-12' />
|
||||
</motion.div>
|
||||
<div className='w-full h-2' />
|
||||
</>
|
||||
)}
|
||||
</Measurer>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user