Mediabibliotheek: een algemene voortgangsbalk voor upload, verwerken en uitsnede
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / config-sls (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 13s
Continuous Integration / frontend-prepare (pull_request) Successful in 27s
Continuous Integration / compile-sites (pull_request) Successful in 2m5s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m12s
Continuous Integration / frontend-build (pull_request) Successful in 38s
Continuous Integration / frontend-lint (pull_request) Successful in 35s
Continuous Integration / frontend-test (pull_request) Successful in 2m47s
Continuous Integration / backend-build (pull_request) Successful in 14m35s
Continuous Integration / backend-test (pull_request) Successful in 3m43s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / config-sls (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 13s
Continuous Integration / frontend-prepare (pull_request) Successful in 27s
Continuous Integration / compile-sites (pull_request) Successful in 2m5s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m12s
Continuous Integration / frontend-build (pull_request) Successful in 38s
Continuous Integration / frontend-lint (pull_request) Successful in 35s
Continuous Integration / frontend-test (pull_request) Successful in 2m47s
Continuous Integration / backend-build (pull_request) Successful in 14m35s
Continuous Integration / backend-test (pull_request) Successful in 3m43s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { Check, Loader2 } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ProcessingProgress } from '@/features/media/components/ProcessingProgress';
|
||||
import { photoProgress, recutProgress, type UploadStage } from '@/features/media/lib/photoProgress';
|
||||
import { useRetryHeroImage } from '../services/hooks';
|
||||
import type { HeroImageDto } from '../services/types';
|
||||
|
||||
@@ -13,46 +15,32 @@ 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({ images }: { images: HeroImageDto[] }) {
|
||||
export function ProcessingStatus({ images, pendingUploads = [] }: { images: HeroImageDto[]; pendingUploads?: UploadStage[] }) {
|
||||
const { t } = useTranslation();
|
||||
const retry = useRetryHeroImage();
|
||||
const total = images.length;
|
||||
const waiting = images.filter((image) => image.processing);
|
||||
if (waiting.length === 0) return null;
|
||||
if (waiting.length === 0 && pendingUploads.length === 0) return null;
|
||||
|
||||
const done = total - waiting.length;
|
||||
// The counter and the one bar cover the current batch: the files that are still being uploaded and the photos that are
|
||||
// being processed. The bar is the overall progress of the whole chain, upload and processing together.
|
||||
const total = images.length + pendingUploads.length;
|
||||
const done = images.length - waiting.length;
|
||||
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 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);
|
||||
const working = waiting.length - failed.length + pendingUploads.length;
|
||||
const percents = [
|
||||
...images.map((image) => photoProgress({ ready: !image.processing, upload: 'done', renderDone: image.renderDone, renderTotal: image.renderTotal })),
|
||||
...pendingUploads.map((stage) => photoProgress({ upload: stage })),
|
||||
];
|
||||
const percent = percents.length === 0 ? 0 : percents.reduce((sum, value) => sum + value, 0) / percents.length;
|
||||
|
||||
return (
|
||||
<div className="space-y-3 rounded-md border bg-muted/40 p-4" data-testid="hero-processing">
|
||||
{working > 0 && (
|
||||
<div className="space-y-2" role="status">
|
||||
<p className="flex items-center gap-2 text-sm font-medium">
|
||||
<Spinner />
|
||||
<span data-testid="hero-processing-count">{t('hero.processing.count', { done, total })}</span>
|
||||
<p className="text-sm font-medium" data-testid="hero-processing-count">
|
||||
{t('hero.processing.count', { done, total })}
|
||||
</p>
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={t('hero.processing.label')}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={total}
|
||||
aria-valuenow={done}
|
||||
aria-valuetext={t('hero.processing.count', { done, total })}
|
||||
className="h-2 w-full overflow-hidden rounded bg-muted"
|
||||
data-testid="hero-processing-bar"
|
||||
>
|
||||
<div className="h-full bg-primary transition-all" style={{ width: `${percent}%` }} />
|
||||
</div>
|
||||
{busy && (
|
||||
<p className="text-sm" data-testid="hero-processing-current">
|
||||
{t('hero.processing.current', { n: done + 1, total, step: busy.renderDone ?? 0, steps: busy.renderTotal })}
|
||||
</p>
|
||||
)}
|
||||
<ProcessingProgress percent={percent} testId="hero-processing-bar" />
|
||||
<p className="text-sm text-muted-foreground">{t('hero.processing.explain')}</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('hero.processing.stuck')}{' '}
|
||||
@@ -97,16 +85,17 @@ export function PhotoPlaceholder({ failed, testId, step }: { failed: boolean; te
|
||||
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'}`}
|
||||
className={`flex h-20 w-28 flex-col items-center justify-center gap-1 rounded p-1.5 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>
|
||||
{!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}
|
||||
{failed ? (
|
||||
<span>{t('hero.slides.failed')}</span>
|
||||
) : (
|
||||
<ProcessingProgress compact className="w-full" testId={`${testId}-progress`} percent={photoProgress({ upload: 'done', renderDone: step?.done, renderTotal: step?.total })} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -118,7 +107,6 @@ export function PhotoPlaceholder({ failed, testId, step }: { failed: boolean; te
|
||||
*/
|
||||
export function RecutThumbnail({ src, failed, testId, step }: { src: string; failed: boolean; testId: string; step?: { done: number; total: number } | null }) {
|
||||
const { t } = useTranslation();
|
||||
const percent = step && step.total > 0 ? Math.min(100, Math.round((step.done / step.total) * 100)) : 0;
|
||||
return (
|
||||
<div className={`relative h-20 w-28 shrink-0 overflow-hidden rounded ${failed ? 'ring-2 ring-destructive' : ''}`} title={t('hero.slides.recutHint')} data-testid={testId}>
|
||||
<img src={src} alt="" className="h-full w-full object-cover" />
|
||||
@@ -127,28 +115,7 @@ export function RecutThumbnail({ src, failed, testId, step }: { src: string; fai
|
||||
role="status"
|
||||
aria-busy={!failed}
|
||||
>
|
||||
{failed ? (
|
||||
<span>{t('hero.slides.failed')}</span>
|
||||
) : (
|
||||
<>
|
||||
<div className="flex items-center justify-between gap-1">
|
||||
<span data-testid={`${testId}-text`}>{t('hero.slides.processing')}</span>
|
||||
<span className="tabular-nums" data-testid={`${testId}-percent`}>{percent}%</span>
|
||||
</div>
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={t('hero.slides.processing')}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={percent}
|
||||
aria-valuetext={`${percent}%`}
|
||||
className="h-1.5 w-full overflow-hidden rounded bg-muted"
|
||||
data-testid={`${testId}-bar`}
|
||||
>
|
||||
<div className="h-full bg-primary transition-all motion-reduce:transition-none" style={{ width: `${percent}%` }} />
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{failed ? <span>{t('hero.slides.failed')}</span> : <ProcessingProgress compact testId={`${testId}-progress`} percent={recutProgress(step?.done, step?.total)} />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { AlertCircle, Check, Clock } from 'lucide-react';
|
||||
import { AlertCircle, Check, Clock, Upload } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Spinner } from './ProcessingStatus';
|
||||
|
||||
export interface UploadItem {
|
||||
key: number;
|
||||
@@ -11,7 +10,7 @@ export interface UploadItem {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
/** The files of the last choice, one row each: waiting, busy (spinner), added, or failed with the reason. */
|
||||
/** The files of the last choice, one row each: waiting, busy, 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;
|
||||
@@ -27,7 +26,7 @@ export function UploadProgress({ items, busy, onClose }: { items: UploadItem[];
|
||||
{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 === 'uploading' && <Upload className="size-4" aria-hidden="true" />}
|
||||
{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" />}
|
||||
|
||||
Reference in New Issue
Block a user