import { useCallback, useEffect, useState } from "react"; import CurvyRect, { Connector } from "@/components/shared/layout/curvy-rect"; import { encryptText } from "@/components/app/(home)/sections/hero/Title/Title"; import HeroScrapingCodeLoading from "./Loading/Loading"; import Code from "@/components/ui/code"; const URL = { value: "https://example.com", encrypted: "h=t*A:!/z!aap?A-cZz", }; const MARKDOWN = { value: "# Getting Started...", encrypted: "# ?0z-ang S*a-Z-a0*9", }; const TITLE = { value: "Guide", encrypted: "G!=*?", }; const SCREENSHOT = { value: "https://example.com/hero", encrypted: "ht-=*:/?*Za!zl=-?a9?h0-!", }; export default function HeroScrapingCode({ step }: { step: number }) { const [url, setUrl] = useState(URL.encrypted); const [markdown, setMarkdown] = useState(MARKDOWN.encrypted); const [title, setTitle] = useState(TITLE.encrypted); const [screenshot, setScreenshot] = useState(SCREENSHOT.encrypted); const reveal = useCallback((value: string, setter: (v: string) => void) => { let progress = 0; let increaseProgress = -10; const animate = () => { increaseProgress = (increaseProgress + 1) % 5; if (increaseProgress === 4) { progress += 0.2; } if (progress > 1) { progress = 1; setter(encryptText(value, progress, { randomizeChance: 0.3 })); return; } setter(encryptText(value, progress, { randomizeChance: 0.3 })); const interval = 70 + progress * 30; setTimeout(animate, interval); }; animate(); }, []); useEffect(() => { if (step >= 0 && url === URL.encrypted) reveal(URL.value, setUrl); if (step >= 3 && title === TITLE.encrypted) reveal(TITLE.value, setTitle); if (step >= 4 && markdown === MARKDOWN.encrypted) reveal(MARKDOWN.value, setMarkdown); if (step >= 5 && screenshot === SCREENSHOT.encrypted) reveal(SCREENSHOT.value, setScreenshot); const interval = setInterval(() => { if (step < 0) { URL.encrypted = encryptText(URL.value, 0, { randomizeChance: 0.3 }); setUrl(URL.encrypted); } if (step < 3) { TITLE.encrypted = encryptText(TITLE.value, 0, { randomizeChance: 0.3 }); setTitle(TITLE.encrypted); } if (step < 4) { MARKDOWN.encrypted = encryptText(MARKDOWN.value, 0, { randomizeChance: 0.3, }); setMarkdown(MARKDOWN.encrypted); } if (step < 5) { SCREENSHOT.encrypted = encryptText(SCREENSHOT.value, 0, { randomizeChance: 0.3, }); setScreenshot(SCREENSHOT.encrypted); } }, 70); return () => clearInterval(interval); // eslint-disable-next-line react-hooks/exhaustive-deps }, [step, reveal]); return (