File size: 1,698 Bytes
75fefa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { AnimatePresence, motion } from "motion/react";
import { useEffect, useState } from "react";

import { encryptText } from "@/components/app/(home)/sections/hero/Title/Title";
import AnimatedWidth from "@/components/shared/layout/animated-width";
import Spinner from "@/components/ui/spinner";

export default function HeroScrapingCodeLoading({
  finished,
}: {
  finished: boolean;
}) {
  const [scrapingText, setScrapingText] = useState("Scraping...");

  useEffect(() => {
    if (finished) return;

    let timeout = 0;
    let tick = 0;

    const animate = () => {
      tick += 1;

      if (tick % 3 !== 0) {
        setScrapingText(
          encryptText("Scraping", 0, {
            randomizeChance: 0.6 + Math.random() * 0.3,
          }) + "...",
        );
      } else {
        setScrapingText("Scraping...");
      }

      const interval = 80;
      timeout = window.setTimeout(animate, interval);
    };

    animate();

    return () => {
      window.clearTimeout(timeout);
    };
  }, [finished]);

  return (
    <div className="flex gap-6 p-6 pr-0 rounded-full inside-border before:border-border-faint absolute right-20 bottom-20 text-mono-small font-mono text-accent-black">
      <Spinner finished={finished} />

      <AnimatedWidth initial={{ width: "auto" }}>
        <AnimatePresence initial={false} mode="popLayout">
          <motion.div
            animate={{ opacity: 1, x: 0 }}
            className="pr-12"
            exit={{ opacity: 0, x: 10 }}
            initial={{ opacity: 0, x: -10 }}
          >
            {finished ? "Scrape Completed" : scrapingText}
          </motion.div>
        </AnimatePresence>
      </AnimatedWidth>
    </div>
  );
}