fix: mobile menu
This commit is contained in:
1 parent
84a631b56a
commit
cd8928ab54
6 files changed
+54
-23
No files matched your search
+30
-17
@@ -1,12 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { useAtom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { ArrowLeft, ArrowRight, SlidersHorizontal } from 'lucide-react';
|
||||
|
||||
import Movie from '@/components/Movie/Preview';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import useMounted from '@/hooks/useMounted';
|
||||
import { genres } from '@/lib/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
@@ -19,6 +21,7 @@ export default function Container() {
|
||||
const [isShowFilter, setIsShowFilter] = useAtom(isShowFilterAtom);
|
||||
const { movie, next, previous, hasPrevious } = useRandomMovie();
|
||||
const [direction, setDirection] = useState(0);
|
||||
const isMounted = useMounted();
|
||||
|
||||
useEffect(() => {
|
||||
const queryClient = getQueryClient();
|
||||
@@ -34,23 +37,33 @@ export default function Container() {
|
||||
return (
|
||||
<>
|
||||
{isShowFilter && <Filter />}
|
||||
<div className='gap-2 flex bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60 mb-2 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='p-2 grow' onClick={handleChangeMovie(-1)} disabled={!hasPrevious} title='Previous movie'>
|
||||
<ArrowLeft size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
<Button
|
||||
className='p-2'
|
||||
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
||||
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
||||
variant={isShowFilter ? 'outline' : 'default'}
|
||||
>
|
||||
<SlidersHorizontal size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
<Button className='p-2 grow' onClick={handleChangeMovie(1)} title='Next movie'>
|
||||
<ArrowRight size={24} strokeWidth={1} />
|
||||
</Button>
|
||||
</div>
|
||||
<Movie movie={movie} direction={direction} />
|
||||
<Movie movie={movie} direction={direction}>
|
||||
<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-12 sm:h-8'
|
||||
onClick={handleChangeMovie(-1)}
|
||||
disabled={!hasPrevious}
|
||||
title='Previous movie'
|
||||
>
|
||||
<ArrowLeft size={24} />
|
||||
</Button>
|
||||
{isMounted &&
|
||||
createPortal(
|
||||
<Button
|
||||
className='p-2'
|
||||
onClick={() => setIsShowFilter((isShow) => !isShow)}
|
||||
title={isShowFilter ? 'Hide filters' : 'Show filters'}
|
||||
variant='ghost'
|
||||
>
|
||||
<SlidersHorizontal size={19} />
|
||||
</Button>,
|
||||
document.getElementById('actions')!
|
||||
)}
|
||||
<Button className='grow h-12 sm:h-8' onClick={handleChangeMovie(1)} title='Next movie'>
|
||||
<ArrowRight size={24} />
|
||||
</Button>
|
||||
</div>
|
||||
</Movie>
|
||||
<div className='w-full h-2 max-sm:h-20' />
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Menu } from 'lucide-react';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
@@ -31,11 +32,12 @@ interface Props {
|
||||
}
|
||||
|
||||
export function NavigationSmall({ className }: Props) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const currentPath = usePathname();
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<DropdownMenu>
|
||||
<DropdownMenu open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant='ghost' size='icon'>
|
||||
<Menu size={19} />
|
||||
@@ -45,7 +47,9 @@ export function NavigationSmall({ className }: Props) {
|
||||
<DropdownMenuRadioGroup value={currentPath}>
|
||||
{paths.map(({ path, title }) => (
|
||||
<Link href={path} legacyBehavior shallow key={path}>
|
||||
<DropdownMenuRadioItem value={path}>{title}</DropdownMenuRadioItem>
|
||||
<DropdownMenuRadioItem value={path} onClick={() => setIsOpen(false)}>
|
||||
{title}
|
||||
</DropdownMenuRadioItem>
|
||||
</Link>
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
|
||||
@@ -18,6 +18,7 @@ const Header: FC = () => (
|
||||
<div className='flex items-center gap-2'>
|
||||
<ToggleTheme />
|
||||
<ToggleSearch />
|
||||
<div id='actions' className='empty:hidden' />
|
||||
<NavigationSmall className='flex sm:hidden' />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,13 +17,13 @@ export default function Actions({ onClose, movie }: Props) {
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
className='h-8 grow'
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() => showTorrentsModal({ title: movie.title, year: new Date(movie.release_date).getFullYear() })}
|
||||
>
|
||||
Torrents
|
||||
</Button>
|
||||
<Button
|
||||
className='h-8 grow'
|
||||
className='h-8 flex-grow w-[50%]'
|
||||
onClick={() => {
|
||||
router.push(`/similar?movieId=${movie.id}&title=${encodeURIComponent(movie.title)}`);
|
||||
onClose?.();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { FC } from 'react';
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { AnimatePresence, motion } from 'framer-motion';
|
||||
|
||||
import Credits from '@/components/Movie/components/Credits';
|
||||
@@ -17,6 +17,7 @@ interface Props {
|
||||
className?: string;
|
||||
direction?: number;
|
||||
onClose?: () => void;
|
||||
children?: ReactNode;
|
||||
}
|
||||
|
||||
const variants = {
|
||||
@@ -29,7 +30,7 @@ const variants = {
|
||||
exit: (direction: number) => ({ scale: 0.8, opacity: 1, x: direction * -300 })
|
||||
};
|
||||
|
||||
const Preview: FC<Props> = ({ movie, className, direction, onClose }) => {
|
||||
const Preview: FC<Props> = ({ movie, className, direction, onClose, children }) => {
|
||||
if (!movie) return null;
|
||||
|
||||
return (
|
||||
@@ -54,6 +55,7 @@ const Preview: FC<Props> = ({ movie, className, direction, onClose }) => {
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
<div className='flex flex-col grow'>
|
||||
{children && <div className='flex w-full mb-2 gap-2'>{children}</div>}
|
||||
<div className='flex w-full gap-2'>
|
||||
<Actions movie={movie} onClose={onClose} />
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { useLayoutEffect, useState } from 'react';
|
||||
|
||||
export default function useMounted() {
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
setIsMounted(true);
|
||||
}, []);
|
||||
|
||||
return isMounted;
|
||||
}
|
||||
Reference in new issue
Block a user