| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { useEffect, useState } from 'react';
- import { Spinner } from '@/components/ui/spinner';
- import type { StoreGeneration } from '@/types';
-
- const generateSteps = [
- 'Reading your brand description',
- 'Choosing colours and fonts',
- 'Picking the right sections',
- 'Writing your store text',
- 'Checking the design',
- ];
-
- const secondsPerStep = 12;
-
- /**
- * Shown while the AI is working in the background.
- * The steps are a friendly estimate based on time passed, not exact progress.
- */
- export default function DesignProgress({
- generation,
- }: {
- generation: StoreGeneration;
- }) {
- const startedAt = generation.created_at
- ? new Date(generation.created_at).getTime()
- : null;
- const [now, setNow] = useState(() => Date.now());
-
- useEffect(() => {
- const timer = setInterval(() => setNow(Date.now()), 1000);
-
- return () => clearInterval(timer);
- }, []);
-
- const elapsed = startedAt
- ? Math.max(0, Math.floor((now - startedAt) / 1000))
- : 0;
- const step = Math.min(
- generateSteps.length - 1,
- Math.floor(elapsed / secondsPerStep),
- );
- const isEdit = generation.type === 'edit';
-
- return (
- <div
- className="flex items-start gap-4 rounded-xl border p-6"
- role="status"
- aria-live="polite"
- data-test="design-progress"
- >
- <Spinner className="mt-0.5 size-5 shrink-0" />
- <div className="min-w-0">
- <h3 className="font-medium">
- {isEdit ? 'Making your change' : 'Designing your store'}
- </h3>
- <p className="mt-1 text-sm text-muted-foreground">
- {isEdit
- ? 'This usually takes a few seconds.'
- : `${generateSteps[step]}… This usually takes about a minute.`}
- </p>
- {isEdit && generation.instruction && (
- <p className="mt-2 truncate text-sm">
- “{generation.instruction}”
- </p>
- )}
- <p className="mt-2 text-xs text-muted-foreground">
- You can leave this page. The work continues in the
- background.
- </p>
- </div>
- </div>
- );
- }
|