Continuous Integration / config-asf (pull_request) Successful in 6s
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 11s
Continuous Integration / compile-sites (pull_request) Successful in 1m44s
Continuous Integration / backend-build (pull_request) Successful in 1m49s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m51s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m2s
Continuous Integration / frontend-build (pull_request) Successful in 42s
Continuous Integration / backend-test (pull_request) Failing after 3m56s
Continuous Integration / frontend-lint (pull_request) Successful in 39s
Continuous Integration / frontend-test (pull_request) Successful in 2m33s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
58 lines
2.9 KiB
TypeScript
58 lines
2.9 KiB
TypeScript
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<Selection>(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 (
|
|
<div className="space-y-6" data-testid="media-library-page">
|
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
|
<h1 className="text-2xl font-semibold">{t('media.page.title')}</h1>
|
|
<Button type="button" variant="outline" onClick={() => setCleanupOpen(true)} data-testid="cleanup-open">
|
|
<Eraser className="mr-2 size-4" aria-hidden="true" />
|
|
{t('media.cleanup.open')}
|
|
</Button>
|
|
</div>
|
|
|
|
{storage.data && <StorageMeter storage={storage.data} />}
|
|
|
|
{photos.isError && (
|
|
<p role="alert" className="text-sm text-destructive" data-testid="media-error">
|
|
{t('media.error')}
|
|
</p>
|
|
)}
|
|
{photos.isPending && <p className="text-sm text-muted-foreground">{t('media.loading')}</p>}
|
|
{photos.data && photos.data.modules.length === 0 && (
|
|
<p className="text-sm text-muted-foreground" data-testid="media-no-modules">
|
|
{t('media.page.noModules')}
|
|
</p>
|
|
)}
|
|
{photos.data && <PhotoSelectionList items={items} selection={selection} onSelectionChange={setSelection} />}
|
|
<BulkActionBar count={selection.size} actions={[]} onClear={() => setSelection(emptySelection)} />
|
|
|
|
<CleanupDialog open={cleanupOpen} onOpenChange={setCleanupOpen} />
|
|
</div>
|
|
);
|
|
}
|