Mediabibliotheek en Hero: definitief verwijderen en prullenbak legen, kiezen uit bibliotheek per slide, uitsnede direct zonder opslaan, teller per batch; aannamelijst
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { ImagePicker } from '@/features/media/components/ImagePicker';
|
||||
import type { PhotoItem } from '@/features/media/components/PhotoSelectionList';
|
||||
import { toPhotoItem } from '@/features/media/lib/toPhotoItem';
|
||||
import { useMediaPhotos } from '@/features/media/services/hooks';
|
||||
import { useUploadHeroImage } from '../services/hooks';
|
||||
import type { HeroImageDto } from '../services/types';
|
||||
|
||||
interface LibraryPickerDialogProps {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
/** The hero image the slide has now (a library id is `hero:` plus this). */
|
||||
currentImageId: string | null;
|
||||
/** Which photo was chosen (the hero image id) and, for a photo uploaded here, the image the server answered with. */
|
||||
onChoose: (imageId: string, uploaded?: HeroImageDto) => void;
|
||||
maxUploadBytes: number;
|
||||
limitsText?: string;
|
||||
slideNumber: number;
|
||||
}
|
||||
|
||||
const MODULE = 'hero';
|
||||
|
||||
/**
|
||||
* "Choose from the library" for a slide: the photos of the media library that a hero slide can use (now the hero's own
|
||||
* photos, also those that are in no slide; never the trash), or a new photo uploaded on the spot with the hero's own upload
|
||||
* (same checks and limits, variants cut in the background). A photo that is already in another slide can be chosen again:
|
||||
* it is the same photo, so its crop is shared (assumption 36).
|
||||
*/
|
||||
export function LibraryPickerDialog({ open, onOpenChange, currentImageId, onChoose, maxUploadBytes, limitsText, slideNumber }: LibraryPickerDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const library = useMediaPhotos(open);
|
||||
const upload = useUploadHeroImage();
|
||||
const items = (library.data?.photos ?? []).filter((p) => p.module === MODULE).map((p) => toPhotoItem(p, t));
|
||||
|
||||
const uploadHere = async (file: File): Promise<PhotoItem> => {
|
||||
const image = await upload.mutateAsync(file);
|
||||
onChoose(image.id, image);
|
||||
return { id: `${MODULE}:${image.id}`, name: file.name, bytes: file.size, createdAt: new Date().toISOString(), uses: [], thumbnailUrl: null };
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto" data-testid="library-picker">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('hero.library.title', { n: slideNumber })}</DialogTitle>
|
||||
<DialogDescription>{t('hero.library.description')}</DialogDescription>
|
||||
</DialogHeader>
|
||||
{library.isError && (
|
||||
<p role="alert" className="text-sm text-destructive">
|
||||
{t('media.error')}
|
||||
</p>
|
||||
)}
|
||||
{library.isPending ? (
|
||||
<p className="text-sm text-muted-foreground">{t('media.loading')}</p>
|
||||
) : (
|
||||
<ImagePicker
|
||||
items={items}
|
||||
value={currentImageId ? `${MODULE}:${currentImageId}` : null}
|
||||
onChange={(id) => onChoose(id.slice(MODULE.length + 1))}
|
||||
onUpload={uploadHere}
|
||||
maxUploadBytes={maxUploadBytes}
|
||||
limitsText={limitsText}
|
||||
label={t('hero.library.group', { n: slideNumber })}
|
||||
/>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user