fix: virtual slides

This commit is contained in:
ner committed 2024-03-23 13:20:53 +02:00
1 parent 97264226b6
commit 0e56de39db
8 files changed
+22 -34

No files matched your search

-1
View File
@@ -59,7 +59,6 @@ export default function Filter() {
))}
</ul>
</Card>
<ScrollBar orientation='horizontal' className='opacity-0' />
</ScrollArea>
<div className='flex w-full my-4 gap-6 flex-wrap'>
<div className='grow flex items-center basis-[250px]'>
+10 -19
View File
@@ -5,7 +5,7 @@ import { createPortal } from 'react-dom';
import { useAtom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
import { EffectCreative } from 'swiper/modules';
import { EffectCoverflow, Virtual } from 'swiper/modules';
import { Swiper, SwiperSlide } from 'swiper/react';
import Card from '@/components/Movie/Card';
@@ -21,17 +21,8 @@ import useRandomMovie from './useRandomMovie';
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
const creativeEffectProps = {
creativeEffect: {
prev: {
shadow: true,
translate: ['-120%', 0, -500]
},
next: {
shadow: true,
translate: ['120%', 0, -500]
}
},
modules: [EffectCreative]
effect: 'coverflow',
modules: [EffectCoverflow, Virtual]
};
export default function Container() {
@@ -66,18 +57,18 @@ export default function Container() {
renderCard={() => (
<Swiper
onSwiper={(instance) => (ref.current = instance)}
effect='creative'
lazyPreloadPrevNext={5}
lazyPreloadPrevNext={3}
resistance={false}
longSwipesRatio={0.25}
speed={600}
longSwipesRatio={0.3}
speed={400}
virtual
initialSlide={index}
onActiveIndexChange={onIndexChange}
className='w-[300px] shrink-0'
{...creativeEffectProps}
>
{movies?.map((movie) => (
<SwiperSlide key={movie.id}>
{movies?.map((movie, index) => (
<SwiperSlide key={movie.id} virtualIndex={index}>
<Card movie={movie} />
</SwiperSlide>
))}
@@ -93,7 +84,7 @@ export default function Container() {
</Button>
</div>
</Movie>
<div className='w-full h-2 max-sm:h-20' />
<div className='w-full h-2 max-sm:h-12' />
</>
);
}
-4
View File
@@ -6,7 +6,6 @@ import { Swiper } from 'swiper/types';
import useFilters from '@/app/(site)/useFilters';
import { randomMovies } from '@/lib/api';
import filterUnknownMovies from '@/lib/filterUnknownMovies';
const UPDATE_RATE = 10;
@@ -22,9 +21,6 @@ const useRandomMovie = () => {
const { data: movies, refetch } = useQuery({
queryKey: ['random-movie', filters],
queryFn: () => randomMovies({ filters }),
select(movies) {
return filterUnknownMovies(movies);
},
structuralSharing(_, newData) {
const uniqueIds: Record<string, number> = {};
const current = queryClient.getQueryData<Movie[]>(['random-movie', filters]) || [];
+6 -5
View File
@@ -24,22 +24,23 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
return (
<motion.div
<div
onDoubleClick={handleToggleFavorite}
onTap={onClick}
className={cn(
'w-[300px] h-[450px] min-w-[300px] shrink-0 mx-auto',
fit ? 'w-full h-auto xs:w-[300px] xs:h-[450px]' : undefined
)}
>
<div className='flex flex-col w-full h-full mx-auto relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg'>
<motion.div className='flex flex-col w-full h-full mx-auto relative bg-card text-card-foreground shadow-sm transition-shadow hover:shadow-lg overflow-hidden rounded-lg'>
<motion.div onTap={onClick} className='flex'>
<Poster
title={movie.title}
size={100}
poster={movie.poster_path}
className={fit ? 'h-auto xs:h-full' : undefined}
/>
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75'>
</motion.div>
<div className='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75 rounded-t-lg'>
<div className='h-full w-full mx-auto pt-1 px-3 text-white'>
<div className='grid items-center grid-cols-[1fr_50px]'>
<Title key={movie.title} title={movie.title} />
@@ -59,8 +60,8 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
iconsFillColor='fill-white'
/>
</div>
</div>
</motion.div>
</div>
);
};
+1 -3
View File
@@ -1,6 +1,5 @@
import { FC } from 'react';
import { ImageOff } from 'lucide-react';
import Image from 'next/image';
import { cn } from '@/lib/utils';
@@ -13,9 +12,8 @@ interface Props {
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
return poster ? (
<Image
<img
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}`}
@@ -14,6 +14,7 @@ const Rating: FC<Props> = ({ isFavorite, rating, toggleFavorite, iconsFillColor
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
<motion.span
onTap={(event) => {
event.preventDefault();
event.stopPropagation();
toggleFavorite();
+3 -1
View File
@@ -2,6 +2,8 @@
import server from '@/network/server';
import filterUnknownMovies from '../filterUnknownMovies';
import pirateBay from './parsers/pirate-bay';
export const search = async ({ query, page }: { query: string; page: number }): Promise<MovieDBResponse> => {
@@ -26,7 +28,7 @@ export const randomMovies = async ({ filters }: { filters: Partial<Filters> }):
'release_date.lte': filters.year?.[1]
}
})
.then((data: unknown) => (data as MovieDBResponse).results);
.then((data: unknown) => filterUnknownMovies((data as MovieDBResponse).results));
};
export const popularMovies = async ({ page }: { page?: string } = {}): Promise<MovieDBResponse> => {
+1 -1
View File
@@ -3,7 +3,7 @@
@tailwind utilities;
@import url('~swiper/css');
@import url('~swiper/css/effect-creative');
@import url('~swiper/css/virtual');
@import url('~swiper/css/effect-coverflow');
@layer utilities {