AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

design-progress.tsx 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. // A job normally starts within a few seconds. If it is still only queued, nothing is picking it up.
  38. const waitingTooLong = generation.status === 'queued' && elapsed > 20;
  39. return (
  40. <div
  41. className="flex items-start gap-4 rounded-xl border p-6"
  42. role="status"
  43. aria-live="polite"
  44. data-test="design-progress"
  45. >
  46. <Spinner className="mt-0.5 size-5 shrink-0" />
  47. <div className="min-w-0">
  48. <h3 className="font-medium">
  49. {isEdit ? 'Making your change' : 'Designing your store'}
  50. </h3>
  51. <p className="mt-1 text-sm text-muted-foreground">
  52. {isEdit
  53. ? 'This usually takes a few seconds.'
  54. : `${generateSteps[step]}… This usually takes about a minute.`}
  55. </p>
  56. {isEdit && generation.instruction && (
  57. <p className="mt-2 truncate text-sm">
  58. “{generation.instruction}”
  59. </p>
  60. )}
  61. {waitingTooLong ? (
  62. <p
  63. className="mt-2 text-xs text-amber-700 dark:text-amber-400"
  64. data-test="worker-hint"
  65. >
  66. This has not started yet. The background worker may not
  67. be running. On a development machine, start it with
  68. “composer run dev”.
  69. </p>
  70. ) : (
  71. <p className="mt-2 text-xs text-muted-foreground">
  72. You can leave this page. The work continues in the
  73. background.
  74. </p>
  75. )}
  76. </div>
  77. </div>
  78. );
  79. }