Spaces:
Paused
Paused
Download components/CinematicPreloader.tsx from samirhosninet/HubAPI: direct link, hf CLI and curl.
- Browser
- Download file 7.01 kB
-
https://huggingface.co/spaces/samirhosninet/HubAPI/resolve/main/components/CinematicPreloader.tsx
- Command line
-
hf download hf://spaces/samirhosninet/HubAPI/components/CinematicPreloader.tsx
-
curl -L -o CinematicPreloader.tsx https://huggingface.co/spaces/samirhosninet/HubAPI/resolve/main/components/CinematicPreloader.tsx
7.01 kB
| "use client"; | |
| import { useEffect, useState } from "react"; | |
| import { motion, AnimatePresence } from "framer-motion"; | |
| import { useLanguage } from "@/components/LanguageContext"; | |
| import { useSplitFlapAudio } from "@/components/ui/split-flap-text"; | |
| export function CinematicPreloader() { | |
| const { t, language } = useLanguage(); | |
| const audio = useSplitFlapAudio(); | |
| const [isVisible, setIsVisible] = useState(false); | |
| const [progress, setProgress] = useState(0); | |
| const [logs, setLogs] = useState<string[]>([]); | |
| const [stage, setStage] = useState(0); | |
| useEffect(() => { | |
| const init = setTimeout(() => { | |
| // Check session storage to show only once per session | |
| const hasSeenPreloader = sessionStorage.getItem("hubapi_preloader_seen"); | |
| if (hasSeenPreloader === "true") { | |
| setIsVisible(false); | |
| return; | |
| } | |
| setIsVisible(true); | |
| }, 0); | |
| return () => clearTimeout(init); | |
| }, []); | |
| useEffect(() => { | |
| if (!isVisible) return; | |
| // Simulate step-by-step logs loading in correct language | |
| const logsEn = [ | |
| "CONNECTING TO NEURAL MESH GATEWAY...", | |
| "ESTABLISHING HOSTINGER SECURE HANDSHAKE...", | |
| "INITIALIZING THREE.JS WEBGL PARTICLE SYSTEM...", | |
| "SYNCHRONIZING LATENCY METRICS AT EDGE NODES...", | |
| "TUNING INTELLIGENT MODEL ROUTERS...", | |
| "GATEWAY STABLE. SECURING NEURAL CHANNEL...", | |
| ]; | |
| const logsAr = [ | |
| "جاري الاتصال بـالبوابة العصبية العالمية...", | |
| "بدء المصافحة الآمنة مع خوادم HOSTINGER...", | |
| "تهيئة نظام الجسيمات ثلاثي الأبعاد WebGL...", | |
| "مزامنة مقاييس زمن الاستجابة في بوابات الحافة...", | |
| "تحسين موجهات الذكاء الاصطناعي التلقائية...", | |
| "البوابة مستقرة. تأمين القناة العصبية...", | |
| ]; | |
| const currentLogs = language === "ar" ? logsAr : logsEn; | |
| if (stage < currentLogs.length) { | |
| const timer = setTimeout(() => { | |
| setLogs((prev) => [...prev, `${currentLogs[stage]} [OK]`]); | |
| setStage((prev) => prev + 1); | |
| // Play subtle click audio if not muted | |
| if (audio && !audio.isMuted) { | |
| audio.playClick(); | |
| } | |
| }, 400); | |
| return () => clearTimeout(timer); | |
| } | |
| }, [isVisible, stage, language, audio]); | |
| useEffect(() => { | |
| if (!isVisible) return; | |
| const interval = setInterval(() => { | |
| setProgress((prev) => { | |
| if (prev >= 100) { | |
| clearInterval(interval); | |
| setTimeout(() => { | |
| // Dismiss preloader | |
| setIsVisible(false); | |
| sessionStorage.setItem("hubapi_preloader_seen", "true"); | |
| // Play satisfying final release chime | |
| if (audio && !audio.isMuted) { | |
| audio.playClick(); // Click as fallback | |
| } | |
| }, 600); | |
| return 100; | |
| } | |
| // Accelerate progress based on stages loaded | |
| const increment = stage === 6 ? 15 : Math.floor(Math.random() * 8) + 4; | |
| return Math.min(prev + increment, 100); | |
| }); | |
| }, 200); | |
| return () => clearInterval(interval); | |
| }, [isVisible, stage, audio]); | |
| return ( | |
| <AnimatePresence> | |
| {isVisible && ( | |
| <motion.div | |
| initial={{ opacity: 1 }} | |
| exit={{ | |
| opacity: 0, | |
| y: -50, | |
| transition: { duration: 0.8, ease: [0.76, 0, 0.24, 1] }, | |
| }} | |
| className="fixed inset-0 z-[9999] bg-black flex flex-col items-center justify-center p-6 select-none font-mono text-xs overflow-hidden" | |
| > | |
| {/* Subtle glowing grid background */} | |
| <div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:40px_40px] pointer-events-none opacity-20" /> | |
| <div className="absolute w-[500px] h-[500px] bg-primary/5 rounded-full blur-[100px] pointer-events-none" /> | |
| <div className="w-full max-w-lg space-y-8 relative z-10"> | |
| {/* Header Glitch Title */} | |
| <div className="flex flex-col items-center text-center space-y-2"> | |
| <motion.div | |
| initial={{ scale: 0.9, opacity: 0 }} | |
| animate={{ scale: 1, opacity: 1 }} | |
| transition={{ duration: 0.5 }} | |
| className="w-12 h-12 border border-primary/40 rounded flex items-center justify-center relative shadow-[0_0_15px_rgba(var(--primary-rgb),0.2)]" | |
| > | |
| <div className="absolute w-3 h-3 bg-primary rounded-full animate-pulse shadow-[0_0_10px_var(--primary-glow)]" /> | |
| </motion.div> | |
| <h2 className="font-fast-hand text-3xl tracking-widest text-foreground mt-4"> | |
| HUBAPI | |
| </h2> | |
| <p className="text-[10px] text-muted-foreground/60 tracking-[0.2em] uppercase"> | |
| {t("loading")} | |
| </p> | |
| </div> | |
| {/* Terminal Live Diagnostics */} | |
| <div className="h-44 p-5 rounded border border-white/5 bg-secondary/15 backdrop-blur-md overflow-hidden flex flex-col justify-end text-[10px] sm:text-xs text-primary/80 leading-relaxed font-mono"> | |
| <div className="space-y-1.5 overflow-y-auto max-h-full pr-2"> | |
| {logs.map((log, index) => ( | |
| <motion.div | |
| key={index} | |
| initial={{ opacity: 0, x: -10 }} | |
| animate={{ opacity: 1, x: 0 }} | |
| transition={{ duration: 0.3 }} | |
| className="flex justify-between items-center gap-4" | |
| > | |
| <span>{log.split(" [OK]")[0]}</span> | |
| <span className="text-primary font-bold">✓ DONE</span> | |
| </motion.div> | |
| ))} | |
| {stage < 6 && ( | |
| <div className="flex items-center gap-1.5"> | |
| <span className="w-1 h-3 bg-primary animate-pulse" /> | |
| <span className="text-muted-foreground/60">...</span> | |
| </div> | |
| )} | |
| </div> | |
| </div> | |
| {/* Progress Bar Container */} | |
| <div className="space-y-2"> | |
| <div className="flex justify-between text-[10px] tracking-widest text-muted-foreground/60"> | |
| <span>SYSTEM_INITIALIZATION</span> | |
| <span className="font-bold text-primary">{progress}%</span> | |
| </div> | |
| <div className="relative w-full h-1.5 bg-secondary/25 border border-white/5 rounded-full overflow-hidden"> | |
| <motion.div | |
| className="h-full bg-gradient-to-r from-primary to-amber-500 shadow-[0_0_10px_var(--primary-glow)]" | |
| style={{ width: `${progress}%` }} | |
| /> | |
| </div> | |
| </div> | |
| </div> | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| ); | |
| } | |