Hero: Slide toevoegen via de bibliotheek of een upload, geen foto wijzigen per slide
Continuous Integration / config-sls (pull_request) Successful in 9s
Continuous Integration / config-asf (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 15s
Continuous Integration / compile-sites (pull_request) Successful in 1m19s
Continuous Integration / backend-build (pull_request) Successful in 1m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m0s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m25s
Continuous Integration / frontend-build (pull_request) Canceled after 0s
Continuous Integration / frontend-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-production (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-test (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-production (pull_request) Canceled after 0s
Continuous Integration / publish-asf-test (pull_request) Canceled after 0s
Continuous Integration / deploy-asf-test (pull_request) Canceled after 0s
Continuous Integration / smoke-sls-test (pull_request) Canceled after 0s
Continuous Integration / smoke-asf-test (pull_request) Canceled after 0s
Continuous Integration / frontend-lint (pull_request) Canceled after 32s
Continuous Integration / backend-test (pull_request) Canceled after 3m42s
Continuous Integration / config-sls (pull_request) Successful in 9s
Continuous Integration / config-asf (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 15s
Continuous Integration / compile-sites (pull_request) Successful in 1m19s
Continuous Integration / backend-build (pull_request) Successful in 1m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m0s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m25s
Continuous Integration / frontend-build (pull_request) Canceled after 0s
Continuous Integration / frontend-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-production (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-test (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-production (pull_request) Canceled after 0s
Continuous Integration / publish-asf-test (pull_request) Canceled after 0s
Continuous Integration / deploy-asf-test (pull_request) Canceled after 0s
Continuous Integration / smoke-sls-test (pull_request) Canceled after 0s
Continuous Integration / smoke-asf-test (pull_request) Canceled after 0s
Continuous Integration / frontend-lint (pull_request) Canceled after 32s
Continuous Integration / backend-test (pull_request) Canceled after 3m42s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
import { ImagePicker } from '@/features/media/components/ImagePicker';
|
||||
@@ -10,32 +11,31 @@ 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
|
||||
* "Add 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).
|
||||
* (same checks and limits, variants cut in the background; it also lands in the library). One photo makes one new slide. A photo
|
||||
* that is already in another slide can be chosen again (assumption 36).
|
||||
*/
|
||||
export function LibraryPickerDialog({ open, onOpenChange, currentImageId, onChoose, maxUploadBytes, limitsText, slideNumber }: LibraryPickerDialogProps) {
|
||||
export function LibraryPickerDialog({ open, onOpenChange, onChoose, maxUploadBytes, limitsText }: LibraryPickerDialogProps) {
|
||||
const { t } = useTranslation();
|
||||
const library = useMediaPhotos(open);
|
||||
const upload = useUploadHeroImage();
|
||||
// The picker chooses a freshly uploaded photo by itself (onChange); the dialog hands the server's answer along with it.
|
||||
const uploaded = useRef(new Map<string, HeroImageDto>());
|
||||
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);
|
||||
uploaded.current.set(image.id, image);
|
||||
return { id: `${MODULE}:${image.id}`, name: file.name, bytes: file.size, createdAt: new Date().toISOString(), uses: [], thumbnailUrl: null };
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ export function LibraryPickerDialog({ open, onOpenChange, currentImageId, onChoo
|
||||
<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>
|
||||
<DialogTitle>{t('hero.library.title')}</DialogTitle>
|
||||
<DialogDescription>{t('hero.library.description')}</DialogDescription>
|
||||
</DialogHeader>
|
||||
{library.isError && (
|
||||
@@ -56,12 +56,15 @@ export function LibraryPickerDialog({ open, onOpenChange, currentImageId, onChoo
|
||||
) : (
|
||||
<ImagePicker
|
||||
items={items}
|
||||
value={currentImageId ? `${MODULE}:${currentImageId}` : null}
|
||||
onChange={(id) => onChoose(id.slice(MODULE.length + 1))}
|
||||
value={null}
|
||||
onChange={(id) => {
|
||||
const imageId = id.slice(MODULE.length + 1);
|
||||
onChoose(imageId, uploaded.current.get(imageId));
|
||||
}}
|
||||
onUpload={uploadHere}
|
||||
maxUploadBytes={maxUploadBytes}
|
||||
limitsText={limitsText}
|
||||
label={t('hero.library.group', { n: slideNumber })}
|
||||
label={t('hero.library.group')}
|
||||
/>
|
||||
)}
|
||||
</DialogContent>
|
||||
|
||||
Reference in New Issue
Block a user