fix: swiper
This commit is contained in:
1 parent
1b87355925
commit
1aa145a98c
13 files changed
+125
-123
No files matched your search
@@ -27,6 +27,7 @@ yarn-error.log*
|
|||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env*.local
|
.env*.local
|
||||||
|
.env
|
||||||
|
|
||||||
# vercel
|
# vercel
|
||||||
.vercel
|
.vercel
|
||||||
|
|||||||
+37
-28
@@ -1,12 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useMemo, useRef } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
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 { EffectCoverflow, Virtual } from 'swiper/modules';
|
import { EffectCoverflow, Virtual } from 'swiper/modules';
|
||||||
import { Swiper, SwiperSlide } from 'swiper/react';
|
import { Swiper, SwiperProps, SwiperSlide } from 'swiper/react';
|
||||||
|
|
||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
import Movie from '@/components/Movie/Preview';
|
import Movie from '@/components/Movie/Preview';
|
||||||
@@ -20,15 +20,24 @@ import useRandomMovie from './useRandomMovie';
|
|||||||
|
|
||||||
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
const isShowFilterAtom = atomWithStorage('is-show-filters', false);
|
||||||
|
|
||||||
const creativeEffectProps = {
|
const slideEffectProps: SwiperProps = {
|
||||||
effect: 'coverflow',
|
effect: 'coverflow',
|
||||||
|
coverflowEffect: {
|
||||||
|
slideShadows: false,
|
||||||
|
depth: 200
|
||||||
|
},
|
||||||
|
virtual: {
|
||||||
|
addSlidesAfter: 3,
|
||||||
|
addSlidesBefore: 3
|
||||||
|
},
|
||||||
modules: [EffectCoverflow, Virtual]
|
modules: [EffectCoverflow, Virtual]
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function Container() {
|
export default function Container() {
|
||||||
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||||
const { ref, hasPrevious, movies, movie, next, previous, index, onIndexChange } = useRandomMovie();
|
const { ref, hasPrevious, movies, movie, next, previous, index, onDrag, onIndexChange } = useRandomMovie();
|
||||||
const isMounted = useMounted();
|
const isMounted = useMounted();
|
||||||
|
const initialIndex = useRef(index);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const queryClient = getQueryClient();
|
const queryClient = getQueryClient();
|
||||||
@@ -36,6 +45,29 @@ export default function Container() {
|
|||||||
queryClient.prefetchQuery({ queryKey: ['genres'], queryFn: () => genres() });
|
queryClient.prefetchQuery({ queryKey: ['genres'], queryFn: () => genres() });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const slides = useMemo(
|
||||||
|
() => (
|
||||||
|
<Swiper
|
||||||
|
onSwiper={(instance) => (ref.current = instance)}
|
||||||
|
lazyPreloadPrevNext={3}
|
||||||
|
longSwipesRatio={0.2}
|
||||||
|
speed={500}
|
||||||
|
initialSlide={initialIndex.current}
|
||||||
|
onActiveIndexChange={onIndexChange}
|
||||||
|
onTouchMove={(swiper) => onDrag(swiper)}
|
||||||
|
className='xs:w-[300px] w-full shrink-0'
|
||||||
|
{...slideEffectProps}
|
||||||
|
>
|
||||||
|
{movies?.map((movie, index) => (
|
||||||
|
<SwiperSlide key={movie.id} virtualIndex={index}>
|
||||||
|
<Card fit movie={movie} />
|
||||||
|
</SwiperSlide>
|
||||||
|
))}
|
||||||
|
</Swiper>
|
||||||
|
),
|
||||||
|
[movies, onDrag, onIndexChange, ref]
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isShowFilter && <Filter />}
|
{isShowFilter && <Filter />}
|
||||||
@@ -51,30 +83,7 @@ export default function Container() {
|
|||||||
</Button>,
|
</Button>,
|
||||||
document.getElementById('actions')!
|
document.getElementById('actions')!
|
||||||
)}
|
)}
|
||||||
<Movie
|
<Movie movie={movie} className='bg-background rounded-md' card={slides}>
|
||||||
movie={movie}
|
|
||||||
className='bg-background rounded-md'
|
|
||||||
renderCard={() => (
|
|
||||||
<Swiper
|
|
||||||
onSwiper={(instance) => (ref.current = instance)}
|
|
||||||
lazyPreloadPrevNext={3}
|
|
||||||
resistance={false}
|
|
||||||
longSwipesRatio={0.3}
|
|
||||||
speed={400}
|
|
||||||
virtual
|
|
||||||
initialSlide={index}
|
|
||||||
onActiveIndexChange={onIndexChange}
|
|
||||||
className='w-[300px] shrink-0'
|
|
||||||
{...creativeEffectProps}
|
|
||||||
>
|
|
||||||
{movies?.map((movie, index) => (
|
|
||||||
<SwiperSlide key={movie.id} virtualIndex={index}>
|
|
||||||
<Card movie={movie} />
|
|
||||||
</SwiperSlide>
|
|
||||||
))}
|
|
||||||
</Swiper>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className='gap-2 flex w-full bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:px-2 max-sm:mb-0'>
|
<div className='gap-2 flex w-full bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 lg:static max-sm:z-10 max-sm:fixed max-sm:bottom-0 max-sm:left-0 max-sm:w-full max-sm:p-2 max-sm:px-2 max-sm:mb-0'>
|
||||||
<Button className='grow h-8' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
<Button className='grow h-8' onClick={previous} disabled={!hasPrevious} title='Previous movie'>
|
||||||
<ArrowLeft size={24} />
|
<ArrowLeft size={24} />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { Swiper } from 'swiper/types';
|
import { Swiper } from 'swiper/types';
|
||||||
|
|
||||||
@@ -17,6 +17,7 @@ const useRandomMovie = () => {
|
|||||||
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
const indexByFilter = previousIndexes[JSON.stringify(filters)];
|
||||||
const [index, setIndex] = useState(indexByFilter);
|
const [index, setIndex] = useState(indexByFilter);
|
||||||
const ref = useRef<Swiper>();
|
const ref = useRef<Swiper>();
|
||||||
|
const timeout = useRef<NodeJS.Timeout>();
|
||||||
|
|
||||||
const { data: movies, refetch } = useQuery({
|
const { data: movies, refetch } = useQuery({
|
||||||
queryKey: ['random-movie', filters],
|
queryKey: ['random-movie', filters],
|
||||||
@@ -49,13 +50,30 @@ const useRandomMovie = () => {
|
|||||||
movies,
|
movies,
|
||||||
movie: movies?.[index],
|
movie: movies?.[index],
|
||||||
hasPrevious: index > 0,
|
hasPrevious: index > 0,
|
||||||
onIndexChange: ({ activeIndex }: Swiper) => {
|
onIndexChange: useCallback(
|
||||||
if ((activeIndex && activeIndex % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
({ activeIndex }: Swiper) => {
|
||||||
refetch();
|
if ((activeIndex && activeIndex % UPDATE_RATE === 0) || movies!.length < UPDATE_RATE) {
|
||||||
}
|
refetch();
|
||||||
previousIndexes[JSON.stringify(filters)] = activeIndex;
|
}
|
||||||
setIndex(activeIndex);
|
clearTimeout(timeout.current);
|
||||||
},
|
previousIndexes[JSON.stringify(filters)] = activeIndex;
|
||||||
|
timeout.current = setTimeout(() => {
|
||||||
|
setIndex(activeIndex);
|
||||||
|
}, 100);
|
||||||
|
},
|
||||||
|
[movies, filters]
|
||||||
|
),
|
||||||
|
onDrag: useCallback(
|
||||||
|
({ activeIndex }: Swiper) => {
|
||||||
|
clearTimeout(timeout.current);
|
||||||
|
timeout.current = setTimeout(() => {
|
||||||
|
if (index === activeIndex) return;
|
||||||
|
|
||||||
|
setIndex(activeIndex);
|
||||||
|
}, 100);
|
||||||
|
},
|
||||||
|
[index]
|
||||||
|
),
|
||||||
next,
|
next,
|
||||||
previous,
|
previous,
|
||||||
index,
|
index,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Input } from '@/components/ui/input';
|
|||||||
|
|
||||||
import useSearch from './useSearch';
|
import useSearch from './useSearch';
|
||||||
|
|
||||||
const Search: FC<InstanceProps<void>> = ({ isOpen, onResolve }) => {
|
const Search: FC<InstanceProps<void>> = ({ onResolve }) => {
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [query, setQuery] = useState('');
|
const [query, setQuery] = useState('');
|
||||||
const timeout = useRef<NodeJS.Timeout>();
|
const timeout = useRef<NodeJS.Timeout>();
|
||||||
@@ -34,10 +34,11 @@ const Search: FC<InstanceProps<void>> = ({ isOpen, onResolve }) => {
|
|||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
handleReset();
|
handleReset();
|
||||||
|
return onResolve();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='block p-3 max-w-[950px]' isOpen={isOpen} onClose={() => onResolve()}>
|
<Modal className='block p-3 max-w-[950px]' onClose={handleClose}>
|
||||||
<div className='relative'>
|
<div className='relative'>
|
||||||
<Input
|
<Input
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
|||||||
<div
|
<div
|
||||||
onDoubleClick={handleToggleFavorite}
|
onDoubleClick={handleToggleFavorite}
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-[300px] h-[450px] min-w-[300px] shrink-0 mx-auto',
|
'w-[300px] h-[450px] min-w-[300px] min-h-[450px] 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
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -37,7 +37,7 @@ const Card: FC<Props> = ({ movie, onClick, fit }) => {
|
|||||||
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 min-h-[450px] xs:h-full' : undefined}
|
||||||
/>
|
/>
|
||||||
</motion.div>
|
</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='absolute left-0 top-0 w-full h-20 bg-gradient-to-t from-transparent to-black opacity-75 rounded-t-lg'>
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import { FC, Fragment, useLayoutEffect, useState } from 'react';
|
|||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
|
||||||
import Card from '@/components/Movie/Card';
|
import Card from '@/components/Movie/Card';
|
||||||
import Preview from '@/components/Movie/Preview';
|
import { showPreviewModal } from '@/components/Movie/Preview';
|
||||||
import { Modal } from '@/components/ui/dialog';
|
|
||||||
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
import filterUnknownMovies from '@/lib/filterUnknownMovies';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -32,7 +31,6 @@ const item = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = true, onPreviewClose }) => {
|
const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = true, onPreviewClose }) => {
|
||||||
const [movie, setMovie] = useState<Movie | null>(null);
|
|
||||||
const [loader, setLoader] = useState<HTMLLIElement>();
|
const [loader, setLoader] = useState<HTMLLIElement>();
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@@ -74,7 +72,7 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
|
|||||||
className='flex cursor-pointer'
|
className='flex cursor-pointer'
|
||||||
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
ref={isAnchor ? (element) => setLoader(element!) : undefined}
|
||||||
>
|
>
|
||||||
<Card fit movie={movie} onClick={() => setMovie(movie)} />
|
<Card fit movie={movie} onClick={() => showPreviewModal({ movie, onClose: onPreviewClose })} />
|
||||||
</motion.li>
|
</motion.li>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@@ -82,21 +80,6 @@ const List: FC<Props> = ({ pages, hasNextPage, fetchNextPage, withBottomGap = tr
|
|||||||
))}
|
))}
|
||||||
</motion.ul>
|
</motion.ul>
|
||||||
{withBottomGap && <div className='h-4 w-full' />}
|
{withBottomGap && <div className='h-4 w-full' />}
|
||||||
<Modal isOpen={Boolean(movie)} onClose={() => setMovie(null)} className='block p-0'>
|
|
||||||
{movie && (
|
|
||||||
<Preview
|
|
||||||
fit
|
|
||||||
key={movie.id}
|
|
||||||
movie={movie}
|
|
||||||
className='border-none'
|
|
||||||
onClose={() => {
|
|
||||||
setMovie(null);
|
|
||||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
||||||
onPreviewClose?.();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Modal>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { FC, ReactNode } from 'react';
|
import { FC, ReactNode } from 'react';
|
||||||
|
import { create, InstanceProps } from 'react-modal-promise';
|
||||||
|
|
||||||
import Credits from '@/components/Movie/components/Credits';
|
import Credits from '@/components/Movie/components/Credits';
|
||||||
|
import { Modal } from '@/components/ui/dialog';
|
||||||
import { Separator } from '@/components/ui/separator';
|
import { Separator } from '@/components/ui/separator';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -16,16 +18,16 @@ interface Props {
|
|||||||
className?: string;
|
className?: string;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
renderCard?: () => ReactNode;
|
card?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Preview: FC<Props> = ({ movie, className, onClose, children, renderCard, fit }) => {
|
const Preview: FC<Props> = ({ movie, className, onClose, children, card, fit }) => {
|
||||||
if (!movie) return null;
|
if (!movie) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
<div className={cn('rounded-xl text-card-foreground', { 'p-2': Boolean(onClose) }, className)}>
|
||||||
<div className='flex flex-col lg:flex-row max-w-[100%] gap-2'>
|
<div className='flex flex-col lg:flex-row max-w-[100%] gap-2'>
|
||||||
{renderCard?.() || <Card fit={fit} movie={movie} />}
|
{card || <Card fit={fit} movie={movie} />}
|
||||||
<div className='flex flex-col grow'>
|
<div className='flex flex-col grow'>
|
||||||
{children && <div className='flex hover-none:hidden w-full mb-2 gap-2'>{children}</div>}
|
{children && <div className='flex hover-none:hidden w-full mb-2 gap-2'>{children}</div>}
|
||||||
<div className='flex w-full gap-2'>
|
<div className='flex w-full gap-2'>
|
||||||
@@ -42,4 +44,19 @@ const Preview: FC<Props> = ({ movie, className, onClose, children, renderCard, f
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const showPreviewModal = create(({ onResolve, onClose, movie }: Props & InstanceProps<void>) => (
|
||||||
|
<Modal className='block p-0' onClose={onResolve}>
|
||||||
|
<Preview
|
||||||
|
fit
|
||||||
|
movie={movie}
|
||||||
|
className='border-none'
|
||||||
|
onClose={() => {
|
||||||
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||||
|
onClose?.();
|
||||||
|
onResolve();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
));
|
||||||
|
|
||||||
export default Preview;
|
export default Preview;
|
||||||
@@ -51,10 +51,10 @@ const TableHeadSortable = ({
|
|||||||
|
|
||||||
const hostAtom = atomWithStorage<string>('magnet-host', '');
|
const hostAtom = atomWithStorage<string>('magnet-host', '');
|
||||||
|
|
||||||
const showHostManagerModal = create(({ onResolve, isOpen }) => {
|
const showHostManagerModal = create(({ onResolve }) => {
|
||||||
const [host, setHost] = useAtom(hostAtom);
|
const [host, setHost] = useAtom(hostAtom);
|
||||||
return (
|
return (
|
||||||
<Modal className='p-3 max-w-[200px] m-auto' isOpen={isOpen} onClose={() => onResolve()}>
|
<Modal className='p-3 max-w-[200px] m-auto' onClose={onResolve}>
|
||||||
<Input
|
<Input
|
||||||
autoFocus
|
autoFocus
|
||||||
placeholder='Enter host of Elementum'
|
placeholder='Enter host of Elementum'
|
||||||
@@ -66,7 +66,7 @@ const showHostManagerModal = create(({ onResolve, isOpen }) => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
const Torrents: FC<Props> = ({ title, year, isOpen, onResolve }) => {
|
const Torrents: FC<Props> = ({ title, year, onResolve }) => {
|
||||||
const hosts = useAtomValue(hostAtom);
|
const hosts = useAtomValue(hostAtom);
|
||||||
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
const [sorting, setSorting] = useState<Sorting>({ by: ORDER.seeders });
|
||||||
const [withYear, setWithYear] = useState(true);
|
const [withYear, setWithYear] = useState(true);
|
||||||
@@ -87,7 +87,7 @@ const Torrents: FC<Props> = ({ title, year, isOpen, onResolve }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal className='p-0' isOpen={isOpen} onClose={() => onResolve()}>
|
<Modal className='p-0' onClose={onResolve}>
|
||||||
<Table className='rounded-xl overflow-hidden'>
|
<Table className='rounded-xl overflow-hidden'>
|
||||||
<TableHeader>
|
<TableHeader>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|||||||
@@ -13,15 +13,11 @@ interface Props {
|
|||||||
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
children?: ({ onPlay, disabled }: { onPlay: () => void; disabled: boolean }) => ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve, isOpen }) => {
|
const Trailer: FC<{ trailerKey?: string } & InstanceProps<void>> = ({ trailerKey, onResolve }) => {
|
||||||
if (!trailerKey) return;
|
if (!trailerKey) return;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9' onClose={onResolve}>
|
||||||
className='block p-0 min-h-[400px] border-none aspect-w-16 aspect-h-9'
|
|
||||||
onClose={() => onResolve()}
|
|
||||||
isOpen={isOpen}
|
|
||||||
>
|
|
||||||
<iframe
|
<iframe
|
||||||
allow='autoplay'
|
allow='autoplay'
|
||||||
className='border-none rounded-lg'
|
className='border-none rounded-lg'
|
||||||
|
|||||||
+26
-46
@@ -1,9 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import { useState } from 'react';
|
||||||
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
||||||
import { AnimatePresence, motion, useDragControls } from 'framer-motion';
|
import { X } from 'lucide-react';
|
||||||
import { GripHorizontal } from 'lucide-react';
|
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
@@ -12,23 +12,19 @@ const Dialog = DialogPrimitive.Root;
|
|||||||
const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => <DialogPrimitive.Portal {...props} />;
|
const DialogPortal = ({ ...props }: DialogPrimitive.DialogPortalProps) => <DialogPrimitive.Portal {...props} />;
|
||||||
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
|
DialogPortal.displayName = DialogPrimitive.Portal.displayName;
|
||||||
|
|
||||||
const transition = { duration: 0.35, type: 'spring', bounce: 0 };
|
|
||||||
|
|
||||||
const DialogOverlay = React.forwardRef<
|
const DialogOverlay = React.forwardRef<
|
||||||
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
React.ElementRef<typeof DialogPrimitive.Overlay>,
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, children, ...props }, ref) => (
|
||||||
<DialogPrimitive.Overlay ref={ref} {...props}>
|
<DialogPrimitive.Overlay ref={ref} {...props}>
|
||||||
<motion.div
|
<div
|
||||||
onScroll={props.onScroll}
|
className={cn(
|
||||||
className={cn('fixed inset-0 z-50 transform-gpu backdrop-brightness-50 select-none', className)}
|
'fixed inset-0 z-50 bg-black/60 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',
|
||||||
transition={transition}
|
className
|
||||||
initial={{ opacity: 0 }}
|
)}
|
||||||
animate={{ opacity: 1 }}
|
|
||||||
exit={{ opacity: 0 }}
|
|
||||||
>
|
>
|
||||||
{props?.children}
|
{children}
|
||||||
</motion.div>
|
</div>
|
||||||
</DialogPrimitive.Overlay>
|
</DialogPrimitive.Overlay>
|
||||||
));
|
));
|
||||||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
|
||||||
@@ -37,38 +33,19 @@ const DialogContent = React.forwardRef<
|
|||||||
React.ElementRef<typeof DialogPrimitive.Content>,
|
React.ElementRef<typeof DialogPrimitive.Content>,
|
||||||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { onClose?: () => void }
|
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { onClose?: () => void }
|
||||||
>(({ className, children, ...props }, ref) => {
|
>(({ className, children, ...props }, ref) => {
|
||||||
const controls = useDragControls();
|
|
||||||
return (
|
return (
|
||||||
<DialogPortal>
|
<DialogPortal>
|
||||||
<DialogOverlay className='overflow-auto flex justify-center select-none'>
|
<DialogOverlay className='overflow-auto flex justify-center select-none'>
|
||||||
<motion.div
|
<div className='absolute top-[20vh] max-w-[1000px] w-[calc(100%-24px)] gap-4 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-50 data-[state=open]:zoom-in-50 select-none'>
|
||||||
className='absolute top-[20vh] max-w-[1000px] w-[calc(100%-24px)] select-none'
|
|
||||||
transition={transition}
|
|
||||||
initial={{ top: '100vh' }}
|
|
||||||
animate={{ top: '20vh' }}
|
|
||||||
exit={{ top: '100vh' }}
|
|
||||||
drag='y'
|
|
||||||
dragConstraints={{ top: 0, bottom: 0 }}
|
|
||||||
onDragEnd={(_, info) => info.offset.y > 100 && props.onClose?.()}
|
|
||||||
dragListener={false}
|
|
||||||
dragControls={controls}
|
|
||||||
dragElastic={0.8}
|
|
||||||
>
|
|
||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn('gap-4 border bg-background p-6 shadow-lg rounded-xl relative', className)}
|
className={cn('gap-4 border bg-background p-6 shadow-lg rounded-xl relative', className)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<motion.div
|
|
||||||
className='w-full h-10 flex p-2 justify-center cursor-grab absolute top-[-36px] z-10'
|
|
||||||
onPointerDown={(e) => controls.start(e)}
|
|
||||||
>
|
|
||||||
<GripHorizontal color='white' />
|
|
||||||
</motion.div>
|
|
||||||
{children}
|
{children}
|
||||||
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
<div className='absolute w-full block h-[20vh] pointer-events-none' />
|
||||||
</DialogPrimitive.Content>
|
</DialogPrimitive.Content>
|
||||||
</motion.div>
|
</div>
|
||||||
</DialogOverlay>
|
</DialogOverlay>
|
||||||
</DialogPortal>
|
</DialogPortal>
|
||||||
);
|
);
|
||||||
@@ -78,19 +55,22 @@ DialogContent.displayName = DialogPrimitive.Content.displayName;
|
|||||||
const Modal: React.FC<{
|
const Modal: React.FC<{
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
isOpen: boolean;
|
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}> = ({ children, onClose, isOpen, className }) => {
|
}> = ({ children, onClose, className }) => {
|
||||||
|
const [open, setOpen] = useState(true);
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
console.log(onClose());
|
||||||
|
console.log('closing');
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatePresence>
|
<Dialog open={open} onOpenChange={handleClose}>
|
||||||
{isOpen && (
|
<DialogContent className={className} onClose={onClose}>
|
||||||
<Dialog defaultOpen={true} onOpenChange={onClose}>
|
{children}
|
||||||
<DialogContent forceMount className={className} onClose={onClose}>
|
</DialogContent>
|
||||||
{children}
|
</Dialog>
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
)}
|
|
||||||
</AnimatePresence>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -3,7 +3,6 @@
|
|||||||
import { ReactNode, useState } from 'react';
|
import { ReactNode, useState } from 'react';
|
||||||
import ModalContainer from 'react-modal-promise';
|
import ModalContainer from 'react-modal-promise';
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
|
||||||
|
|
||||||
import { queryClientOptions } from '@/lib/queryClient';
|
import { queryClientOptions } from '@/lib/queryClient';
|
||||||
import ThemeProvider from '@/providers/Theme';
|
import ThemeProvider from '@/providers/Theme';
|
||||||
@@ -14,8 +13,7 @@ const Providers = ({ children, theme }: { children: ReactNode; theme?: Theme })
|
|||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
<ThemeProvider theme={theme}>{children}</ThemeProvider>
|
||||||
<ModalContainer />
|
<ModalContainer exitTimeout={500} enterTimeout={0} />
|
||||||
{/* <ReactQueryDevtools initialIsOpen={false} /> */}
|
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -94,7 +94,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
user-select: none;
|
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
-webkit-touch-callout: none;
|
-webkit-touch-callout: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
extend: {
|
extend: {
|
||||||
screens: {
|
screens: {
|
||||||
xs: '400px'
|
xs: '500px'
|
||||||
},
|
},
|
||||||
colors: {
|
colors: {
|
||||||
border: 'hsl(var(--border))',
|
border: 'hsl(var(--border))',
|
||||||
|
|||||||
Reference in new issue
Block a user