2026-11-17 06:45:33 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
|
|
|
|
|
import { ZodiacWheel } from "./ZodiacWheel";
|
|
|
|
|
|
2026-11-18 21:47:37 +00:00
|
|
|
/**
|
|
|
|
|
* Slowly turning wheel with the elapsed time, while the LLM writes. The time
|
|
|
|
|
* counts from `since` (when the text was asked for), so it does not start
|
|
|
|
|
* again from zero after a reload; without it, from when the wheel appeared.
|
|
|
|
|
*/
|
|
|
|
|
export function AnalysisLoading({
|
|
|
|
|
title,
|
|
|
|
|
text,
|
|
|
|
|
compact = false,
|
|
|
|
|
since,
|
|
|
|
|
}: {
|
|
|
|
|
title?: string;
|
|
|
|
|
text: string;
|
|
|
|
|
compact?: boolean;
|
|
|
|
|
since?: string;
|
|
|
|
|
}) {
|
|
|
|
|
const [start] = useState(() => {
|
|
|
|
|
const t = since ? Date.parse(since) : NaN;
|
|
|
|
|
return Number.isNaN(t) ? Date.now() : Math.min(t, Date.now());
|
|
|
|
|
});
|
|
|
|
|
const [seconds, setSeconds] = useState(() => Math.floor((Date.now() - start) / 1000));
|
2026-11-17 06:45:33 +00:00
|
|
|
useEffect(() => {
|
2026-11-18 21:47:37 +00:00
|
|
|
const t = setInterval(() => setSeconds(Math.floor((Date.now() - start) / 1000)), 1000);
|
2026-11-17 06:45:33 +00:00
|
|
|
return () => clearInterval(t);
|
2026-11-18 21:47:37 +00:00
|
|
|
}, [start]);
|
2026-11-17 06:45:33 +00:00
|
|
|
const elapsed = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, "0")}`;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={compact ? "loading loading-compact" : "loading"}>
|
|
|
|
|
<ZodiacWheel className="loading-wheel" />
|
|
|
|
|
<div className="loading-text">
|
|
|
|
|
{title && <strong>{title}</strong>}
|
|
|
|
|
<p className="muted" role="status">
|
|
|
|
|
{text}
|
|
|
|
|
</p>
|
2026-11-18 21:47:37 +00:00
|
|
|
<p className="hint" aria-hidden="true" suppressHydrationWarning>
|
2026-11-17 06:45:33 +00:00
|
|
|
{elapsed}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|