"use client"; import { useState, useEffect } from "react"; import { QUOTES } from "@/lib/quotes"; export default function TerminalBox({ children }: { children: React.ReactNode }) { const [showFirstPrompt, setShowFirstPrompt] = useState(false); const [showEnterEcho, setShowEnterEcho] = useState(false); const [typedCommand1, setTypedCommand1] = useState(""); const [showQuote, setShowQuote] = useState(false); const [quote, setQuote] = useState(""); const [typedCommand2, setTypedCommand2] = useState(""); const [showLoader, setShowLoader] = useState(false); const [loaderProgress, setLoaderProgress] = useState(0); const [showTree, setShowTree] = useState(false); // INIT useEffect(() => { setQuote(QUOTES[Math.floor(Math.random() * QUOTES.length)]); setTimeout(() => setShowFirstPrompt(true), 400); setTimeout(() => setShowEnterEcho(true), 1500); setTimeout(() => typeCommand1(), 1800); }, []); // TYPE COMMAND 1 const typeCommand1 = () => { const cmd = "juntekim@site:~$ quoteOfTheDay"; let i = 0; const interval = setInterval(() => { setTypedCommand1(cmd.slice(0, i + 1)); i++; if (i >= cmd.length) { clearInterval(interval); setTimeout(() => setShowQuote(true), 300); setTimeout(() => typeCommand2(), 1200); } }, 50); }; // TYPE COMMAND 2 const typeCommand2 = () => { const cmd = "juntekim@site:~$ tree ."; let i = 0; const interval = setInterval(() => { setTypedCommand2(cmd.slice(0, i + 1)); i++; if (i >= cmd.length) { clearInterval(interval); setTimeout(() => startLoader(), 400); } }, 60); }; // LOADER const startLoader = () => { setShowLoader(true); let progress = 0; const interval = setInterval(() => { progress += Math.random() * 20; if (progress >= 100) { progress = 100; clearInterval(interval); setTimeout(() => { setShowTree(true); setShowLoader(false); }, 500); } setLoaderProgress(Math.floor(progress)); }, 300); }; // Loader UI const LoaderBar = () => (
compiling… {loaderProgress}%
); return (
{/* Prompt 1 */} {showFirstPrompt &&
juntekim@site:~$
} {/* Enter echo */} {showEnterEcho &&
juntekim@site:~$
} {/* Command 1 (NO cursor here) */} {typedCommand1 && (
{typedCommand1}
)} {/* Quote */} {showQuote && (
{quote}
)} {/* Command 2 (NO cursor here) */} {typedCommand2 && (
{typedCommand2}
)} {/* Loader */} {showLoader && } {/* Final tree */} {showTree && (
/
{children}
{/* Final Prompt WITH cursor */}
juntekim@site:~$ â–®
)}
); }