11"use client" ;
22
3- import React from "react" ;
3+ import React , { useEffect , useState } from "react" ;
44import { CodeSpace } from "./components/CodeSpace" ;
55import { formatTime } from "./utils" ;
66import { GameOverModal } from "./components/GameOverModal" ;
77import { PreviewPane } from "./components/PreviewPane" ;
88import { SparkRushProvider , useSparkRush } from "./SparkRushContext" ;
9+ import Link from "next/link" ;
910
1011const SparkRushGame = ( ) => {
1112 const { gameState, challenge, showTargetFlash, showSuccessOverlay } =
@@ -34,19 +35,21 @@ const SparkRushGame = () => {
3435 { /* countdown overlay */ }
3536 < div
3637 className = { `absolute inset-0 bg-opacity-50 flex items-center justify-center z-50 transition-all duration-500 pointer-events-none ${
37- gameState . timeRemaining <= 5 && ! showSuccessOverlay ? "visible opacity-100" : "invisible opacity-0"
38+ gameState . timeRemaining <= 5 && ! showSuccessOverlay
39+ ? "visible opacity-100"
40+ : "invisible opacity-0"
3841 } flex flex-col gap-8`}
3942 >
4043 < div className = "text-yellow-300 drop-shadow-sm drop-shadow-black text-9xl font-bold " >
4144 { gameState . timeRemaining }
42- </ div >
45+ </ div >
4346 </ div >
4447
4548 { gameState . gameOver && < GameOverModal /> }
4649
4750 { /* Header */ }
4851 < header className = "flex items-center justify-between p-4 border-b border-gray-200" >
49- < h1 className = "text-2xl font-bold" >
52+ < Link href = "/" className = "text-2xl font-bold" >
5053 < span style = { { color : "var(--google-blue)" } } > S</ span >
5154 < span style = { { color : "var(--google-red)" } } > p</ span >
5255 < span style = { { color : "var(--google-yellow)" } } > a</ span >
@@ -57,7 +60,7 @@ const SparkRushGame = () => {
5760 < span style = { { color : "var(--google-yellow)" } } > u</ span >
5861 < span style = { { color : "var(--google-green)" } } > s</ span >
5962 < span style = { { color : "var(--google-blue)" } } > h</ span >
60- </ h1 >
63+ </ Link >
6164 < div className = "flex items-center gap-6" >
6265 < div
6366 className = { `text-2xl font-semibold transition-colors flex items-center gap-2 ${
@@ -108,6 +111,38 @@ const SparkRushGame = () => {
108111} ;
109112
110113export const SparkRush = ( ) => {
114+ const [ countdown , setCountdown ] = useState ( 3 ) ;
115+
116+ useEffect ( ( ) => {
117+ const intervalId = setInterval ( ( ) => {
118+ setCountdown ( ( prev ) => prev - 1 ) ;
119+ } , 1000 ) ;
120+
121+ return ( ) => {
122+ clearInterval ( intervalId ) ;
123+ setCountdown ( 3 ) ;
124+ } ;
125+ } , [ ] ) ;
126+
127+ if ( countdown > 0 ) {
128+ return (
129+ < div className = "flex items-center justify-center h-screen" >
130+ { /* countdown overlay */ }
131+ < div
132+ className = { `absolute inset-0 bg-opacity-50 flex items-center justify-center z-50 transition-all duration-500 pointer-events-none ${
133+ true
134+ ? "visible opacity-100"
135+ : "invisible opacity-0"
136+ } flex flex-col gap-8`}
137+ >
138+ < div className = "text-yellow-300 drop-shadow-sm drop-shadow-black text-9xl font-bold " >
139+ { countdown }
140+ </ div >
141+ </ div >
142+ </ div >
143+ ) ;
144+ }
145+
111146 return (
112147 < SparkRushProvider >
113148 < SparkRushGame />
0 commit comments