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:
@@ -71,3 +71,4 @@ Kept while Bryan is away (2026-11-17): no questions to him, a most probable assu
|
|||||||
| 40 | **Switching the copy on at the test hosts without access to the Pi** (Bryan, 2026-11-17: the copy may run on test). | The deploy workflow has a new input `media_library_copy` (unchanged, on, off; dispatch input of the CI workflow, passed to the SLS test and ASF test deploys). A step edits ONLY the key `Media__Library__CopyOnStartup` in `<deploy_path>/shared/env` over the deploy account's SSH access (refuses any environment that is not `test`, accepts only on, off or unchanged, never prints the file), before the service restart; after the restart a step shows the journal line `Media library copy verified: N photos and M uses`. `off` removes the key again. | Set the variable by hand in `shared/env` on the Pi (needs a shell there). | `.gitea/workflows/deploy-scp.yaml`, `continuous_integration.yaml` |
|
| 40 | **Switching the copy on at the test hosts without access to the Pi** (Bryan, 2026-11-17: the copy may run on test). | The deploy workflow has a new input `media_library_copy` (unchanged, on, off; dispatch input of the CI workflow, passed to the SLS test and ASF test deploys). A step edits ONLY the key `Media__Library__CopyOnStartup` in `<deploy_path>/shared/env` over the deploy account's SSH access (refuses any environment that is not `test`, accepts only on, off or unchanged, never prints the file), before the service restart; after the restart a step shows the journal line `Media library copy verified: N photos and M uses`. `off` removes the key again. | Set the variable by hand in `shared/env` on the Pi (needs a shell there). | `.gitea/workflows/deploy-scp.yaml`, `continuous_integration.yaml` |
|
||||||
| 41 | **The picker has a single and a multiple mode** (Bryan, 2026-11-17). | `ImagePicker` takes `mode="single"` (default, radio group, used by the hero slides) or `mode="multiple"` (checkboxes, several photos, several files per upload, ready for the gallery). Both use the same upload checks. | n/a | `ImagePicker.tsx` |
|
| 41 | **The picker has a single and a multiple mode** (Bryan, 2026-11-17). | `ImagePicker` takes `mode="single"` (default, radio group, used by the hero slides) or `mode="multiple"` (checkboxes, several photos, several files per upload, ready for the gallery). Both use the same upload checks. | n/a | `ImagePicker.tsx` |
|
||||||
| 42 | **One progress pattern for upload, processing and a new crop** (Bryan, 2026-11-17, after seeing it on test). | A shared `ProcessingProgress` (text "Wordt verwerkt…", one 0-100% bar, the percentage, no spinner, no step counts) is used on every photo and for the batch. The batch bar covers upload and processing together; there are no byte counts from the upload, so a photo's percentage is staged: waiting 0, uploading 15, uploaded 30, then 30-100 from the server's processing steps. A new crop uses the full 0-100 from its steps. The counter "x van y verwerkt" stays per batch. | Real upload byte progress (needs XHR progress in the API client). | `features/media/components/ProcessingProgress.tsx`, `lib/photoProgress.ts`, `hero/components/ProcessingStatus.tsx` |
|
| 42 | **One progress pattern for upload, processing and a new crop** (Bryan, 2026-11-17, after seeing it on test). | A shared `ProcessingProgress` (text "Wordt verwerkt…", one 0-100% bar, the percentage, no spinner, no step counts) is used on every photo and for the batch. The batch bar covers upload and processing together; there are no byte counts from the upload, so a photo's percentage is staged: waiting 0, uploading 15, uploaded 30, then 30-100 from the server's processing steps. A new crop uses the full 0-100 from its steps. The counter "x van y verwerkt" stays per batch. | Real upload byte progress (needs XHR progress in the API client). | `features/media/components/ProcessingProgress.tsx`, `lib/photoProgress.ts`, `hero/components/ProcessingStatus.tsx` |
|
||||||
|
| 43 | **"Slide toevoegen" replaces the per-slide library button** (Bryan, 2026-11-17, after seeing it on test; replaces assumption 36's per-slide button). | The per-slide "Kies uit bibliotheek" is gone. The existing add button is "Slide toevoegen" and opens the shared picker: choose a library photo or upload one on the spot (it also lands in the library, ML-17); one photo makes one NEW slide. A slide's photo cannot be changed or replaced: remove the slide and add another. Dropping files on the section still adds one slide per file (same upload as before). The crop per slide stays a goal (phase 2). | Keep a per-slide change button: Bryan said no. | `HeroPage.addSlideWithPhoto`, `LibraryPickerDialog` |
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { useRef } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { ImagePicker } from '@/features/media/components/ImagePicker';
|
import { ImagePicker } from '@/features/media/components/ImagePicker';
|
||||||
@@ -10,32 +11,31 @@ import type { HeroImageDto } from '../services/types';
|
|||||||
interface LibraryPickerDialogProps {
|
interface LibraryPickerDialogProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onOpenChange: (open: boolean) => void;
|
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. */
|
/** 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;
|
onChoose: (imageId: string, uploaded?: HeroImageDto) => void;
|
||||||
maxUploadBytes: number;
|
maxUploadBytes: number;
|
||||||
limitsText?: string;
|
limitsText?: string;
|
||||||
slideNumber: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MODULE = 'hero';
|
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
|
* 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:
|
* (same checks and limits, variants cut in the background; it also lands in the library). One photo makes one new slide. A photo
|
||||||
* it is the same photo, so its crop is shared (assumption 36).
|
* 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 { t } = useTranslation();
|
||||||
const library = useMediaPhotos(open);
|
const library = useMediaPhotos(open);
|
||||||
const upload = useUploadHeroImage();
|
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 items = (library.data?.photos ?? []).filter((p) => p.module === MODULE).map((p) => toPhotoItem(p, t));
|
||||||
|
|
||||||
const uploadHere = async (file: File): Promise<PhotoItem> => {
|
const uploadHere = async (file: File): Promise<PhotoItem> => {
|
||||||
const image = await upload.mutateAsync(file);
|
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 };
|
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}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto" data-testid="library-picker">
|
<DialogContent className="max-h-[90vh] max-w-3xl overflow-y-auto" data-testid="library-picker">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{t('hero.library.title', { n: slideNumber })}</DialogTitle>
|
<DialogTitle>{t('hero.library.title')}</DialogTitle>
|
||||||
<DialogDescription>{t('hero.library.description')}</DialogDescription>
|
<DialogDescription>{t('hero.library.description')}</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
{library.isError && (
|
{library.isError && (
|
||||||
@@ -56,12 +56,15 @@ export function LibraryPickerDialog({ open, onOpenChange, currentImageId, onChoo
|
|||||||
) : (
|
) : (
|
||||||
<ImagePicker
|
<ImagePicker
|
||||||
items={items}
|
items={items}
|
||||||
value={currentImageId ? `${MODULE}:${currentImageId}` : null}
|
value={null}
|
||||||
onChange={(id) => onChoose(id.slice(MODULE.length + 1))}
|
onChange={(id) => {
|
||||||
|
const imageId = id.slice(MODULE.length + 1);
|
||||||
|
onChoose(imageId, uploaded.current.get(imageId));
|
||||||
|
}}
|
||||||
onUpload={uploadHere}
|
onUpload={uploadHere}
|
||||||
maxUploadBytes={maxUploadBytes}
|
maxUploadBytes={maxUploadBytes}
|
||||||
limitsText={limitsText}
|
limitsText={limitsText}
|
||||||
label={t('hero.library.group', { n: slideNumber })}
|
label={t('hero.library.group')}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
@@ -1230,7 +1230,7 @@ describe('Tabs Content and Images', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('Choose a photo from the library for a slide', () => {
|
describe('Add a slide with a photo from the library or an upload', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
resetMockHero();
|
resetMockHero();
|
||||||
});
|
});
|
||||||
@@ -1250,7 +1250,7 @@ describe('Choose a photo from the library for a slide', () => {
|
|||||||
...over,
|
...over,
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lists the library photos (also those in no slide, never the trash) and puts the chosen one in the slide, ready to save', async () => {
|
it('lists the library photos (also those in no slide, never the trash) and adds the chosen one as a new slide, ready to save', async () => {
|
||||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
||||||
server.use(
|
server.use(
|
||||||
http.get('*/media-library/photos', () =>
|
http.get('*/media-library/photos', () =>
|
||||||
@@ -1259,38 +1259,41 @@ describe('Choose a photo from the library for a slide', () => {
|
|||||||
http.get(`${API_BASE}/api/v1/hero/images/10000000-0000-0000-0000-000000000002`, () => HttpResponse.json(slide(2).image)),
|
http.get(`${API_BASE}/api/v1/hero/images/10000000-0000-0000-0000-000000000002`, () => HttpResponse.json(slide(2).image)),
|
||||||
);
|
);
|
||||||
await openPage();
|
await openPage();
|
||||||
await userEvent.click(screen.getByTestId('hero-slide-0-library'));
|
await userEvent.click(screen.getByTestId('hero-upload-button'));
|
||||||
|
|
||||||
const dialog = await screen.findByTestId('library-picker', {}, T);
|
const dialog = await screen.findByTestId('library-picker', {}, T);
|
||||||
const radios = await within(dialog).findAllByRole('radio');
|
const radios = await within(dialog).findAllByRole('radio');
|
||||||
expect(radios.map((r) => r.getAttribute('aria-label'))).toEqual(['foto-3.jpg', 'foto-2.jpg', 'foto-1.jpg']);
|
expect(radios.map((r) => r.getAttribute('aria-label'))).toEqual(['foto-3.jpg', 'foto-2.jpg', 'foto-1.jpg']);
|
||||||
expect(within(dialog).getByRole('radio', { name: 'foto-1.jpg' })).toBeChecked();
|
expect(within(dialog).queryAllByRole('radio', { checked: true })).toHaveLength(0);
|
||||||
expect(within(dialog).getByTestId('picker-upload-button')).toBeInTheDocument();
|
expect(within(dialog).getByTestId('picker-upload-button')).toBeInTheDocument();
|
||||||
|
|
||||||
await userEvent.click(within(dialog).getByRole('radio', { name: 'foto-2.jpg' }));
|
await userEvent.click(within(dialog).getByRole('radio', { name: 'foto-2.jpg' }));
|
||||||
|
|
||||||
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
||||||
await waitFor(() => expect(screen.getByTestId('hero-save')).toBeEnabled());
|
await waitFor(() => expect(screen.getByTestId('hero-save')).toBeEnabled());
|
||||||
|
await userEvent.type(screen.getByTestId('hero-slide-1-alt'), 'Beschrijving');
|
||||||
await userEvent.click(screen.getByTestId('hero-save'));
|
await userEvent.click(screen.getByTestId('hero-save'));
|
||||||
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
||||||
expect(getSavedHeroRequests()[0].slides[0].imageId).toBe('10000000-0000-0000-0000-000000000002');
|
expect(getSavedHeroRequests()[0].slides.map((x) => x.imageId)).toEqual(['10000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000002']);
|
||||||
|
expect(screen.queryByTestId('hero-slide-0-library')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('lets a photo that is already in another slide be chosen again (same photo, separate slide)', async () => {
|
it('lets a photo that is already in another slide be chosen again as a new slide (same photo, separate slide)', async () => {
|
||||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1), slide(2)] });
|
||||||
server.use(
|
server.use(
|
||||||
http.get('*/media-library/photos', () => HttpResponse.json({ photos: [libraryPhoto(2, { uses: [{ module: 'hero', kind: 'slide', position: 2, active: true }] }), libraryPhoto(1)], modules: ['hero'] })),
|
http.get('*/media-library/photos', () => HttpResponse.json({ photos: [libraryPhoto(2, { uses: [{ module: 'hero', kind: 'slide', position: 2, active: true }] }), libraryPhoto(1)], modules: ['hero'] })),
|
||||||
);
|
);
|
||||||
await openPage();
|
await openPage();
|
||||||
await userEvent.click(screen.getByTestId('hero-slide-0-library'));
|
await userEvent.click(screen.getByTestId('hero-upload-button'));
|
||||||
const dialog = await screen.findByTestId('library-picker', {}, T);
|
const dialog = await screen.findByTestId('library-picker', {}, T);
|
||||||
|
|
||||||
await userEvent.click(await within(dialog).findByRole('radio', { name: 'foto-2.jpg' }));
|
await userEvent.click(await within(dialog).findByRole('radio', { name: 'foto-2.jpg' }));
|
||||||
|
|
||||||
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
||||||
|
await userEvent.type(screen.getByTestId('hero-slide-2-alt'), 'Beschrijving');
|
||||||
await userEvent.click(screen.getByTestId('hero-save'));
|
await userEvent.click(screen.getByTestId('hero-save'));
|
||||||
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
||||||
expect(getSavedHeroRequests()[0].slides.map((x) => x.imageId)).toEqual(['10000000-0000-0000-0000-000000000002', '10000000-0000-0000-0000-000000000002']);
|
expect(getSavedHeroRequests()[0].slides.map((x) => x.imageId)).toEqual(['10000000-0000-0000-0000-000000000001', '10000000-0000-0000-0000-000000000002', '10000000-0000-0000-0000-000000000002']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('tells that the crop is shared when the same photo is in more than one slide', async () => {
|
it('tells that the crop is shared when the same photo is in more than one slide', async () => {
|
||||||
@@ -1308,7 +1311,7 @@ describe('Choose a photo from the library for a slide', () => {
|
|||||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [slide(1)] });
|
||||||
server.use(http.get('*/media-library/photos', () => HttpResponse.json({ photos: [], modules: ['hero'] })));
|
server.use(http.get('*/media-library/photos', () => HttpResponse.json({ photos: [], modules: ['hero'] })));
|
||||||
await openPage();
|
await openPage();
|
||||||
await userEvent.click(screen.getByTestId('hero-slide-0-library'));
|
await userEvent.click(screen.getByTestId('hero-upload-button'));
|
||||||
const dialog = await screen.findByTestId('library-picker', {}, T);
|
const dialog = await screen.findByTestId('library-picker', {}, T);
|
||||||
expect(await within(dialog).findByTestId('picker-empty')).toBeInTheDocument();
|
expect(await within(dialog).findByTestId('picker-empty')).toBeInTheDocument();
|
||||||
|
|
||||||
@@ -1316,8 +1319,10 @@ describe('Choose a photo from the library for a slide', () => {
|
|||||||
|
|
||||||
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
await waitFor(() => expect(screen.queryByTestId('library-picker')).not.toBeInTheDocument());
|
||||||
await waitFor(() => expect(screen.getByTestId('hero-save')).toBeEnabled());
|
await waitFor(() => expect(screen.getByTestId('hero-save')).toBeEnabled());
|
||||||
|
await userEvent.type(screen.getByTestId('hero-slide-1-alt'), 'Beschrijving');
|
||||||
await userEvent.click(screen.getByTestId('hero-save'));
|
await userEvent.click(screen.getByTestId('hero-save'));
|
||||||
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
await waitFor(() => expect(getSavedHeroRequests()).toHaveLength(1));
|
||||||
expect(getSavedHeroRequests()[0].slides[0].imageId).not.toBe('10000000-0000-0000-0000-000000000001');
|
expect(getSavedHeroRequests()[0].slides).toHaveLength(2);
|
||||||
|
expect(getSavedHeroRequests()[0].slides[1].imageId).not.toBe('10000000-0000-0000-0000-000000000001');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -155,7 +155,7 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
|||||||
const [batch, setBatch] = useState<string[]>([]);
|
const [batch, setBatch] = useState<string[]>([]);
|
||||||
const [recutIds, setRecutIds] = useState<string[]>([]);
|
const [recutIds, setRecutIds] = useState<string[]>([]);
|
||||||
// The slide (by position) whose photo is being chosen from the library.
|
// The slide (by position) whose photo is being chosen from the library.
|
||||||
const [libraryFor, setLibraryFor] = useState<number | null>(null);
|
const [adding, setAdding] = useState(false);
|
||||||
const fileInput = useRef<HTMLInputElement>(null);
|
const fileInput = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -271,18 +271,16 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
|||||||
return () => window.removeEventListener('beforeunload', warn);
|
return () => window.removeEventListener('beforeunload', warn);
|
||||||
}, [hasUnsaved]);
|
}, [hasUnsaved]);
|
||||||
|
|
||||||
// A photo chosen from the library (or uploaded in the picker) becomes the photo of that slide: only the image id of the
|
// "Add slide": a photo chosen from the library, or uploaded in the picker (it then also lands in the library), becomes a NEW
|
||||||
// slide changes (no new data model). The photo is the same photo wherever it is used, so its crop is shared.
|
// slide with exactly that one photo. A slide's photo is never changed afterwards: remove the slide and add another.
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const chooseForSlide = async (index: number, imageId: string, uploaded?: HeroImageDto) => {
|
const addSlideWithPhoto = async (imageId: string, uploaded?: HeroImageDto) => {
|
||||||
const current = watchedSlides[index];
|
|
||||||
if (!current) return;
|
|
||||||
try {
|
try {
|
||||||
const image: HeroImageDto = uploaded ?? ((await queryClient.fetchQuery(heroImageQuery(imageId))) as HeroImageDto);
|
const image: HeroImageDto = uploaded ?? ((await queryClient.fetchQuery(heroImageQuery(imageId))) as HeroImageDto);
|
||||||
setLocalImages((cur) => ({ ...cur, [image.id]: image }));
|
setLocalImages((cur) => ({ ...cur, [image.id]: image }));
|
||||||
if (uploaded && image.processing) setBatch((cur) => (cur.some((id) => images[id]?.processing) ? [...cur, image.id] : [image.id]));
|
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 });
|
slides.append({ id: null, imageId: image.id, alt: '', decorative: false, isActive: true }, { shouldFocus: false });
|
||||||
setLibraryFor(null);
|
setAdding(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setServerError(serverMessage(error, t('errors.generic'), t('errors.network')));
|
setServerError(serverMessage(error, t('errors.generic'), t('errors.network')));
|
||||||
}
|
}
|
||||||
@@ -530,7 +528,7 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
|||||||
data-testid="hero-upload"
|
data-testid="hero-upload"
|
||||||
onChange={(event) => void onFiles(event.target.files)}
|
onChange={(event) => void onFiles(event.target.files)}
|
||||||
/>
|
/>
|
||||||
<Button type="button" variant="outline" disabled={uploading} onClick={() => fileInput.current?.click()} data-testid="hero-upload-button">
|
<Button type="button" variant="outline" disabled={uploading} onClick={() => setAdding(true)} data-testid="hero-upload-button">
|
||||||
<ImagePlus className="mr-2 size-4" aria-hidden="true" />
|
<ImagePlus className="mr-2 size-4" aria-hidden="true" />
|
||||||
{uploading ? t('hero.slides.uploading') : t('hero.slides.add')}
|
{uploading ? t('hero.slides.uploading') : t('hero.slides.add')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -574,9 +572,6 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
|||||||
<div className="flex h-20 w-28 items-center justify-center rounded bg-muted text-xs">?</div>
|
<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`} />
|
<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>
|
|
||||||
{watchedSlides.some((other, otherIndex) => otherIndex !== index && other?.imageId === field.imageId) && (
|
{watchedSlides.some((other, otherIndex) => otherIndex !== index && other?.imageId === field.imageId) && (
|
||||||
<p className="max-w-28 text-xs text-muted-foreground" data-testid={`hero-slide-${index}-shared-crop`}>
|
<p className="max-w-28 text-xs text-muted-foreground" data-testid={`hero-slide-${index}-shared-crop`}>
|
||||||
{t('hero.library.sharedCrop')}
|
{t('hero.library.sharedCrop')}
|
||||||
@@ -664,13 +659,11 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LibraryPickerDialog
|
<LibraryPickerDialog
|
||||||
open={libraryFor !== null}
|
open={adding}
|
||||||
onOpenChange={(open) => !open && setLibraryFor(null)}
|
onOpenChange={setAdding}
|
||||||
currentImageId={libraryFor !== null ? (watchedSlides[libraryFor]?.imageId ?? null) : null}
|
onChoose={(imageId, uploaded) => void addSlideWithPhoto(imageId, uploaded)}
|
||||||
onChoose={(imageId, uploaded) => libraryFor !== null && void chooseForSlide(libraryFor, imageId, uploaded)}
|
|
||||||
maxUploadBytes={limits?.maxUploadBytes ?? MAX_UPLOAD_BYTES}
|
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}
|
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
|
<FocusDialog
|
||||||
image={focusImageId ? images[focusImageId] ?? null : null}
|
image={focusImageId ? images[focusImageId] ?? null : null}
|
||||||
|
|||||||
@@ -643,15 +643,14 @@
|
|||||||
"target": "Button {{n}}: target"
|
"target": "Button {{n}}: target"
|
||||||
},
|
},
|
||||||
"library": {
|
"library": {
|
||||||
"choose": "Choose from library",
|
"title": "Add slide",
|
||||||
"title": "Image for slide {{n}}",
|
"description": "Choose a photo from the media library or upload a new one; it then lands in the library too. Every slide has one photo. A slide's photo is not changed: remove the slide and add a new one.",
|
||||||
"description": "Choose a photo from the media library or upload a new one. A photo that is already in another slide is fine too: it is the same photo, so its crop is shared.",
|
"group": "Photo for the new slide",
|
||||||
"group": "Image of slide {{n}}",
|
|
||||||
"sharedCrop": "This photo is in more slides; the crop applies to all of them."
|
"sharedCrop": "This photo is in more slides; the crop applies to all of them."
|
||||||
},
|
},
|
||||||
"slides": {
|
"slides": {
|
||||||
"title": "Images",
|
"title": "Images",
|
||||||
"add": "Add image",
|
"add": "Add slide",
|
||||||
"uploading": "Uploading…",
|
"uploading": "Uploading…",
|
||||||
"hint": "Choose several files at once or drag them into this box. New photos are added at the bottom of the list. Drag a photo by its handle, or use the arrows, to change the order; visitors see the first photo first. With the Focus button you show where the subject is.",
|
"hint": "Choose several files at once or drag them into this box. New photos are added at the bottom of the list. Drag a photo by its handle, or use the arrows, to change the order; visitors see the first photo first. With the Focus button you show where the subject is.",
|
||||||
"empty": "No images yet.",
|
"empty": "No images yet.",
|
||||||
|
|||||||
@@ -643,15 +643,14 @@
|
|||||||
"target": "Knop {{n}}: doel"
|
"target": "Knop {{n}}: doel"
|
||||||
},
|
},
|
||||||
"library": {
|
"library": {
|
||||||
"choose": "Kies uit bibliotheek",
|
"title": "Slide toevoegen",
|
||||||
"title": "Afbeelding voor slide {{n}}",
|
"description": "Kies een foto uit de mediabibliotheek of upload een nieuwe foto; die komt dan ook in de bibliotheek. Elke slide heeft één foto. Een foto wijzig je niet op een slide: verwijder de slide en voeg een nieuwe toe.",
|
||||||
"description": "Kies een foto uit de mediabibliotheek of upload een nieuwe foto. Een foto die al in een andere slide staat mag ook: het is dezelfde foto, dus de uitsnede is gedeeld.",
|
"group": "Foto voor de nieuwe slide",
|
||||||
"group": "Afbeelding van slide {{n}}",
|
|
||||||
"sharedCrop": "Deze foto staat in meer slides; de uitsnede geldt voor allemaal."
|
"sharedCrop": "Deze foto staat in meer slides; de uitsnede geldt voor allemaal."
|
||||||
},
|
},
|
||||||
"slides": {
|
"slides": {
|
||||||
"title": "Afbeeldingen",
|
"title": "Afbeeldingen",
|
||||||
"add": "Afbeelding toevoegen",
|
"add": "Slide toevoegen",
|
||||||
"uploading": "Bezig met uploaden…",
|
"uploading": "Bezig met uploaden…",
|
||||||
"hint": "Kies meerdere bestanden tegelijk of sleep ze naar dit vak. Nieuwe foto’s komen onderaan de lijst. Sleep een foto aan het greepje, of gebruik de pijltjes, om de volgorde te wijzigen; de eerste foto zien bezoekers als eerste. Met de knop Focus geef je aan waar het onderwerp staat.",
|
"hint": "Kies meerdere bestanden tegelijk of sleep ze naar dit vak. Nieuwe foto’s komen onderaan de lijst. Sleep een foto aan het greepje, of gebruik de pijltjes, om de volgorde te wijzigen; de eerste foto zien bezoekers als eerste. Met de knop Focus geef je aan waar het onderwerp staat.",
|
||||||
"empty": "Nog geen afbeeldingen.",
|
"empty": "Nog geen afbeeldingen.",
|
||||||
|
|||||||
Reference in New Issue
Block a user