File size: 2,176 Bytes
83003f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { useState, useEffect } from "react";
import { Box, Typography } from "@mui/material";
import { motion } from "framer-motion";
import CreateIcon from "@mui/icons-material/Create";
import AutoStoriesIcon from "@mui/icons-material/AutoStories";
import PaletteIcon from "@mui/icons-material/Palette";

const defaultMessages = [
  "waking up a sleepy AI...",
  "teaching robots to tell bedtime stories...",
  "bribing pixels to make pretty pictures...",
];

const iconMap = {
  story: CreateIcon,
  universe: AutoStoriesIcon,
  art: PaletteIcon,
};

export const LoadingScreen = ({
  messages = defaultMessages,
  icon = "story",
  messageInterval = 3000,
  iconColor = "white",
  textColor = "white",
}) => {
  const [currentMessage, setCurrentMessage] = useState(0);
  const IconComponent = iconMap[icon] || CreateIcon;

  useEffect(() => {
    const interval = setInterval(() => {
      setCurrentMessage((prev) => (prev + 1) % messages.length);
    }, messageInterval);
    return () => clearInterval(interval);
  }, [messages.length, messageInterval]);

  return (
    <Box
      sx={{
        position: "absolute",
        top: "50%",
        left: "50%",
        transform: "translate(-50%, -50%)",
        display: "flex",
        flexDirection: "column",
        alignItems: "center",
        gap: 2,
      }}
    >
      <motion.div
        animate={{
          y: [0, -10, 0],
        }}
        transition={{
          duration: 2,
          repeat: Infinity,
          ease: "easeInOut",
        }}
      >
        <IconComponent
          sx={{
            fontSize: 40,
            color: iconColor,
            opacity: 0.2,
          }}
        />
      </motion.div>
      <motion.div
        key={currentMessage}
        initial={{ opacity: 0, y: 5 }}
        animate={{ opacity: 1, y: 0 }}
        exit={{ opacity: 0, y: -5 }}
        transition={{ duration: 0.3 }}
      >
        <Typography
          variant="body1"
          sx={{
            color: textColor,
            opacity: 0.8,
            fontStyle: "italic",
          }}
        >
          {messages[currentMessage]}
        </Typography>
      </motion.div>
    </Box>
  );
};