-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
122 lines (103 loc) · 3.36 KB
/
Copy pathApp.tsx
File metadata and controls
122 lines (103 loc) · 3.36 KB
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
112
113
114
115
116
117
118
119
120
121
122
import { Switch, Route } from "wouter";
import { useEffect, useState, useRef } from "react";
import { queryClient } from "./lib/queryClient";
import { QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "@/components/ui/toaster";
import { TooltipProvider } from "@/components/ui/tooltip";
import Loader from "@/pages/Loader";
import NotFound from "@/pages/not-found";
import Home from "@/pages/Home";
import SportsList from "@/pages/SportsList";
import SportDetails from "@/pages/SportDetails";
import Rules from "@/pages/Rules";
import AdminDashboard from "@/pages/Admin";
import Staff from "@/pages/Staff";
import GCPoints from "@/pages/GCPoints";
// Import the new Navigation Component
import { BottomNav } from "@/components/Navigation";
// Import SSE Listener
import { LiveScoreListener } from "@/components/LiveScoreListener";
// Import music
import backgroundMusic from "./assets/music.mp3";
function Router() {
return (
<Switch>
<Route path="/" component={Home} />
<Route path="/sports" component={SportsList} />
<Route path="/sports/:id" component={SportDetails} />
<Route path="/gc-points" component={GCPoints} />
<Route path="/staff" component={Staff} />
<Route path="/rules" component={Rules} />
<Route path="/admin" component={AdminDashboard} />
<Route component={NotFound} />
</Switch>
);
}
function App() {
const [loading, setLoading] = useState(true);
const audioRef = useRef<HTMLAudioElement>(null);
// 1. Loader Timer
useEffect(() => {
const timer = setTimeout(() => {
setLoading(false);
}, 8000);
return () => clearTimeout(timer);
}, []);
// 2. Music Logic
useEffect(() => {
if (loading) return;
const playMusic = () => {
if (audioRef.current) {
audioRef.current.volume = 0.5;
const playPromise = audioRef.current.play();
if (playPromise !== undefined) {
playPromise
.then(() => {
console.log("🎵 Music started successfully!");
window.removeEventListener("click", playMusic);
window.removeEventListener("keydown", playMusic);
window.removeEventListener("touchstart", playMusic);
})
.catch((error) => {
console.log("⚠️ Autoplay blocked. Waiting for user to click Home page.");
});
}
}
};
playMusic();
window.addEventListener("click", playMusic);
window.addEventListener("keydown", playMusic);
window.addEventListener("touchstart", playMusic);
return () => {
window.removeEventListener("click", playMusic);
window.removeEventListener("keydown", playMusic);
window.removeEventListener("touchstart", playMusic);
};
}, [loading]);
return (
<QueryClientProvider client={queryClient}>
<TooltipProvider>
<Toaster />
<LiveScoreListener />
{/* Music Player */}
<audio
ref={audioRef}
src={backgroundMusic}
loop
hidden
/>
{loading ? (
<Loader />
) : (
<>
{/* Render Router for page content */}
<Router />
{/* Render BottomNav on top of content */}
<BottomNav />
</>
)}
</TooltipProvider>
</QueryClientProvider>
);
}
export default App;