2024-02-16 01:49:19 +00:00
|
|
|
'use client';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-02-16 01:49:19 +00:00
|
|
|
import { Menu } from 'lucide-react';
|
|
|
|
import { usePathname } from 'next/navigation';
|
|
|
|
import { useMobileSidebar } from '@/hooks/use-mobile-sidebar';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
2024-02-16 01:49:19 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
import { Sheet, SheetContent } from '@/components/ui/sheet';
|
|
|
|
import { Sidebar } from './sidebar';
|
2024-02-15 02:30:10 +00:00
|
|
|
|
|
|
|
export const MobileSidebar = () => {
|
|
|
|
const pathname = usePathname();
|
|
|
|
const [isMounted, setIsMounted] = useState(false);
|
|
|
|
|
|
|
|
const onOpen = useMobileSidebar((state) => state.onOpen);
|
|
|
|
const onClose = useMobileSidebar((state) => state.onClose);
|
|
|
|
const isOpen = useMobileSidebar((state) => state.isOpen);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setIsMounted(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
onClose();
|
|
|
|
}, [pathname, onClose]);
|
|
|
|
|
|
|
|
if (!isMounted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Button
|
|
|
|
onClick={onOpen}
|
2024-02-16 01:49:19 +00:00
|
|
|
className='mr-2 block md:hidden'
|
|
|
|
variant='ghost'
|
|
|
|
size='sm'
|
2024-02-15 02:30:10 +00:00
|
|
|
>
|
2024-02-16 01:49:19 +00:00
|
|
|
<Menu className='h-4 w-4' />
|
2024-02-15 02:30:10 +00:00
|
|
|
</Button>
|
|
|
|
<Sheet open={isOpen} onOpenChange={onClose}>
|
2024-02-16 01:49:19 +00:00
|
|
|
<SheetContent side='left' className='p-2 pt-10'>
|
|
|
|
<Sidebar storageKey='t-sidebar-mobile-state' />
|
2024-02-15 02:30:10 +00:00
|
|
|
</SheetContent>
|
|
|
|
</Sheet>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|