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:
@@ -0,0 +1,34 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
/**
|
||||
* THE progress pattern for everything that takes time in the library (upload, processing, a new crop): the same text
|
||||
* ("Wordt verwerkt…"), one bar from 0 to 100 percent and the percentage. No spinner and no step counts, so it reads the same
|
||||
* everywhere and works without motion. The caller decides what the percentage means (see <c>photoProgress</c>).
|
||||
*/
|
||||
export function ProcessingProgress({ percent, testId, compact = false, className }: { percent: number; testId: string; compact?: boolean; className?: string }) {
|
||||
const { t } = useTranslation();
|
||||
const value = Math.max(0, Math.min(100, Math.round(percent)));
|
||||
return (
|
||||
<div className={cn('space-y-1', compact ? 'text-xs' : 'text-sm', className)} data-testid={testId}>
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<span data-testid={`${testId}-text`}>{t('media.progress.working')}</span>
|
||||
<span className="tabular-nums" data-testid={`${testId}-percent`}>
|
||||
{value}%
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
role="progressbar"
|
||||
aria-label={t('media.progress.working')}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={value}
|
||||
aria-valuetext={`${value}%`}
|
||||
className={cn('w-full overflow-hidden rounded bg-muted', compact ? 'h-1.5' : 'h-2')}
|
||||
data-testid={`${testId}-bar`}
|
||||
>
|
||||
<div className="h-full bg-primary transition-all motion-reduce:transition-none" style={{ width: `${value}%` }} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* One percentage for the whole chain of a photo that is added: the upload takes the first part, the background processing
|
||||
* (cutting the variants, step by step on the server) the rest. A new crop has no upload, so it runs over the full bar.
|
||||
*/
|
||||
export const UPLOAD_SHARE = 30;
|
||||
|
||||
export type UploadStage = 'waiting' | 'uploading' | 'done';
|
||||
|
||||
/** The processing part, 0 to 1, from the steps the server reports (no steps yet = not started). */
|
||||
export function renderFraction(renderDone?: number | null, renderTotal?: number | null): number {
|
||||
return renderTotal ? Math.max(0, Math.min(1, (renderDone ?? 0) / renderTotal)) : 0;
|
||||
}
|
||||
|
||||
/** Overall percentage (0-100) of a photo: its upload stage, then its processing steps. `ready` photos are at 100. */
|
||||
export function photoProgress(options: { ready?: boolean; upload?: UploadStage; renderDone?: number | null; renderTotal?: number | null }): number {
|
||||
if (options.ready) return 100;
|
||||
if (options.upload === 'waiting') return 0;
|
||||
if (options.upload === 'uploading') return UPLOAD_SHARE / 2;
|
||||
const processing = renderFraction(options.renderDone, options.renderTotal);
|
||||
// An upload that is done (or a photo that was uploaded before) has its upload part behind it.
|
||||
return options.upload === undefined && options.renderTotal == null && processing === 0 ? UPLOAD_SHARE : UPLOAD_SHARE + (100 - UPLOAD_SHARE) * processing;
|
||||
}
|
||||
|
||||
/** A new crop only has the processing part. */
|
||||
export function recutProgress(renderDone?: number | null, renderTotal?: number | null): number {
|
||||
return Math.round(renderFraction(renderDone, renderTotal) * 100);
|
||||
}
|
||||
Reference in New Issue
Block a user