feat: swiper

This commit is contained in:
ner committed 2024-03-23 11:20:30 +02:00
1 parent cd8928ab54
commit 12223b79d5
20 files changed
+222 -164

No files matched your search

@@ -36,7 +36,7 @@ const Credits: FC<Props> = ({ movieId, onPersonClick }) => {
return (
Boolean(credits?.length) && (
<div className='overflow-auto no-scrollbar max-w-[100%] py-2 pb-5 mb-[-0.75rem]'>
<div className='overflow-auto no-scrollbar max-w-[100%] py-2 mb-[-0.75rem]'>
<motion.ul className='flex gap-3' variants={container} initial='hidden' animate='visible' whileInView='visible'>
{credits?.map((actor) => (
<motion.li
+16 -25
View File
@@ -1,38 +1,29 @@
import { FC, ReactNode } from 'react';
import { FC } from 'react';
import { ImageOff } from 'lucide-react';
import Image from 'next/image';
import { cn } from '@/lib/utils';
interface Props {
title: string;
poster: string;
width: number;
height: number;
size: number;
className?: string;
children?: ReactNode;
}
const Poster: FC<Props> = ({ title, poster, width, height, size = 250, className, children }) => {
return (
<div
className={`w-full flex flex-col rounded-lg overflow-hidden shrink-0 lg:m-0 mx-auto relative ${className}`}
style={{ minHeight: poster ? '' : height }}
>
{poster ? (
<Image
className='rounded-lg mx-auto w-auto'
unoptimized
height={height}
width={width}
src={`https://image.tmdb.org/t/p/w500/${poster}`}
alt={title}
/>
) : (
<div className={`h-[${height}px] w-full flex items-center justify-center rounded-lg border grow`}>
<ImageOff size={size} strokeWidth={1} />
</div>
)}
{children}
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
return poster ? (
<Image
className={cn('rounded-lg mx-auto w-auto h-full object-fill', className)}
unoptimized
height={750}
width={500}
src={`https://image.tmdb.org/t/p/w500/${poster}`}
alt={title}
/>
) : (
<div className={'w-full flex items-center justify-center rounded-lg grow'}>
<ImageOff size={size} strokeWidth={1} color='hsl(215.4 16.3% 46.9%)' />
</div>
);
};
+6 -11
View File
@@ -2,26 +2,21 @@ import { FC } from 'react';
import { motion } from 'framer-motion';
import { Heart, Star } from 'lucide-react';
import useFavorites, { useFavoritesMutation } from '@/app/(site)/favorites/useFavorites';
interface Props {
movie: Movie;
isFavorite: boolean;
toggleFavorite: () => void;
iconsFillColor?: string;
rating?: number;
}
const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' }) => {
const { map } = useFavorites();
const { add, remove } = useFavoritesMutation();
const isFavorite = map.has(movie.id);
const Rating: FC<Props> = ({ isFavorite, rating, toggleFavorite, iconsFillColor = 'fill-accent-foreground' }) => {
return (
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
<motion.span
onTap={(event) => {
event.stopPropagation();
isFavorite ? remove(movie.id) : add(movie);
toggleFavorite();
}}
className='z-[2] cursor-pointer'
title={isFavorite ? 'Remove from favorites' : 'Add to favorite'}
@@ -30,7 +25,7 @@ const Rating: FC<Props> = ({ movie, iconsFillColor = 'fill-accent-foreground' })
</motion.span>
<span className='flex items-center'>
<Star size={18} className={`mr-1 ${iconsFillColor}`} />
<span className='font-semibold'>{movie.vote_average?.toFixed(1)}</span>
<span className='font-semibold'>{rating?.toFixed(1)}</span>
</span>
</span>
);
+15 -14
View File
@@ -1,6 +1,6 @@
'use client';
import { FC } from 'react';
import { FC, ReactNode } from 'react';
import { create, InstanceProps } from 'react-modal-promise';
import { motion } from 'framer-motion';
import { Play } from 'lucide-react';
@@ -10,6 +10,7 @@ import { Modal } from '@/components/ui/dialog';
interface Props {
movieId?: number;
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
}
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve, isOpen }) => {
@@ -35,18 +36,18 @@ const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey
export const showTrailerModal = create(Trailer);
export default function ToggleTrailer({ movieId }: Props) {
const { data: trailer } = useTrailer({ movieId });
export default function ToggleTrailer({ movieId, children }: Props) {
const { data: trailer, isFetched } = useTrailer({ movieId });
return (
trailer && (
<motion.div
onTap={() => 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>
)
);
return children
? children({ onPlay: () => showTrailerModal({ trailerKey: trailer?.key }), disabled: isFetched && !trailer })
: trailer && (
<motion.div
onTap={() => 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>
);
}