Skip to content

Commit af1a632

Browse files
authored
release v0.3 (#7)
* fixing sorting logic * saving * refactor: changing code structure * feat: good sorting ui * feat: load actual challenge data * feat: CORE functionality implemented * feat: cleaned the directory * feat: cleaned dir * feat: landing page * Feat/sparkrush UI (#3) * made the light mode on spark rush * feat: score overlay * feat: countdown * Feat/sparkrush UI (#5) * made the light mode on spark rush * feat: score overlay * feat: countdown * feat: start countdown * feat: start countdown
1 parent dc60c79 commit af1a632

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/components/SparkRush/SparkRush.tsx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
"use client";
22

3-
import React from "react";
3+
import React, { useEffect, useState } from "react";
44
import { CodeSpace } from "./components/CodeSpace";
55
import { formatTime } from "./utils";
66
import { GameOverModal } from "./components/GameOverModal";
77
import { PreviewPane } from "./components/PreviewPane";
88
import { SparkRushProvider, useSparkRush } from "./SparkRushContext";
9+
import Link from "next/link";
910

1011
const 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

110113
export 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 />

src/components/SparkRush/SparkRushContext.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ interface SparkRushProviderProps {
4141
export const SparkRushProvider: React.FC<SparkRushProviderProps> = ({
4242
children,
4343
}) => {
44+
45+
const timeRemaining = 90;
4446
const [gameState, setGameState] = useState<GameState>({
45-
timeRemaining: 90,
47+
timeRemaining: timeRemaining,
4648
score: 0,
4749
gameActive: true,
4850
gameOver: false,
@@ -53,7 +55,7 @@ export const SparkRushProvider: React.FC<SparkRushProviderProps> = ({
5355
const resetGame = () => {
5456
setChallenge(loadRandomChallenge());
5557
setGameState({
56-
timeRemaining: 180,
58+
timeRemaining: timeRemaining,
5759
score: 0,
5860
gameActive: true,
5961
gameOver: false,

0 commit comments

Comments
 (0)