Hero: varianten op de achtergrond knippen; upload en opslaan antwoorden direct
Opslaan van 8 foto's met gewijzigde focus duurde 40 s op een snelle pc en ruim 3 minuten op de Pi (proxy-timeout 60 s gaf 504, hero niet bewaard). Upload bewaart het origineel en antwoordt; HeroRenderService knipt de set per afbeelding en schakelt over zodra de set compleet is (oude set blijft ondertussen live; afbeelding zonder set wordt niet gepubliceerd). Opslaan legt alleen de focus vast. Admin toont 'wordt verwerkt' en ververst zelf; Seed-Hero wacht tot alles klaar is. Metingen: HeroSaveTimingTests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,7 @@ const seedImage = (id: string, width = 1600, height = 1067): HeroImageDto => ({
|
||||
{ ratio: 'wide', width, height, type: 'image/webp', url: `/media/hero/0123456789abcdef/wide-${width}.webp` },
|
||||
{ ratio: 'tall', width: 640, height: 800, type: 'image/webp', url: '/media/hero/0123456789abcdef/tall-640.webp' },
|
||||
],
|
||||
processing: false,
|
||||
});
|
||||
|
||||
export const emptyHero = (): HeroAdminDto => ({
|
||||
|
||||
@@ -31,6 +31,16 @@ describe('Hero page', () => {
|
||||
expect(screen.getByTestId('hero-display-single')).toBeChecked();
|
||||
});
|
||||
|
||||
it('shows a placeholder, and no focus button, for an image whose variants are still being cut', async () => {
|
||||
const waiting = slide(1);
|
||||
setMockHero({ ...emptyHero(), id: 'h1', title: 'T', slides: [{ ...waiting, image: { ...waiting.image, variants: [], src: '', processing: true } }] });
|
||||
|
||||
await openPage();
|
||||
|
||||
expect(await screen.findByTestId('hero-slide-0-processing', {}, T)).toBeInTheDocument();
|
||||
expect(screen.getByTestId('hero-slide-0-focus')).toBeDisabled();
|
||||
});
|
||||
|
||||
it('is reachable from the navigation for an administrator', async () => {
|
||||
mockAuthenticated();
|
||||
renderApp('/dashboard');
|
||||
|
||||
@@ -299,7 +299,11 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
||||
const decorative = watchedSlides[index]?.decorative ?? false;
|
||||
return (
|
||||
<li key={field.id} className="flex flex-wrap items-start gap-3 rounded-md border p-3" data-testid={`hero-slide-${index}`}>
|
||||
{image ? (
|
||||
{image && image.variants.length === 0 ? (
|
||||
<div className="flex h-20 w-28 items-center justify-center rounded bg-muted p-1 text-center text-xs" title={t('hero.slides.processingHint')} data-testid={`hero-slide-${index}-processing`}>
|
||||
{t('hero.slides.processing')}
|
||||
</div>
|
||||
) : image ? (
|
||||
<img src={thumbnail(image)} alt="" className="h-20 w-28 rounded object-cover" />
|
||||
) : (
|
||||
<div className="flex h-20 w-28 items-center justify-center rounded bg-muted text-xs">?</div>
|
||||
@@ -329,7 +333,7 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
|
||||
<Button type="button" variant="outline" size="icon" aria-label={t('hero.slides.down')} disabled={index === slides.fields.length - 1} onClick={() => slides.move(index, index + 1)} data-testid={`hero-slide-${index}-down`}>
|
||||
<ArrowDown className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button type="button" variant={focusEdits[field.imageId] ? 'default' : 'outline'} size="icon" aria-label={t('hero.slides.focus')} disabled={!image} onClick={() => setFocusImageId(field.imageId)} data-testid={`hero-slide-${index}-focus`}>
|
||||
<Button type="button" variant={focusEdits[field.imageId] ? 'default' : 'outline'} size="icon" aria-label={t('hero.slides.focus')} disabled={!image || image.variants.length === 0} onClick={() => setFocusImageId(field.imageId)} data-testid={`hero-slide-${index}-focus`}>
|
||||
<Crosshair className="size-4" aria-hidden="true" />
|
||||
</Button>
|
||||
<Button type="button" variant="outline" size="icon" aria-label={t('hero.slides.remove')} onClick={() => slides.remove(index)} data-testid={`hero-slide-${index}-remove`}>
|
||||
|
||||
@@ -9,6 +9,8 @@ export function useHero() {
|
||||
return useQuery<HeroAdminDto, Error>({
|
||||
queryKey: HERO_KEY,
|
||||
queryFn: () => api.get<HeroAdminDto>('/api/v1/hero/all'),
|
||||
// Images are cut in the background after an upload or a saved focus change: look again until they are all ready.
|
||||
refetchInterval: (query) => (query.state.data?.slides.some((s) => s.image.processing) ? 5000 : false),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ export interface HeroImageDto {
|
||||
tallFocus: FocusDto | null;
|
||||
src: string;
|
||||
variants: HeroVariantDto[];
|
||||
/** The variants of this image are still being cut in the background; it is not published yet. */
|
||||
processing: boolean;
|
||||
}
|
||||
|
||||
export interface HeroButtonDto {
|
||||
|
||||
Reference in New Issue
Block a user