Hero-admin: schakelaar Actief, destructieve knoppen rood, slide-kopjes, juiste voorvertoning in het focusvenster, status per foto
- Schakelaar (role=switch) Actief / Niet actief bij de knoppen, gedimde rij; 'Verberg voor schermlezers'; veld 'Beschrijving' binnen een groep 'Slide N'
- Alle foto's zonder complete set tonen 'Wordt verwerkt' (voortgang bij de foto die bezig is, 'in de wachtrij' bij de rest); totaal bovenaan telt ook nog niet opgeslagen foto's
- Per foto 'Verwerking afgerond' (zelfde weergave voor een hergebruikte foto), foto direct bruikbaar; niet-opgeslagen foto's worden zelf ververst (GET /hero/images/{id}), ook in een achtergrondtab
- Focusvenster toont de hele foto (full-preview in elke set, achtergrond-aanvulling voor oude sets) in plaats van de uitgesneden wide-variant (vervorming)
- Prullenbak en 'Wijzigingen weggooien' in de destructieve stijl
- upload-respons: reused (intern)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,8 @@ const percent = (fraction: number) => Math.round(fraction * 1000) / 10;
|
||||
function FocusEditor({ image, onApply, onClose }: { image: HeroImageDto; onApply: (imageId: string, request: HeroFocusRequest) => void; onClose: () => void }) {
|
||||
const { t } = useTranslation();
|
||||
const area = useRef<HTMLDivElement>(null);
|
||||
// The whole picture: image.src is already a crop of the wide shape and would be shown stretched and out of place.
|
||||
const previewUrl = image.previewSrc ? mediaUrl(image.previewSrc) : null;
|
||||
const [target, setTarget] = useState<Target>('general');
|
||||
const [general, setGeneral] = useState<FocusDto>(image.focus ?? CENTRE);
|
||||
const [wide, setWide] = useState<FocusDto | null>(image.wideFocus);
|
||||
@@ -143,7 +145,13 @@ function FocusEditor({ image, onApply, onClose }: { image: HeroImageDto; onApply
|
||||
onKeyDown={onKeyDown}
|
||||
data-testid="focus-area"
|
||||
>
|
||||
<img src={mediaUrl(image.src)} alt="" draggable={false} className="pointer-events-none absolute inset-0 h-full w-full" />
|
||||
{previewUrl ? (
|
||||
<img src={previewUrl} alt="" draggable={false} className="pointer-events-none absolute inset-0 h-full w-full object-cover" />
|
||||
) : (
|
||||
<p className="absolute inset-0 flex items-center justify-center bg-muted p-4 text-center text-sm text-muted-foreground" role="status" data-testid="focus-preview-pending">
|
||||
{t('hero.focus.previewPending')}
|
||||
</p>
|
||||
)}
|
||||
<div className="pointer-events-none absolute border-2 border-sky-400" style={outline(WIDE, effective.wide)} data-testid="focus-outline-wide" />
|
||||
<div className="pointer-events-none absolute border-2 border-amber-400" style={outline(TALL, effective.tall)} data-testid="focus-outline-tall" />
|
||||
<div
|
||||
@@ -212,8 +220,8 @@ function FocusEditor({ image, onApply, onClose }: { image: HeroImageDto; onApply
|
||||
style={{ aspectRatio: `${ratio.numerator} / ${ratio.denominator}`, maxWidth: ratio.name === 'tall' ? '8rem' : '12rem' }}
|
||||
data-testid={`focus-preview-${ratio.name}`}
|
||||
>
|
||||
<img
|
||||
src={mediaUrl(image.src)}
|
||||
{previewUrl && <img
|
||||
src={previewUrl}
|
||||
alt=""
|
||||
className="absolute max-w-none"
|
||||
style={{
|
||||
@@ -222,7 +230,7 @@ function FocusEditor({ image, onApply, onClose }: { image: HeroImageDto; onApply
|
||||
// top is a percentage of the box height, which is the box width times denominator over numerator.
|
||||
top: `${(-crop.y / crop.width) * (ratio.numerator / ratio.denominator) * 100}%`,
|
||||
}}
|
||||
/>
|
||||
/>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { Check, Loader2 } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useRetryHeroImage } from '../services/hooks';
|
||||
import type { HeroAdminDto } from '../services/types';
|
||||
import type { HeroImageDto } from '../services/types';
|
||||
|
||||
/** A spinner that stands still for people who asked for less motion. */
|
||||
export function Spinner({ className = 'size-4' }: { className?: string }) {
|
||||
@@ -13,19 +13,18 @@ export function Spinner({ className = 'size-4' }: { className?: string }) {
|
||||
* Shown above the form while photos of the saved hero are still being prepared in the background: how many are ready,
|
||||
* what that means for the website, and a way to try again for a photo that failed.
|
||||
*/
|
||||
export function ProcessingStatus({ hero }: { hero: HeroAdminDto }) {
|
||||
export function ProcessingStatus({ images }: { images: HeroImageDto[] }) {
|
||||
const { t } = useTranslation();
|
||||
const retry = useRetryHeroImage();
|
||||
const total = hero.slides.length;
|
||||
const waiting = hero.slides.filter((s) => s.image.processing);
|
||||
const total = images.length;
|
||||
const waiting = images.filter((image) => image.processing);
|
||||
if (waiting.length === 0) return null;
|
||||
|
||||
const done = total - waiting.length;
|
||||
const failed = waiting.filter((s) => s.image.failed);
|
||||
const failed = waiting.filter((image) => image.failed);
|
||||
const working = waiting.length - failed.length;
|
||||
// The photo the server is busy with right now, and how far along it is (a photo that waits has no step yet).
|
||||
const busyIndex = waiting.findIndex((s) => s.image.renderTotal);
|
||||
const busy = busyIndex === -1 ? null : waiting[busyIndex].image;
|
||||
const busy = waiting.find((image) => image.renderTotal) ?? null;
|
||||
const fraction = busy && busy.renderTotal ? (busy.renderDone ?? 0) / busy.renderTotal : 0;
|
||||
const percent = total === 0 ? 0 : Math.min(100, ((done + fraction) / total) * 100);
|
||||
|
||||
@@ -61,7 +60,7 @@ export function ProcessingStatus({ hero }: { hero: HeroAdminDto }) {
|
||||
type="button"
|
||||
className="underline underline-offset-2 hover:text-foreground disabled:opacity-50"
|
||||
disabled={retry.isPending}
|
||||
onClick={() => waiting.forEach((s) => retry.mutate(s.imageId))}
|
||||
onClick={() => waiting.forEach((image) => retry.mutate(image.id))}
|
||||
data-testid="hero-processing-retry-all"
|
||||
>
|
||||
{t('hero.processing.retry')}
|
||||
@@ -78,7 +77,7 @@ export function ProcessingStatus({ hero }: { hero: HeroAdminDto }) {
|
||||
variant="outline"
|
||||
size="sm"
|
||||
disabled={retry.isPending}
|
||||
onClick={() => failed.forEach((s) => retry.mutate(s.imageId))}
|
||||
onClick={() => failed.forEach((image) => retry.mutate(image.id))}
|
||||
data-testid="hero-processing-retry"
|
||||
>
|
||||
{t('hero.processing.retry')}
|
||||
@@ -107,6 +106,7 @@ export function PhotoPlaceholder({ failed, testId, step }: { failed: boolean; te
|
||||
{failed ? null : <Spinner className="size-3.5" />}
|
||||
<span>{failed ? t('hero.slides.failed') : t('hero.slides.processing')}</span>
|
||||
{!failed && step ? <span className="tabular-nums opacity-80" data-testid={`${testId}-step`}>{step.done}/{step.total}</span> : null}
|
||||
{!failed && !step ? <span className="opacity-70" data-testid={`${testId}-queued`}>{t('hero.slides.queued')}</span> : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -134,3 +134,23 @@ export function RecutThumbnail({ src, failed, testId, step }: { src: string; fai
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Per photo: shortly after its processing is done a check mark with "Processing finished" shows on that photo itself and
|
||||
* fades away. The region is always there (empty) so a screen reader announces the text when it appears; the text names
|
||||
* the slide. With reduced motion it does not fade but disappears after the same time.
|
||||
*/
|
||||
export function DoneStatus({ done, slideNumber, testId }: { done: boolean; slideNumber: number; testId: string }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<div role="status" aria-live="polite" className="min-h-4 text-[11px] leading-tight" data-testid={testId}>
|
||||
{done && (
|
||||
<span className="hero-done inline-flex items-center gap-1 font-medium text-green-700 dark:text-green-400" data-testid={`${testId}-text`}>
|
||||
<Check className="size-3.5" aria-hidden="true" />
|
||||
<span className="sr-only">{t('hero.slides.doneFor', { n: slideNumber })}</span>
|
||||
<span aria-hidden="true">{t('hero.slides.done')}</span>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
interface SlideSwitchProps {
|
||||
checked: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
testId: string;
|
||||
/** What a screen reader says besides the visible text, so the switch is clearly about this slide. */
|
||||
slideNumber: number;
|
||||
}
|
||||
|
||||
/** A switch (role="switch") that turns a slide on or off; the text next to it says the current state. */
|
||||
export function SlideSwitch({ checked, onChange, testId, slideNumber }: SlideSwitchProps) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={checked}
|
||||
onClick={() => onChange(!checked)}
|
||||
className="flex items-center gap-2 rounded-md px-1 py-1 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
data-testid={testId}
|
||||
>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={`relative inline-flex h-5 w-9 shrink-0 items-center rounded-full border transition-colors ${checked ? 'border-primary bg-primary' : 'border-input bg-muted'}`}
|
||||
>
|
||||
<span className={`inline-block size-4 rounded-full bg-background shadow transition-transform motion-reduce:transition-none ${checked ? 'translate-x-[1.1rem]' : 'translate-x-0.5'}`} />
|
||||
</span>
|
||||
<span className="min-w-[4.5rem] text-left">{checked ? t('hero.slides.activeOn') : t('hero.slides.activeOff')}</span>
|
||||
<span className="sr-only">{t('hero.slides.activeFor', { n: slideNumber })}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,8 @@ interface SortableSlideProps {
|
||||
/** The id of the form field of this slide (stable while the order changes). */
|
||||
id: string;
|
||||
index: number;
|
||||
/** A slide that is switched off is shown dimmed. */
|
||||
dimmed?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
@@ -16,7 +18,7 @@ interface SortableSlideProps {
|
||||
* 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) {
|
||||
export function SortableSlide({ id, index, dimmed = false, children }: SortableSlideProps) {
|
||||
const { t } = useTranslation();
|
||||
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({ id });
|
||||
|
||||
@@ -24,9 +26,10 @@ export function SortableSlide({ id, index, children }: SortableSlideProps) {
|
||||
<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' : ''}`}
|
||||
className={`flex flex-wrap items-start gap-3 rounded-md border bg-background p-3 ${isDragging ? 'shadow-lg ring-2 ring-primary' : ''} ${dimmed ? 'opacity-60' : ''}`}
|
||||
data-testid={`hero-slide-${index}`}
|
||||
data-dragging={isDragging ? 'true' : undefined}
|
||||
data-inactive={dimmed ? 'true' : undefined}
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -27,7 +27,7 @@ export function UnsavedChangesGuard({ dirty }: { dirty: boolean }) {
|
||||
<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">
|
||||
<Button type="button" variant="destructive" onClick={() => blocker.proceed?.()} data-testid="hero-leave-discard">
|
||||
{t('hero.unsaved.discard')}
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
Reference in New Issue
Block a user