|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React, { useEffect, useState, useMemo } from 'react'; |
| 4 | +import { motion, AnimatePresence } from 'framer-motion'; |
| 5 | +import Image from 'next/image'; |
| 6 | + |
| 7 | +interface LoadingScreenProps { |
| 8 | + message?: string; |
| 9 | +} |
| 10 | + |
| 11 | +const MBTI_GROUPS = [ |
| 12 | + { |
| 13 | + name: 'Analysts', |
| 14 | + color: '#E0D7FF', // Purple-ish |
| 15 | + textColor: '#5D2FB7', |
| 16 | + characters: ['INTJ', 'INTP', 'ENTJ', 'ENTP'], |
| 17 | + }, |
| 18 | + { |
| 19 | + name: 'Diplomats', |
| 20 | + color: '#D7FFD7', // Green-ish |
| 21 | + textColor: '#2D812D', |
| 22 | + characters: ['INFJ', 'INFP', 'ENFJ', 'ENFP'], |
| 23 | + }, |
| 24 | + { |
| 25 | + name: 'Sentinels', |
| 26 | + color: '#D7F3FF', // Blue-ish |
| 27 | + textColor: '#2B6DA1', |
| 28 | + characters: ['ISTJ', 'ISFJ', 'ESTJ', 'ESFJ'], |
| 29 | + }, |
| 30 | + { |
| 31 | + name: 'Explorers', |
| 32 | + color: '#FFF7D7', // Yellow-ish |
| 33 | + textColor: '#A17D1F', |
| 34 | + characters: ['ISTP', 'ISFP', 'ESTP', 'ESFP'], |
| 35 | + }, |
| 36 | +]; |
| 37 | + |
| 38 | +export default function LoadingScreen({ |
| 39 | + message = 'Loading...', |
| 40 | +}: LoadingScreenProps) { |
| 41 | + const [activeStep, setActiveStep] = useState(0); |
| 42 | + |
| 43 | + // Pick one random character from each group |
| 44 | + const selectedCharacters = useMemo(() => { |
| 45 | + return MBTI_GROUPS.map((group) => { |
| 46 | + const randomIndex = Math.floor(Math.random() * group.characters.length); |
| 47 | + return { |
| 48 | + id: group.characters[randomIndex], |
| 49 | + groupColor: group.color, |
| 50 | + textColor: group.textColor, |
| 51 | + }; |
| 52 | + }); |
| 53 | + }, []); |
| 54 | + |
| 55 | + useEffect(() => { |
| 56 | + const timer = setInterval(() => { |
| 57 | + setActiveStep((prev) => (prev + 1) % selectedCharacters.length); |
| 58 | + }, 1500); // Wait for jump animation to mostly complete |
| 59 | + |
| 60 | + return () => clearInterval(timer); |
| 61 | + }, [selectedCharacters.length]); |
| 62 | + |
| 63 | + return ( |
| 64 | + <motion.div |
| 65 | + className="fixed inset-0 z-[9999] flex flex-col items-center justify-center overflow-hidden" |
| 66 | + initial={{ backgroundColor: selectedCharacters[0].groupColor }} |
| 67 | + animate={{ backgroundColor: selectedCharacters[activeStep].groupColor }} |
| 68 | + transition={{ duration: 0.8 }} |
| 69 | + > |
| 70 | + {/* Retro-pop dot pattern background */} |
| 71 | + <div |
| 72 | + className="absolute inset-0 opacity-40" |
| 73 | + style={{ |
| 74 | + backgroundImage: 'radial-gradient(circle, #fff 2px, transparent 2px)', |
| 75 | + backgroundSize: '24px 24px', |
| 76 | + }} |
| 77 | + /> |
| 78 | + |
| 79 | + <div className="relative z-10 flex flex-col items-center"> |
| 80 | + {/* Characters Row */} |
| 81 | + <div className="mb-12 flex items-end justify-center gap-4 sm:gap-8"> |
| 82 | + {selectedCharacters.map((char, index) => { |
| 83 | + const isActive = index === activeStep; |
| 84 | + |
| 85 | + return ( |
| 86 | + <div |
| 87 | + key={char.id} |
| 88 | + className="relative flex flex-col items-center" |
| 89 | + > |
| 90 | + <motion.div |
| 91 | + animate={ |
| 92 | + isActive |
| 93 | + ? { |
| 94 | + y: [0, -60, 0], |
| 95 | + scale: [1, 1.1, 1], |
| 96 | + } |
| 97 | + : { y: 0, scale: 0.9 } |
| 98 | + } |
| 99 | + transition={{ |
| 100 | + duration: 0.6, |
| 101 | + ease: 'easeOut', |
| 102 | + }} |
| 103 | + className="relative h-24 w-24 sm:h-32 sm:w-32" |
| 104 | + > |
| 105 | + <Image |
| 106 | + src={`/images/mbti/${char.id}.png`} |
| 107 | + alt={char.id} |
| 108 | + fill |
| 109 | + className="object-contain" |
| 110 | + priority |
| 111 | + /> |
| 112 | + </motion.div> |
| 113 | + |
| 114 | + {/* Visual indicator / shadow under active char */} |
| 115 | + <motion.div |
| 116 | + className="mt-2 h-2 rounded-full bg-black/10" |
| 117 | + animate={ |
| 118 | + isActive |
| 119 | + ? { width: ['40%', '20%', '40%'], opacity: [0.2, 0.1, 0.2] } |
| 120 | + : { width: '40%', opacity: 0.2 } |
| 121 | + } |
| 122 | + transition={{ duration: 0.6 }} |
| 123 | + /> |
| 124 | + </div> |
| 125 | + ); |
| 126 | + })} |
| 127 | + </div> |
| 128 | + |
| 129 | + {/* Loading Text */} |
| 130 | + <div className="relative"> |
| 131 | + <motion.p |
| 132 | + key={activeStep} |
| 133 | + initial={{ y: 10, opacity: 0 }} |
| 134 | + animate={{ y: 0, opacity: 1 }} |
| 135 | + className="text-4xl font-black italic tracking-wider sm:text-5xl" |
| 136 | + style={{ |
| 137 | + color: 'black', |
| 138 | + WebkitTextStroke: '2px white', |
| 139 | + textShadow: '4px 4px 0px rgba(0,0,0,0.1)', |
| 140 | + }} |
| 141 | + > |
| 142 | + {message} |
| 143 | + </motion.p> |
| 144 | + |
| 145 | + {/* Pulsing dots indicator */} |
| 146 | + <div className="mt-4 flex justify-center gap-2"> |
| 147 | + {[0, 1, 2].map((i) => ( |
| 148 | + <motion.div |
| 149 | + key={i} |
| 150 | + animate={{ |
| 151 | + scale: [1, 1.5, 1], |
| 152 | + opacity: [0.3, 1, 0.3], |
| 153 | + }} |
| 154 | + transition={{ |
| 155 | + duration: 0.8, |
| 156 | + repeat: Infinity, |
| 157 | + delay: i * 0.2, |
| 158 | + }} |
| 159 | + className="h-3 w-3 rounded-full bg-current" |
| 160 | + style={{ color: selectedCharacters[activeStep].textColor }} |
| 161 | + /> |
| 162 | + ))} |
| 163 | + </div> |
| 164 | + </div> |
| 165 | + </div> |
| 166 | + |
| 167 | + {/* Group Name display (Subtle) */} |
| 168 | + <div className="absolute bottom-8 left-0 right-0 flex justify-center"> |
| 169 | + <motion.p |
| 170 | + key={activeStep} |
| 171 | + initial={{ opacity: 0 }} |
| 172 | + animate={{ opacity: 0.4 }} |
| 173 | + className="text-sm font-bold uppercase tracking-[0.3em] text-black" |
| 174 | + > |
| 175 | + {MBTI_GROUPS[activeStep].name} |
| 176 | + </motion.p> |
| 177 | + </div> |
| 178 | + </motion.div> |
| 179 | + ); |
| 180 | +} |
0 commit comments