feat: reduced countries list
This commit is contained in:
1 parent
29f6de300b
commit
375ebf93d9
13 files changed
+62
-129
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>
|
||||
);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { FC, useEffect, useRef, useState } from 'react';
|
||||
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu';
|
||||
import { motion } from 'framer-motion';
|
||||
import { Menu } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
@@ -71,11 +70,16 @@ export function DesktopNavigation() {
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
<Cursor position={position} />
|
||||
<Cursor options={position} />
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
const Cursor: FC<{ position: { left: number; width: number; opacity: number } }> = ({ position }) => {
|
||||
return <motion.li className='pointer-events-none absolute bg-primary rounded-full h-full z-0' animate={position} />;
|
||||
const Cursor: FC<{ options: { left: number; width: number; opacity: number } }> = ({ options }) => {
|
||||
return (
|
||||
<li
|
||||
className='pointer-events-none absolute bg-primary rounded-full h-full z-0 transition-all'
|
||||
style={{ width: options.width, left: options.left, opacity: options.opacity }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -62,7 +62,6 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
className='pr-10 focus-visible:ring-0'
|
||||
/>
|
||||
<Button
|
||||
base
|
||||
variant='outline'
|
||||
type='button'
|
||||
size='icon'
|
||||
@@ -112,7 +111,7 @@ export const showSearchModal = create(({ onResolve }) => {
|
||||
|
||||
export default function ToggleSearch() {
|
||||
return (
|
||||
<Button base variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
||||
<Button variant='ghost' size='icon' onClick={() => showSearchModal()}>
|
||||
<SearchIcon size={19} />
|
||||
</Button>
|
||||
);
|
||||
|
||||
@@ -31,8 +31,8 @@ const Card: FC<Props> = ({ movie, onClick, className }) => {
|
||||
</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'>
|
||||
<Handlers movie={movie} onClick={onClick} />
|
||||
<div className='flex items-start justify-between text-lg opacity-75'>
|
||||
<span>{movie.name || movie.title}</span>
|
||||
<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>
|
||||
{Boolean(movie.release_date) && <span>{new Date(movie.release_date).getFullYear()}</span>}
|
||||
</div>
|
||||
<div className='opacity-75 mb-[-5px]'>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { FC, forwardRef, useMemo } from 'react';
|
||||
import { FC, useMemo } from 'react';
|
||||
import { VirtuosoGrid, VirtuosoGridProps } from 'react-virtuoso';
|
||||
import { motion } from 'framer-motion';
|
||||
|
||||
import Card from '@/components/Movie/Card';
|
||||
import { showPreviewModal } from '@/components/Movie/Preview';
|
||||
@@ -15,27 +14,7 @@ interface Props {
|
||||
onPreviewClose?: () => void;
|
||||
}
|
||||
|
||||
const container = {
|
||||
hidden: { y: -20, opacity: 0 },
|
||||
visible: {
|
||||
y: 0,
|
||||
opacity: 1
|
||||
}
|
||||
};
|
||||
|
||||
const components: VirtuosoGridProps<Movie, { shows: Movie[]; onClick: (movie: Movie) => void }>['components'] = {
|
||||
List: forwardRef(function List({ context, ...props }, ref) {
|
||||
return (
|
||||
<motion.div
|
||||
{...props}
|
||||
variants={container}
|
||||
initial='hidden'
|
||||
animate='visible'
|
||||
className='flex gap-2 flex-wrap justify-center grow empty:hidden'
|
||||
ref={ref}
|
||||
/>
|
||||
);
|
||||
}),
|
||||
Item: ({ context, 'data-index': index }) => {
|
||||
const { shows, onClick } = context || {};
|
||||
const movie = shows?.[index];
|
||||
@@ -70,6 +49,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, onPreviewClose, ty
|
||||
<>
|
||||
<VirtuosoGrid
|
||||
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}
|
||||
|
||||
@@ -1,59 +1,33 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { User2 } from 'lucide-react';
|
||||
import Image from 'next/image';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
|
||||
import useCredits from '@/app/(site)/useCredits';
|
||||
|
||||
interface Props {
|
||||
type?: ShowType;
|
||||
movieId: number;
|
||||
onPersonClick?: (id: string) => void;
|
||||
type?: ShowType;
|
||||
}
|
||||
|
||||
const container = {
|
||||
hidden: {},
|
||||
visible: {
|
||||
transition: {
|
||||
staggerChildren: 0.03
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const item = {
|
||||
hidden: { x: -20, opacity: 0 },
|
||||
visible: {
|
||||
x: 0,
|
||||
opacity: 1
|
||||
}
|
||||
};
|
||||
|
||||
const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
const router = useRouter();
|
||||
const { data: credits } = useCredits({ movieId, type });
|
||||
|
||||
return (
|
||||
Boolean(credits?.length) && (
|
||||
<motion.ul
|
||||
className='flex gap-2 no-scrollbar overflow-auto rounded-lg snap-mandatory snap-x'
|
||||
variants={container}
|
||||
initial='hidden'
|
||||
animate='visible'
|
||||
whileInView='visible'
|
||||
>
|
||||
<ul className='flex gap-2 no-scrollbar overflow-auto rounded-lg snap-mandatory snap-x opacity-0 animate-fade-aside-slide-in'>
|
||||
{credits?.map((actor) => (
|
||||
<motion.li
|
||||
variants={item}
|
||||
<li
|
||||
key={`${actor.id}_${actor.cast_id}`}
|
||||
title={actor.name}
|
||||
onTap={() => {
|
||||
router.push(`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`);
|
||||
onPersonClick?.(actor.id.toString());
|
||||
}}
|
||||
className='bg-card text-card-foreground self-end max-w-[120px] w-full shrink-0 cursor-pointer transition-shadow hover:shadow-lg relative snap-start'
|
||||
>
|
||||
<Link
|
||||
href={`/starring?actorId=${actor.id}&title=${encodeURIComponent(actor.name)}`}
|
||||
onClick={() => onPersonClick?.(actor.id.toString())}
|
||||
>
|
||||
<div className='rounded-lg overflow-hidden'>
|
||||
{actor.profile_path ? (
|
||||
@@ -76,9 +50,10 @@ const Credits: FC<Props> = ({ movieId, onPersonClick, type = 'movie' }) => {
|
||||
<p className='overflow-ellipsis whitespace-nowrap overflow-hidden'>{actor.character}</p>
|
||||
)}
|
||||
</div>
|
||||
</motion.li>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</motion.ul>
|
||||
</ul>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { create, InstanceProps } from 'react-modal-promise';
|
||||
import { motion } from 'framer-motion';
|
||||
import { Play } from 'lucide-react';
|
||||
|
||||
import useTrailer from '@/app/(site)/useTrailer';
|
||||
@@ -39,12 +38,12 @@ export default function ToggleTrailer({ movieId, type = 'movie', children }: Pro
|
||||
return children
|
||||
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
|
||||
: trailer && (
|
||||
<motion.div
|
||||
onTap={() => showTrailerModal({ trailerKey: trailer?.key })}
|
||||
<div
|
||||
onClick={() => showTrailerModal({ trailerKey: trailer?.key })}
|
||||
title='Play trailer'
|
||||
className='absolute w-full h-full left-0 top-0 bg-black cursor-pointer overflow-hidden rounded-lg transition-opacity opacity-0 hover:opacity-70 flex items-center justify-center'
|
||||
>
|
||||
<Play size={100} className='fill-white' />
|
||||
</motion.div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import { useRef, useState } from 'react';
|
||||
import { cva, type VariantProps } from 'class-variance-authority';
|
||||
import { HTMLMotionProps, motion } from 'framer-motion';
|
||||
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
@@ -37,27 +35,8 @@ export interface ButtonProps
|
||||
asChild?: boolean;
|
||||
}
|
||||
|
||||
const Button = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
HTMLMotionProps<'button'> & Pick<ButtonProps, 'size' | 'variant'> & { base?: boolean }
|
||||
>(({ className, variant, size, base, ...props }, ref) => {
|
||||
if (base)
|
||||
return (
|
||||
<button
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...(props as unknown as ButtonProps)}
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<motion.button
|
||||
className={cn(buttonVariants({ variant, size, className }))}
|
||||
ref={ref}
|
||||
{...props}
|
||||
onClick={undefined}
|
||||
onTap={(e) => props.onClick?.(e as unknown as React.MouseEvent<HTMLButtonElement, MouseEvent>)}
|
||||
/>
|
||||
);
|
||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(({ className, variant, size, ...props }, ref) => {
|
||||
return <button className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />;
|
||||
});
|
||||
Button.displayName = 'Button';
|
||||
|
||||
|
||||
+4
-3
@@ -25,10 +25,11 @@ export const search = async ({
|
||||
|
||||
export const randomMovies = async ({ filters }: { filters: Partial<Filters> }): Promise<Movie[]> => {
|
||||
return server
|
||||
.get('/discover/movie', {
|
||||
.get<MovieDBResponse>('/discover/movie', {
|
||||
params: {
|
||||
sort_by: 'popularity.desc',
|
||||
page: Math.floor(Math.random() * 500) + 1,
|
||||
with_origin_country: 'UA|GB|AU|US|IT|DE|FR',
|
||||
page: Math.floor(Math.random() * 499) + 1,
|
||||
with_genres: filters.genres?.join('|'),
|
||||
'vote_average.gte': filters.score?.[0],
|
||||
'vote_average.lte': filters.score?.[1],
|
||||
@@ -36,7 +37,7 @@ export const randomMovies = async ({ filters }: { filters: Partial<Filters> }):
|
||||
'release_date.lte': filters.year?.[1]
|
||||
}
|
||||
})
|
||||
.then((data: unknown) => filterUnknownMovies((data as MovieDBResponse).results));
|
||||
.then((data) => filterUnknownMovies(data.results));
|
||||
};
|
||||
|
||||
export const popularMovies = async ({ page }: { page?: string } = {}): Promise<MovieDBResponse> => {
|
||||
|
||||
@@ -10,7 +10,6 @@ class Server {
|
||||
}, new URLSearchParams());
|
||||
|
||||
return fetch(`${base}${url}?${serializedParams}`, {
|
||||
cache: 'force-cache',
|
||||
next: { revalidate: 3600 },
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.MOVIE_DB_TOKEN}`
|
||||
|
||||
+2
-7
@@ -7,8 +7,8 @@
|
||||
display: none;
|
||||
}
|
||||
.no-scrollbar {
|
||||
-ms-overflow-style: none; /* IE and Edge */
|
||||
scrollbar-width: none; /* Firefox */
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,11 +103,6 @@
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
/* html {
|
||||
scroll-padding-top: 62px;
|
||||
scroll-snap-type: y mandatory;
|
||||
} */
|
||||
|
||||
.card-gradient {
|
||||
background: linear-gradient(
|
||||
rgba(0, 0, 0, 0.4) 0%,
|
||||
|
||||
+11
-1
@@ -62,11 +62,21 @@ module.exports = {
|
||||
'accordion-up': {
|
||||
from: { height: 'var(--radix-accordion-content-height)' },
|
||||
to: { height: 0 }
|
||||
},
|
||||
fadeInSlideIn: {
|
||||
'0%': { opacity: 0, transform: 'translate3d(0, -30px, 0)' },
|
||||
'100%': { opacity: 1, transform: 'translate3d(0, 0, 0)' }
|
||||
},
|
||||
fadeAsideSlideIn: {
|
||||
'0%': { opacity: 0, transform: 'translate3d(-20px, 0, 0)' },
|
||||
'100%': { opacity: 1, transform: 'translate3d(0, 0, 0)' }
|
||||
}
|
||||
},
|
||||
animation: {
|
||||
'accordion-down': 'accordion-down 0.2s ease-out',
|
||||
'accordion-up': 'accordion-up 0.2s ease-out'
|
||||
'accordion-up': 'accordion-up 0.2s ease-out',
|
||||
'fade-in-slide-in': 'fadeInSlideIn 0.2s ease-in-out forwards',
|
||||
'fade-aside-slide-in': 'fadeAsideSlideIn 0.2s ease-in-out forwards'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user