Skip to content

Commit 84e1691

Browse files
committed
feat: target preview changed
1 parent 494c962 commit 84e1691

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

src/app/components/CssRush/CssRush.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
4141
});
4242
const [isClient, setIsClient] = useState(false);
4343
const [showSuccessFlash, setShowSuccessFlash] = useState(false);
44+
const [showTargetFlash, setShowTargetFlash] = useState(true);
4445

4546
// Hooks
4647
const [holdingBlockId, setHoldingBlockId] = useState<string | null>(null);
@@ -112,10 +113,21 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
112113
const shuffled = shuffleArray(newTarget.blocks);
113114
setCode(createCodeBlocks(shuffled));
114115
setShowSuccessFlash(false);
116+
setShowTargetFlash(true);
115117
}, 500);
116118
}
117119
}, [code, currentTarget]);
118120

121+
// Flash target at start of each round
122+
useEffect(() => {
123+
if (showTargetFlash) {
124+
const timer = setTimeout(() => {
125+
setShowTargetFlash(false);
126+
}, 1000);
127+
return () => clearTimeout(timer);
128+
}
129+
}, [showTargetFlash]);
130+
119131
// Handlers
120132
const handleDragEnd = (event: any) => {
121133
setHoldingBlockId(null);
@@ -190,7 +202,7 @@ export function CssRush({ gameDurationSeconds = 180 }: GameConfigProps) {
190202
</div>
191203

192204
{/* Right Column */}
193-
<PreviewPane code={code} targetHtml={generateTargetHtml(currentTarget.blocks)} />
205+
<PreviewPane code={code} targetHtml={generateTargetHtml(currentTarget.blocks)} showTargetFlash={showTargetFlash} />
194206
</div>
195207
</div>
196208

src/app/components/CssRush/components/PreviewPane.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,41 @@ import { CodeBlock } from '../types';
44
interface PreviewPaneProps {
55
code: CodeBlock[];
66
targetHtml: string;
7+
showTargetFlash?: boolean;
78
}
89

910
/**
1011
* Preview pane showing user code and target design
1112
*/
12-
export function PreviewPane({ code, targetHtml }: PreviewPaneProps) {
13+
export function PreviewPane({ code, targetHtml, showTargetFlash }: PreviewPaneProps) {
1314
const [showTarget, setShowTarget] = useState(false);
15+
const displayTarget = showTarget || showTargetFlash;
1416

1517
const userCode = code.map((c) => c.content).join('');
1618
const userHtml =
1719
code.length === 0
18-
? '<html><body style="margin:0;padding:0;"></body></html>'
19-
: `<html><body style="margin:0;padding:0;">${userCode}</body></html>`;
20+
? '<html><body style="margin:0;padding:1rem;"></body></html>'
21+
: `<html><body style="margin:0;padding:1rem;">${userCode}</body></html>`;
2022

2123
return (
22-
<div className="flex flex-col bg-slate-900/40 backdrop-blur rounded-lg p-6 border border-slate-800">
23-
<h3 className="text-sm font-semibold text-slate-300 mb-3 uppercase tracking-wide">
24-
{showTarget ? '🎯 Target Design' : '👁 Your Rendered Code'}
24+
<div className={`flex flex-col backdrop-blur rounded-lg p-6 border h-full transition-colors ${
25+
displayTarget ? 'bg-yellow-400/20 border-yellow-400/30' : 'bg-slate-900/40 border-slate-800'
26+
}`}>
27+
<h3 className="text-sm font-semibold text-slate-300 mb-4 uppercase tracking-wide">
28+
{displayTarget ? 'Target Design' : 'Your Output'}
2529
</h3>
2630

2731
<div
2832
onMouseEnter={() => setShowTarget(true)}
2933
onMouseLeave={() => setShowTarget(false)}
30-
className="flex-1 relative rounded-lg overflow-hidden border border-slate-700 bg-white"
34+
className="flex-1 relative rounded-lg overflow-hidden border border-slate-700 bg-white p-4"
3135
>
3236
<iframe
3337
key="user"
3438
title="User Output"
3539
srcDoc={userHtml}
3640
className={`absolute inset-0 w-full h-full transition-opacity ${
37-
showTarget ? 'opacity-0 pointer-events-none' : 'opacity-100'
41+
displayTarget ? 'opacity-0 pointer-events-none' : 'opacity-100'
3842
}`}
3943
/>
4044

@@ -43,7 +47,7 @@ export function PreviewPane({ code, targetHtml }: PreviewPaneProps) {
4347
title="Target Output"
4448
srcDoc={targetHtml}
4549
className={`absolute inset-0 w-full h-full transition-opacity ${
46-
showTarget ? 'opacity-100' : 'opacity-0 pointer-events-none'
50+
displayTarget ? 'opacity-100' : 'opacity-0 pointer-events-none'
4751
}`}
4852
/>
4953
</div>

src/app/components/targets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface Target {
88
*/
99
export function generateTargetHtml(blocks: string[]): string {
1010
const code = blocks.join('');
11-
return `<html><body style="margin:0;padding:0;">${code}</body></html>`;
11+
return `<html><body style="margin:0;padding:1rem;">${code}</body></html>`;
1212
}
1313

1414
export const targets: Target[] = [

0 commit comments

Comments
 (0)