tfrere commited on
Commit
7eed06f
·
1 Parent(s): b4fbe2e

fix slot machine loading and healthchecks

Browse files
client/src/main.jsx CHANGED
@@ -10,7 +10,6 @@ import { Tutorial } from "./pages/Tutorial";
10
  import Debug from "./pages/Debug";
11
  import { Universe } from "./pages/Universe";
12
  import { SoundProvider } from "./contexts/SoundContext";
13
- import { ServiceStatusProvider } from "./contexts/ServiceStatusContext";
14
  import { GameNavigation } from "./components/GameNavigation";
15
  import { AppBackground } from "./components/AppBackground";
16
  import "./index.css";
@@ -19,19 +18,17 @@ ReactDOM.createRoot(document.getElementById("root")).render(
19
  <ThemeProvider theme={theme}>
20
  <CssBaseline />
21
  <SoundProvider>
22
- <ServiceStatusProvider>
23
- <BrowserRouter>
24
- <GameNavigation />
25
- <AppBackground />
26
- <Routes>
27
- <Route path="/" element={<Home />} />
28
- <Route path="/game" element={<Game />} />
29
- <Route path="/tutorial" element={<Tutorial />} />
30
- <Route path="/debug" element={<Debug />} />
31
- <Route path="/universe" element={<Universe />} />
32
- </Routes>
33
- </BrowserRouter>
34
- </ServiceStatusProvider>
35
  </SoundProvider>
36
  </ThemeProvider>
37
  );
 
10
  import Debug from "./pages/Debug";
11
  import { Universe } from "./pages/Universe";
12
  import { SoundProvider } from "./contexts/SoundContext";
 
13
  import { GameNavigation } from "./components/GameNavigation";
14
  import { AppBackground } from "./components/AppBackground";
15
  import "./index.css";
 
18
  <ThemeProvider theme={theme}>
19
  <CssBaseline />
20
  <SoundProvider>
21
+ <BrowserRouter>
22
+ <GameNavigation />
23
+ <AppBackground />
24
+ <Routes>
25
+ <Route path="/" element={<Home />} />
26
+ <Route path="/game" element={<Game />} />
27
+ <Route path="/tutorial" element={<Tutorial />} />
28
+ <Route path="/debug" element={<Debug />} />
29
+ <Route path="/universe" element={<Universe />} />
30
+ </Routes>
31
+ </BrowserRouter>
 
 
32
  </SoundProvider>
33
  </ThemeProvider>
34
  );
client/src/pages/Game.jsx CHANGED
@@ -329,8 +329,8 @@ function GameContent() {
329
  );
330
  }
331
 
332
- // Show loading state while session is initializing
333
- if (isSessionLoading) {
334
  return (
335
  <Box
336
  sx={{
@@ -356,8 +356,8 @@ function GameContent() {
356
  );
357
  }
358
 
359
- // Afficher la slot machine pendant le chargement initial
360
- if (isInitialLoading) {
361
  return (
362
  <Box sx={{ width: "100%", height: "100vh", backgroundColor: "#1a1a1a" }}>
363
  <UniverseSlotMachine
 
329
  );
330
  }
331
 
332
+ // Show loading state while session is initializing or universe is not ready
333
+ if (isSessionLoading || !gameUniverse || !slotMachineState.style) {
334
  return (
335
  <Box
336
  sx={{
 
356
  );
357
  }
358
 
359
+ // Afficher la slot machine seulement si on a l'univers ET les données sont initialisées
360
+ if (isInitialLoading && gameUniverse && slotMachineState.style) {
361
  return (
362
  <Box sx={{ width: "100%", height: "100vh", backgroundColor: "#1a1a1a" }}>
363
  <UniverseSlotMachine
client/src/pages/Home.jsx CHANGED
@@ -5,22 +5,31 @@ import {
5
  useTheme,
6
  useMediaQuery,
7
  Tooltip,
 
8
  } from "@mui/material";
9
  import { motion } from "framer-motion";
10
  import { useNavigate } from "react-router-dom";
11
  import { useSoundSystem } from "../contexts/SoundContext";
12
- import { useServiceStatus } from "../contexts/ServiceStatusContext";
 
 
 
13
  import { BlinkingText } from "../components/BlinkingText";
14
  import { BookPages } from "../components/BookPages";
15
  import { ServiceStatus } from "../components/ServiceStatus";
16
 
17
- export function Home() {
18
  const navigate = useNavigate();
19
  const { playSound } = useSoundSystem();
20
- const { areServicesHealthy } = useServiceStatus();
21
  const theme = useTheme();
22
  const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
23
 
 
 
 
 
 
24
  const handlePlay = () => {
25
  playSound("page");
26
  navigate("/tutorial");
@@ -32,15 +41,40 @@ export function Home() {
32
  size="large"
33
  variant="contained"
34
  onClick={handlePlay}
35
- disabled={!areServicesHealthy()}
36
  sx={{
37
  mt: 4,
38
  fontSize: isMobile ? "1rem" : "1.2rem",
39
  padding: isMobile ? "8px 24px" : "12px 36px",
40
  zIndex: 10,
 
 
41
  }}
42
  >
43
- Play
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  </Button>
45
  );
46
 
@@ -119,17 +153,29 @@ export function Home() {
119
  Experience a unique comic book where artificial intelligence brings
120
  your choices to life, shaping the narrative as you explore.
121
  </Typography>
122
- {areServicesHealthy() ? (
123
- playButton
124
- ) : (
125
  <Tooltip
126
- title="Services are currently unavailable. Please wait..."
 
 
 
 
127
  arrow
128
  >
129
  <span>{playButton}</span>
130
  </Tooltip>
 
 
131
  )}
132
  </Box>
133
  </motion.div>
134
  );
135
  }
 
 
 
 
 
 
 
 
 
5
  useTheme,
6
  useMediaQuery,
7
  Tooltip,
8
+ CircularProgress,
9
  } from "@mui/material";
10
  import { motion } from "framer-motion";
11
  import { useNavigate } from "react-router-dom";
12
  import { useSoundSystem } from "../contexts/SoundContext";
13
+ import {
14
+ ServiceStatusProvider,
15
+ useServiceStatus,
16
+ } from "../contexts/ServiceStatusContext";
17
  import { BlinkingText } from "../components/BlinkingText";
18
  import { BookPages } from "../components/BookPages";
19
  import { ServiceStatus } from "../components/ServiceStatus";
20
 
21
+ function HomeContent() {
22
  const navigate = useNavigate();
23
  const { playSound } = useSoundSystem();
24
+ const { services, areServicesHealthy } = useServiceStatus();
25
  const theme = useTheme();
26
  const isMobile = useMediaQuery(theme.breakpoints.down("sm"));
27
 
28
+ // Vérifier si les services sont en cours de chargement
29
+ const isLoading = Object.values(services).some(
30
+ (service) => service.status === "loading"
31
+ );
32
+
33
  const handlePlay = () => {
34
  playSound("page");
35
  navigate("/tutorial");
 
41
  size="large"
42
  variant="contained"
43
  onClick={handlePlay}
44
+ disabled={isLoading || !areServicesHealthy()}
45
  sx={{
46
  mt: 4,
47
  fontSize: isMobile ? "1rem" : "1.2rem",
48
  padding: isMobile ? "8px 24px" : "12px 36px",
49
  zIndex: 10,
50
+ minWidth: "120px",
51
+ position: "relative",
52
  }}
53
  >
54
+ <Box
55
+ sx={{
56
+ height: "24px",
57
+ display: "flex",
58
+ alignItems: "center",
59
+ justifyContent: "center",
60
+ visibility: isLoading ? "hidden" : "visible",
61
+ }}
62
+ >
63
+ Play
64
+ </Box>
65
+ {isLoading && (
66
+ <CircularProgress
67
+ size={24}
68
+ sx={{
69
+ color: "inherit",
70
+ position: "absolute",
71
+ top: "50%",
72
+ left: "50%",
73
+ marginTop: "-12px",
74
+ marginLeft: "-12px",
75
+ }}
76
+ />
77
+ )}
78
  </Button>
79
  );
80
 
 
153
  Experience a unique comic book where artificial intelligence brings
154
  your choices to life, shaping the narrative as you explore.
155
  </Typography>
156
+ {isLoading || !areServicesHealthy() ? (
 
 
157
  <Tooltip
158
+ title={
159
+ isLoading
160
+ ? "Checking services availability..."
161
+ : "Services are currently unavailable. Please wait..."
162
+ }
163
  arrow
164
  >
165
  <span>{playButton}</span>
166
  </Tooltip>
167
+ ) : (
168
+ playButton
169
  )}
170
  </Box>
171
  </motion.div>
172
  );
173
  }
174
+
175
+ export function Home() {
176
+ return (
177
+ <ServiceStatusProvider>
178
+ <HomeContent />
179
+ </ServiceStatusProvider>
180
+ );
181
+ }
client/src/pages/Tutorial.jsx CHANGED
@@ -69,8 +69,7 @@ export function Tutorial() {
69
  How to play
70
  </Typography>
71
 
72
- <Typography
73
- variant="body1"
74
  sx={{
75
  zIndex: 10,
76
  textAlign: "center",
@@ -79,22 +78,35 @@ export function Tutorial() {
79
  opacity: 0.8,
80
  color: "white",
81
  px: isMobile ? 3 : 0,
82
- fontSize: "clamp(0.875rem, 2vw, 1.125rem)",
83
- lineHeight: 1.6,
84
  }}
85
  >
86
- Each story takes you on a journey through a unique universe.
87
- <br />
88
- <br />
89
- At every step, you will choose between two different options. until
90
- you reach the end of the story
91
- <br />
 
 
 
92
  <br />
 
 
 
 
 
 
 
 
 
 
 
93
  <Box
94
  sx={{
95
  display: "flex",
96
  gap: { xs: 1, sm: 4 },
97
  justifyContent: "center",
 
98
  mb: { xs: 1, sm: 2 },
99
  alignItems: "center",
100
  flexDirection: { xs: "column", sm: "row" },
@@ -218,7 +230,7 @@ export function Tutorial() {
218
  </Box>
219
  </Box>
220
  </Box>
221
- </Typography>
222
 
223
  <Button
224
  color="primary"
 
69
  How to play
70
  </Typography>
71
 
72
+ <Box
 
73
  sx={{
74
  zIndex: 10,
75
  textAlign: "center",
 
78
  opacity: 0.8,
79
  color: "white",
80
  px: isMobile ? 3 : 0,
 
 
81
  }}
82
  >
83
+ <Typography
84
+ variant="body1"
85
+ sx={{
86
+ fontSize: "clamp(0.875rem, 2vw, 1.125rem)",
87
+ lineHeight: 1.6,
88
+ }}
89
+ >
90
+ Each story takes you on a journey through a unique universe.
91
+ </Typography>
92
  <br />
93
+ <Typography
94
+ variant="body1"
95
+ sx={{
96
+ fontSize: "clamp(0.875rem, 2vw, 1.125rem)",
97
+ lineHeight: 1.6,
98
+ }}
99
+ >
100
+ At every step, you will choose between two different options. until
101
+ you reach the end of the story
102
+ </Typography>
103
+
104
  <Box
105
  sx={{
106
  display: "flex",
107
  gap: { xs: 1, sm: 4 },
108
  justifyContent: "center",
109
+ mt: 4,
110
  mb: { xs: 1, sm: 2 },
111
  alignItems: "center",
112
  flexDirection: { xs: "column", sm: "row" },
 
230
  </Box>
231
  </Box>
232
  </Box>
233
+ </Box>
234
 
235
  <Button
236
  color="primary"