fix: virtual slides
This commit is contained in:
1 parent
97264226b6
commit
0e56de39db
8 files changed
+22
-34
No files matched your search
@@ -59,7 +59,6 @@ export default function Filter() {
|
|||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
</Card>
|
</Card>
|
||||||
<ScrollBar orientation='horizontal' className='opacity-0' />
|
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
<div className='flex w-full my-4 gap-6 flex-wrap'>
|
<div className='flex w-full my-4 gap-6 flex-wrap'>
|
||||||
<div className='grow flex items-center basis-[250px]'>
|
<div className='grow flex items-center basis-[250px]'>
|
||||||
|
|||||||
+10
-19
@@ -5,7 +5,7 @@ import { createPortal } from 'react-dom';
|
|||||||
import { useAtom } from 'jotai';
|
import { useAtom } from 'jotai';
|
||||||
import { atomWithStorage } from 'jotai/utils';
|
import { atomWithStorage } from 'jotai/utils';
|
||||||
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
|
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 { Swiper, SwiperSlide } from 'swiper/react';
|
||||||
|
|
||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
@@ -21,17 +21,8 @@ import useRandomMovie from './useRandomMovie';
|
|||||||
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||||
|
|
||||||
const creativeEffectProps = {
|
const creativeEffectProps = {
|
||||||
creativeEffect: {
|
effect: 'coverflow',
|
||||||
prev: {
|
modules: [EffectCoverflow, Virtual]
|
||||||
shadow: true,
|
|
||||||
translate: ['-120%', 0, -500]
|
|
||||||
},
|
|
||||||
next: {
|
|
||||||
shadow: true,
|
|
||||||
translate: ['120%', 0, -500]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modules: [EffectCreative]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
@@ -66,18 +57,18 @@ export default function Container() {
|
|||||||
renderCard={() => (
|
renderCard={() => (
|
||||||
<Swiper
|
<Swiper
|
||||||
onSwiper={(instance) => (ref.current = instance)}
|
onSwiper={(instance) => (ref.current = instance)}
|
||||||
effect='creative'
|
lazyPreloadPrevNext={3}
|
||||||
lazyPreloadPrevNext={5}
|
|
||||||
resistance={false}
|
resistance={false}
|
||||||
longSwipesRatio={0.25}
|
longSwipesRatio={0.3}
|
||||||
speed={600}
|
speed={400}
|
||||||
|
virtual
|
||||||
initialSlide={index}
|
initialSlide={index}
|
||||||
onActiveIndexChange={onIndexChange}
|
onActiveIndexChange={onIndexChange}
|
||||||
className='w-[300px] shrink-0'
|
className='w-[300px] shrink-0'
|
||||||
{...creativeEffectProps}
|
{...creativeEffectProps}
|
||||||
>
|
>
|
||||||
{movies?.map((movie) => (
|
{movies?.map((movie, index) => (
|
||||||
<SwiperSlide key={movie.id}>
|
<SwiperSlide key={movie.id} virtualIndex={index}>
|
||||||
<Card movie={movie} />
|
<Card movie={movie} />
|
||||||
</SwiperSlide>
|
</SwiperSlide>
|
||||||
))}
|
))}
|
||||||
@@ -93,7 +84,7 @@ export default function Container() {
|
|||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</Movie>
|
</Movie>
|
||||||
<div className='w-full h-2 max-sm:h-20' />
|
<div className='w-full h-2 max-sm:h-12' />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ import { Swiper } from 'swiper/types';
|
|||||||
|
|
||||||
import useFilters from '@/app/(site)/useFilters';
|
import useFilters from '@/app/(site)/useFilters';
|
||||||
import { randomMovies } from '@/lib/api';
|
import { randomMovies } from '@/lib/api';
|
||||||
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
|
||||||
|
|
||||||
const UPDATE_RATE = 10;
|
const UPDATE_RATE = 10;
|
||||||
|
|
||||||
@@ -22,9 +21,6 @@ const useRandomMovie = () => {
|
|||||||
const { data: movies, refetch } = useQuery({
|
const { data: movies, refetch } = useQuery({
|
||||||
queryKey: ['random-movie', filters],
|
queryKey: ['random-movie', filters],
|
||||||
queryFn: () => randomMovies({ filters }),
|
queryFn: () => randomMovies({ filters }),
|
||||||
select(movies) {
|
|
||||||
return filterUnknownMovies(movies);
|
|
||||||
},
|
|
||||||
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', filters]) || [];
|
||||||
|
|||||||
@@ -24,22 +24,23 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
|||||||
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
|
const handleToggleFavorite = () => (isFavorite ? remove(movie.id) : add(movie));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<div
|
||||||
onDoubleClick={handleToggleFavorite}
|
onDoubleClick={handleToggleFavorite}
|
||||||
onTap={onClick}
|
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-[300px] h-[450px] min-w-[300px] shrink-0 mx-auto',
|
'w-[300px] h-[450px] min-w-[300px] shrink-0 mx-auto',
|
||||||
fit ? 'w-full h-auto xs:w-[300px] xs:h-[450px]' : undefined
|
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
|
<Poster
|
||||||
title={movie.title}
|
title={movie.title}
|
||||||
size={100}
|
size={100}
|
||||||
poster={movie.poster_path}
|
poster={movie.poster_path}
|
||||||
className={fit ? 'h-auto xs:h-full' : undefined}
|
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='h-full w-full mx-auto pt-1 px-3 text-white'>
|
||||||
<div className='grid items-center grid-cols-[1fr_50px]'>
|
<div className='grid items-center grid-cols-[1fr_50px]'>
|
||||||
<Title key={movie.title} title={movie.title} />
|
<Title key={movie.title} title={movie.title} />
|
||||||
@@ -59,8 +60,8 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
|||||||
iconsFillColor='fill-white'
|
iconsFillColor='fill-white'
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
import { ImageOff } from 'lucide-react';
|
import { ImageOff } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -13,9 +12,8 @@ interface Props {
|
|||||||
|
|
||||||
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
|
const Poster: FC<Props> = ({ title, poster, size = 250, className }) => {
|
||||||
return poster ? (
|
return poster ? (
|
||||||
<Image
|
<img
|
||||||
className={cn('rounded-lg mx-auto w-auto h-full object-fill', className)}
|
className={cn('rounded-lg mx-auto w-auto h-full object-fill', className)}
|
||||||
unoptimized
|
|
||||||
height={750}
|
height={750}
|
||||||
width={500}
|
width={500}
|
||||||
src={`https://image.tmdb.org/t/p/w500/${poster}`}
|
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'>
|
<span className='select-none flex w-full items-center ml-auto gap-1 mt-[-8px] justify-between'>
|
||||||
<motion.span
|
<motion.span
|
||||||
onTap={(event) => {
|
onTap={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
toggleFavorite();
|
toggleFavorite();
|
||||||
|
|||||||
+3
-1
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import server from '@/network/server';
|
import server from '@/network/server';
|
||||||
|
|
||||||
|
import filterUnknownMovies from '../filterUnknownMovies';
|
||||||
|
|
||||||
import pirateBay from './parsers/pirate-bay';
|
import pirateBay from './parsers/pirate-bay';
|
||||||
|
|
||||||
export const search = async ({ query, page }: { query: string; page: number }): Promise<MovieDBResponse> => {
|
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]
|
'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> => {
|
export const popularMovies = async ({ page }: { page?: string } = {}): Promise<MovieDBResponse> => {
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
@import url('~swiper/css');
|
@import url('~swiper/css');
|
||||||
@import url('~swiper/css/effect-creative');
|
@import url('~swiper/css/virtual');
|
||||||
@import url('~swiper/css/effect-coverflow');
|
@import url('~swiper/css/effect-coverflow');
|
||||||
|
|
||||||
@layer utilities {
|
@layer utilities {
|
||||||
|
|||||||
Reference in new issue
Block a user