Hero-admin: meerdere foto's tegelijk, slepen, niet-opgeslagen waarschuwing, begrijpelijke teksten, rustige wachtanimatie
- Meerdere bestanden kiezen of slepen (2 tegelijk, per bestand voortgang en reden bij falen, volgorde van kiezen), uploadlimiet standaard 100 per uur - Volgorde ook met slepen (greepje, toetsenbord), pijltjes blijven - Waarschuwing bij niet-opgeslagen wijzigingen (badge, beforeunload, bevestiging bij navigeren, vergelijking met laatst opgeslagen stand) - Teksten zonder vakjargon, uitleg per onderdeel, formaten en limieten van de host (GET /hero/images/limits) - Shimmer (CSS, reduced-motion) op foto's die nog verwerkt worden Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -66,3 +66,24 @@ export function ProcessingStatus({ hero }: { hero: HeroAdminDto }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The place of a photo that has no pictures yet: one calm shimmer (hidden from assistive technology) and a readable
|
||||
* text. It lives in the row of the slide, so it stays mounted (and the animation keeps running) while the page asks the
|
||||
* server again every few seconds, and it disappears when the photo is ready.
|
||||
*/
|
||||
export function PhotoPlaceholder({ failed, testId }: { failed: boolean; testId: string }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div
|
||||
className={`flex h-20 w-28 flex-col items-center justify-center gap-1 rounded p-1 text-center text-xs ${failed ? 'bg-destructive/10 text-destructive' : 'hero-shimmer bg-muted'}`}
|
||||
role="status"
|
||||
aria-busy={!failed}
|
||||
title={t('hero.slides.processingHint')}
|
||||
data-testid={testId}
|
||||
>
|
||||
{failed ? null : <Spinner className="size-3.5" />}
|
||||
<span>{failed ? t('hero.slides.failed') : t('hero.slides.processing')}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { useSortable } from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { GripVertical } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface SortableSlideProps {
|
||||
/** The id of the form field of this slide (stable while the order changes). */
|
||||
id: string;
|
||||
index: number;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* One row of the image list that can be dragged by its handle (mouse, touch or keyboard: focus the handle, press Space,
|
||||
* use the arrow keys, press Space again). The arrow buttons of the row stay as another way to change the order. While
|
||||
* dragging, the row gets a frame and a shadow and the other rows make room, so it is clear where it will land.
|
||||
*/
|
||||
export function SortableSlide({ id, index, children }: SortableSlideProps) {
|
||||
const { t } = useTranslation();
|
||||
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id });
|
||||
|
||||
return (
|
||||
<li
|
||||
ref={setNodeRef}
|
||||
style={{ transform: CSS.Transform.toString(transform), transition, position: 'relative', zIndex: isDragging ? 10 : undefined }}
|
||||
className={`flex flex-wrap items-start gap-3 rounded-md border bg-background p-3 ${isDragging ? 'shadow-lg ring-2 ring-primary' : ''}`}
|
||||
data-testid={`hero-slide-${index}`}
|
||||
data-dragging={isDragging ? 'true' : undefined}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
ref={setActivatorNodeRef}
|
||||
className="mt-1 cursor-grab touch-none rounded p-1 text-muted-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring active:cursor-grabbing"
|
||||
aria-label={t('hero.slides.drag', { n: index + 1 })}
|
||||
data-testid={`hero-slide-${index}-drag`}
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
>
|
||||
<GripVertical className="size-5" aria-hidden="true" />
|
||||
</button>
|
||||
{children}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useBlocker } from '@tanstack/react-router';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
|
||||
|
||||
/**
|
||||
* Asks for confirmation before the administrator leaves the page through the menu or a link while the form holds changes
|
||||
* that are not saved. (Closing the tab or reloading is covered by the browser warning in the page itself.)
|
||||
*/
|
||||
export function UnsavedChangesGuard({ dirty }: { dirty: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
const blocker = useBlocker({
|
||||
shouldBlockFn: () => dirty,
|
||||
disabled: !dirty,
|
||||
enableBeforeUnload: false,
|
||||
withResolver: true,
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog open={blocker.status === 'blocked'} onOpenChange={(open) => { if (!open) blocker.reset?.(); }}>
|
||||
<DialogContent data-testid="hero-leave-dialog">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{t('hero.unsaved.leaveTitle')}</DialogTitle>
|
||||
<DialogDescription>{t('hero.unsaved.leaveText')}</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button type="button" onClick={() => blocker.reset?.()} data-testid="hero-leave-stay">
|
||||
{t('hero.unsaved.stay')}
|
||||
</Button>
|
||||
<Button type="button" variant="outline" onClick={() => blocker.proceed?.()} data-testid="hero-leave-discard">
|
||||
{t('hero.unsaved.discard')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { AlertCircle, Check, Clock } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Spinner } from './ProcessingStatus';
|
||||
|
||||
export interface UploadItem {
|
||||
key: number;
|
||||
name: string;
|
||||
status: 'waiting' | 'uploading' | 'done' | 'failed';
|
||||
/** Why it failed, in words for the administrator. */
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/** The files of the last choice, one row each: waiting, busy (spinner), added, or failed with the reason. */
|
||||
export function UploadProgress({ items, busy, onClose }: { items: UploadItem[]; busy: boolean; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
if (items.length === 0) return null;
|
||||
const finished = items.filter((i) => i.status === 'done' || i.status === 'failed').length;
|
||||
const added = items.filter((i) => i.status === 'done').length;
|
||||
|
||||
return (
|
||||
<div className="space-y-2 rounded-md border p-3" data-testid="hero-upload-list" aria-busy={busy}>
|
||||
<p className="text-sm font-medium" role="status" data-testid="hero-upload-summary">
|
||||
{busy ? t('hero.upload.progress', { done: finished, total: items.length }) : t('hero.upload.summary', { ok: added, total: items.length })}
|
||||
</p>
|
||||
<ul className="space-y-1 text-sm">
|
||||
{items.map((item) => (
|
||||
<li key={item.key} className="flex items-start gap-2" data-testid={`hero-upload-item-${item.key}`} data-status={item.status}>
|
||||
<span className="mt-0.5 shrink-0">
|
||||
{item.status === 'uploading' && <Spinner />}
|
||||
{item.status === 'waiting' && <Clock className="size-4 text-muted-foreground" aria-hidden="true" />}
|
||||
{item.status === 'done' && <Check className="size-4 text-green-600" aria-hidden="true" />}
|
||||
{item.status === 'failed' && <AlertCircle className="size-4 text-destructive" aria-hidden="true" />}
|
||||
</span>
|
||||
<span className="min-w-0 flex-1 break-words">
|
||||
<span className="font-medium">{item.name}</span>
|
||||
{' – '}
|
||||
{item.status === 'failed' ? (
|
||||
<span className="text-destructive" role="alert" data-testid="hero-upload-error">{item.message}</span>
|
||||
) : (
|
||||
<span className="text-muted-foreground">{t(`hero.upload.${item.status}`)}</span>
|
||||
)}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{!busy && (
|
||||
<Button type="button" variant="outline" size="sm" onClick={onClose} data-testid="hero-upload-close">
|
||||
{t('hero.upload.close')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user