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:
2026-11-17 17:05:34 +01:00
co-authored by Claude Sonnet 5.5
parent 4436a40ddf
commit e09304c2e9
10 changed files with 498 additions and 3 deletions
+33 -1
View File
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import { useQueries } from '@tanstack/react-query';
import { useQueries, useQueryClient } from '@tanstack/react-query';
import { useFieldArray, useForm, useWatch } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { useTranslation } from 'react-i18next';
@@ -17,6 +17,7 @@ import { FieldError } from '@/components/ui/FieldError';
import { FormErrorBanner } from '@/components/ui/FormErrorBanner';
import { NetworkError, ProblemDetailsError } from '@/lib/api-client';
import { FocusDialog } from '../components/FocusDialog';
import { LibraryPickerDialog } from '../components/LibraryPickerDialog';
import { CropThumbnail } from '../components/CropThumbnail';
import { DoneStatus, PhotoPlaceholder, ProcessingStatus, RecutThumbnail, Spinner } from '../components/ProcessingStatus';
import { SlideSwitch } from '../components/SlideSwitch';
@@ -153,6 +154,8 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
// every photo of the hero. A new batch starts when the previous one is finished.
const [batch, setBatch] = useState<string[]>([]);
const [recutIds, setRecutIds] = useState<string[]>([]);
// The slide (by position) whose photo is being chosen from the library.
const [libraryFor, setLibraryFor] = useState<number | null>(null);
const fileInput = useRef<HTMLInputElement>(null);
const {
@@ -268,6 +271,23 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
return () => window.removeEventListener('beforeunload', warn);
}, [hasUnsaved]);
// A photo chosen from the library (or uploaded in the picker) becomes the photo of that slide: only the image id of the
// slide changes (no new data model). The photo is the same photo wherever it is used, so its crop is shared.
const queryClient = useQueryClient();
const chooseForSlide = async (index: number, imageId: string, uploaded?: HeroImageDto) => {
const current = watchedSlides[index];
if (!current) return;
try {
const image: HeroImageDto = uploaded ?? ((await queryClient.fetchQuery(heroImageQuery(imageId))) as HeroImageDto);
setLocalImages((cur) => ({ ...cur, [image.id]: image }));
if (uploaded && image.processing) setBatch((cur) => (cur.some((id) => images[id]?.processing) ? [...cur, image.id] : [image.id]));
if (image.id !== current.imageId) slides.update(index, { ...current, imageId: image.id });
setLibraryFor(null);
} catch (error) {
setServerError(serverMessage(error, t('errors.generic'), t('errors.network')));
}
};
// A new crop goes to the server at once; the page then shows the photo as processing until the new variants are ready.
const applyFocus = (imageId: string, request: HeroFocusRequest) => {
setServerError(null);
@@ -551,6 +571,9 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
<div className="flex h-20 w-28 items-center justify-center rounded bg-muted text-xs">?</div>
)}
<DoneStatus done={Boolean(image && justDone[image.id] && !image.processing)} slideNumber={index + 1} testId={`hero-slide-${index}-done`} />
<Button type="button" variant="outline" size="sm" onClick={() => setLibraryFor(index)} data-testid={`hero-slide-${index}-library`}>
{t('hero.library.choose')}
</Button>
</div>
<div className="min-w-[12rem] flex-1 space-y-2" role="group" aria-labelledby={`hero-slide-title-${field.id}`}>
<h3 id={`hero-slide-title-${field.id}`} className="text-xs font-medium uppercase tracking-wide text-muted-foreground" data-testid={`hero-slide-${index}-title`}>
@@ -632,6 +655,15 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
</Button>
</div>
<LibraryPickerDialog
open={libraryFor !== null}
onOpenChange={(open) => !open && setLibraryFor(null)}
currentImageId={libraryFor !== null ? (watchedSlides[libraryFor]?.imageId ?? null) : null}
onChoose={(imageId, uploaded) => libraryFor !== null && void chooseForSlide(libraryFor, imageId, uploaded)}
maxUploadBytes={limits?.maxUploadBytes ?? MAX_UPLOAD_BYTES}
limitsText={limits ? t('hero.slides.limits', { formats: limits.formats.join(', '), size: Math.round(limits.maxUploadBytes / (1024 * 1024)), megapixels: limits.maxMegapixels }) : undefined}
slideNumber={(libraryFor ?? 0) + 1}
/>
<FocusDialog
image={focusImageId ? images[focusImageId] ?? null : null}
onApply={applyFocus}