import { Sheet, SheetContent, SheetHeader, SheetTitle } from '@/components/ui/sheet'; import { Spinner } from '@/components/ui/spinner'; import useMediaStore from '@/stores/MediaStore'; import { Edit3 } from 'lucide-react'; import { useEffect } from 'react'; interface EditSidebarProps { isOpen: boolean; onClose: () => void; } export default function EditSidebar({ isOpen, onClose }: EditSidebarProps) { const { memes, backgrounds, isFetchingMemes, isFetchingBackgrounds, currentTab, setCurrentTab, fetchMemes, fetchBackgrounds } = useMediaStore(); // Fetch media based on currentTab when it changes and data isn't fetched yet useEffect(() => { if (currentTab === 'memes' && memes.length === 0 && !isFetchingMemes) { fetchMemes(); } else if (currentTab === 'backgrounds' && backgrounds.length === 0 && !isFetchingBackgrounds) { fetchBackgrounds(); } }, [currentTab]); // Determine display states const isFetching = currentTab === 'memes' ? isFetchingMemes : isFetchingBackgrounds; const media = currentTab === 'memes' ? memes : backgrounds; const mediaType = currentTab === 'memes' ? 'memes' : 'backgrounds'; return ( !open && onClose()}> Edit Media
{/* Background and Meme Selection */}
setCurrentTab('backgrounds')} >
Gaming background
Background
setCurrentTab('memes')} >
Meme character
Meme
{/* Media Grid */} {isFetching && } {!isFetching && media.length === 0 &&
No {mediaType} available.
} {!isFetching && media.length > 0 && (
{media.map((item, index) => (
{currentTab
))}
)}
); }