aboutsummaryrefslogtreecommitdiffstats
path: root/frontend/src/components/loading.tsx
blob: cbd5c15dbff090e6a374940b95392dc1bc5a3635 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"use client";

import { useEffect, useState } from "react";
import Image from "next/image";

export function LoadingScreen() {
  const [isVisible, setIsVisible] = useState(true);

  useEffect(() => {
    // Hide loading screen after a short delay to ensure everything is ready
    const timer = setTimeout(() => {
      setIsVisible(false);
    }, 1000);

    return () => clearTimeout(timer);
  }, []);

  if (!isVisible) return null;

  return (
    <div className="fixed inset-0 z-[9999] bg-background flex items-center justify-center">
      {/* Background pattern */}
      <div className="absolute inset-0 bg-gradient-to-br from-background via-background to-muted/20" />
      
      {/* Loading content */}
      <div className="relative z-10 flex flex-col items-center space-y-4">
        {/* Logo with animation */}
        <div className="relative">
          <div className="animate-pulse">
            <Image
              src="/black-logo.png"
              alt="blcklst"
              width={160}
              height={50}
              className="h-12 w-auto block dark:hidden"
              priority
            />
            <Image
              src="/white-logo.png"
              alt="blcklst"
              width={160}
              height={50}
              className="h-12 w-auto hidden dark:block"
              priority
            />
          </div>
        </div>

        {/* Loading text - closer to logo */}
        <div className="text-center space-y-3 -mt-2">
          <p className="text-sm text-muted-foreground animate-pulse">
            not everyone gets blcklsted
          </p>
          
          {/* Loading dots */}
          <div className="flex items-center justify-center space-x-1">
            <div className="w-2 h-2 bg-foreground/60 rounded-full animate-bounce [animation-delay:-0.3s]"></div>
            <div className="w-2 h-2 bg-foreground/60 rounded-full animate-bounce [animation-delay:-0.15s]"></div>
            <div className="w-2 h-2 bg-foreground/60 rounded-full animate-bounce"></div>
          </div>
        </div>

        {/* Progress bar */}
        <div className="w-64 h-1 bg-muted rounded-full overflow-hidden">
          <div className="h-full bg-foreground rounded-full animate-[loading_1s_ease-in-out_infinite]"></div>
        </div>
      </div>
    </div>
  );
}

export function PageWrapper({ children }: { children: React.ReactNode }) {
  const [isLoading, setIsLoading] = useState(true);
  const [showContent, setShowContent] = useState(false);

  useEffect(() => {
    // Check if page is ready
    const checkReady = () => {
      if (document.readyState === 'complete') {
        setTimeout(() => {
          setIsLoading(false);
          setTimeout(() => setShowContent(true), 100);
        }, 800);
      }
    };

    if (document.readyState === 'complete') {
      checkReady();
    } else {
      window.addEventListener('load', checkReady);
    }

    return () => {
      window.removeEventListener('load', checkReady);
    };
  }, []);

  return (
    <>
      {isLoading && <LoadingScreen />}
      <div 
        className={`transition-opacity duration-500 ${
          showContent ? 'opacity-100' : 'opacity-0'
        }`}
        suppressHydrationWarning
      >
        {children}
      </div>
    </>
  );
}