Skip to content

Commit 57dc58e

Browse files
committed
feat: codespace bg green flash on success
1 parent 4a93523 commit 57dc58e

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/app/components/CssRush/CssRush.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
4040
return createCodeBlocks(shuffled);
4141
});
4242
const [isClient, setIsClient] = useState(false);
43+
const [showSuccessFlash, setShowSuccessFlash] = useState(false);
4344

4445
// Hooks
4546
const [holdingBlockId, setHoldingBlockId] = useState<string | null>(null);
@@ -102,10 +103,16 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
102103

103104
if (userCode === targetCode) {
104105
setGameState((prev) => ({ ...prev, score: prev.score + 1 }));
105-
const newTarget = getRandomTarget();
106-
setCurrentTarget(newTarget);
107-
const shuffled = shuffleArray(newTarget.blocks);
108-
setCode(createCodeBlocks(shuffled));
106+
setShowSuccessFlash(true);
107+
108+
// Wait 0.5 second before loading next target
109+
setTimeout(() => {
110+
const newTarget = getRandomTarget();
111+
setCurrentTarget(newTarget);
112+
const shuffled = shuffleArray(newTarget.blocks);
113+
setCode(createCodeBlocks(shuffled));
114+
setShowSuccessFlash(false);
115+
}, 500);
109116
}
110117
}, [code, currentTarget]);
111118

@@ -177,6 +184,7 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
177184
code={code}
178185
setDroppableRef={setDroppableRef}
179186
activeId={holdingBlockId}
187+
showSuccessFlash={showSuccessFlash}
180188
/>
181189
</Droppable>
182190
</div>

src/app/components/CssRush/components/CodeSpace.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@ interface CodeSpaceProps {
88
code: CodeBlock[];
99
setDroppableRef: (ref: HTMLDivElement | null) => void;
1010
activeId: string | null;
11+
showSuccessFlash?: boolean;
1112
}
1213

1314
/**
1415
* Code space where blocks are dropped and arranged
1516
*/
16-
export function CodeSpace({ code, setDroppableRef, activeId }: CodeSpaceProps) {
17+
export function CodeSpace({ code, setDroppableRef, activeId, showSuccessFlash }: CodeSpaceProps) {
1718
return (
1819
<div className="flex-1 flex flex-col">
1920
<h3 className="text-sm font-semibold text-slate-300 mb-2 uppercase tracking-wide">
2021
Code Space
2122
</h3>
2223
<div
2324
ref={setDroppableRef}
24-
className="flex-1 p-4 bg-slate-900/30 rounded-lg border border-slate-700 hover:border-slate-600 transition-colors overflow-y-auto overflow-x-hidden max-h-[calc(100vh-250px)]"
25+
className={`flex-1 p-4 rounded-lg border overflow-y-auto overflow-x-hidden max-h-[calc(100vh-250px)] transition-colors duration-500 ${
26+
showSuccessFlash
27+
? 'bg-green-500/40 border-green-400'
28+
: 'bg-slate-900/30 border-slate-700 hover:border-slate-600'
29+
}`}
2530
>
2631
<SortableContext items={code.map(c => c.id)}>
2732
{code.length === 0 ? (

0 commit comments

Comments
 (0)