import { useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Eraser } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { BulkActionBar } from '../components/BulkActionBar'; import { CleanupDialog } from '../components/CleanupDialog'; import { PhotoSelectionList } from '../components/PhotoSelectionList'; import { StorageMeter } from '../components/StorageMeter'; import { emptySelection, prune, type Selection } from '../lib/selection'; import { toPhotoItem } from '../lib/toPhotoItem'; import { useMediaPhotos, useMediaStorage } from '../services/hooks'; /** * The media library: every photo of every module, newest first, with where it is used; the storage against its limit; * the "Clean up" preview. Selecting works already (bulk actions come with deleting, after the assumptions are checked). */ export function MediaLibraryPage() { const { t } = useTranslation(); const photos = useMediaPhotos(); const storage = useMediaStorage(); const [chosen, setSelection] = useState(emptySelection); const [cleanupOpen, setCleanupOpen] = useState(false); const items = useMemo(() => (photos.data?.photos ?? []).map((p) => toPhotoItem(p, t)), [photos.data, t]); // Photos that left the list (after a reload) drop out of the selection. const selection = useMemo(() => prune(chosen, items.map((i) => i.id)), [chosen, items]); return (

{t('media.page.title')}

{storage.data && } {photos.isError && (

{t('media.error')}

)} {photos.isPending &&

{t('media.loading')}

} {photos.data && photos.data.modules.length === 0 && (

{t('media.page.noModules')}

)} {photos.data && } setSelection(emptySelection)} />
); }