import { CSSProperties, useState, useEffect } from "react"; import cn from "../utils/classnames.ts"; import { MODEL_FACTS } from "../constants.ts"; export default function ModelLoader({ progress, className = "", style, }: { progress: number; className?: string; style?: CSSProperties; }) { const [shuffledFacts, setShuffledFacts] = useState([]); const [currentFactIndex, setCurrentFactIndex] = useState(0); const [isTransitioning, setIsTransitioning] = useState(false); // Shuffle facts on mount useEffect(() => { const shuffled = [...MODEL_FACTS].sort(() => Math.random() - 0.5); setShuffledFacts(shuffled); }, []); // Rotate facts every 5 seconds useEffect(() => { if (shuffledFacts.length === 0) return; const interval = setInterval(() => { setIsTransitioning(true); setTimeout(() => { setCurrentFactIndex((prev) => (prev + 1) % shuffledFacts.length); setIsTransitioning(false); }, 400); // Half of transition duration for crossfade }, 10_000); return () => clearInterval(interval); }, [shuffledFacts]); return (
{shuffledFacts.length > 0 && (

{shuffledFacts[currentFactIndex]}

)} {/* Progress */}
Loading model... {progress.toFixed(2)}%

This may take a few moments. Please don't close the page.

); }