AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

design-progress.tsx 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useEffect, useState } from 'react';
  2. import { Spinner } from '@/components/ui/spinner';
  3. import type { StoreGeneration } from '@/types';
  4. const generateSteps = [
  5. 'Reading your brand description',
  6. 'Choosing colours and fonts',
  7. 'Picking the right sections',
  8. 'Writing your store text',
  9. 'Checking the design',
  10. ];
  11. const secondsPerStep = 12;
  12. /**
  13. * Shown while the AI is working in the background.
  14. * The steps are a friendly estimate based on time passed, not exact progress.
  15. */
  16. export default function DesignProgress({
  17. generation,
  18. }: {
  19. generation: StoreGeneration;
  20. }) {
  21. const startedAt = generation.created_at
  22. ? new Date(generation.created_at).getTime()
  23. : null;
  24. const [now, setNow] = useState(() => Date.now());
  25. useEffect(() => {
  26. const timer = setInterval(() => setNow(Date.now()), 1000);
  27. return () => clearInterval(timer);
  28. }, []);
  29. const elapsed = startedAt
  30. ? Math.max(0, Math.floor((now - startedAt) / 1000))
  31. : 0;
  32. const step = Math.min(
  33. generateSteps.length - 1,
  34. Math.floor(elapsed / secondsPerStep),
  35. );
  36. const isEdit = generation.type === 'edit';
  37. return (
  38. <div
  39. className="flex items-start gap-4 rounded-xl border p-6"
  40. role="status"
  41. aria-live="polite"
  42. data-test="design-progress"
  43. >
  44. <Spinner className="mt-0.5 size-5 shrink-0" />
  45. <div className="min-w-0">
  46. <h3 className="font-medium">
  47. {isEdit ? 'Making your change' : 'Designing your store'}
  48. </h3>
  49. <p className="mt-1 text-sm text-muted-foreground">
  50. {isEdit
  51. ? 'This usually takes a few seconds.'
  52. : `${generateSteps[step]}… This usually takes about a minute.`}
  53. </p>
  54. {isEdit && generation.instruction && (
  55. <p className="mt-2 truncate text-sm">
  56. “{generation.instruction}”
  57. </p>
  58. )}
  59. <p className="mt-2 text-xs text-muted-foreground">
  60. You can leave this page. The work continues in the
  61. background.
  62. </p>
  63. </div>
  64. </div>
  65. );
  66. }