Skip to content

Commit 3ba7dcb

Browse files
feat: overhaul puzzle log
1 parent 47150c6 commit 3ba7dcb

2 files changed

Lines changed: 101 additions & 27 deletions

File tree

src/components/Training/PuzzleLog.tsx

Lines changed: 91 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,98 @@ export const PuzzleLog: React.FC<Props> = ({
1515
setCurrentIndex,
1616
}: Props) => {
1717
return (
18-
<div className="flex flex-row flex-wrap items-start justify-start gap-1 overflow-y-auto">
19-
{previousGameResults.map((game, index) => (
20-
<button
21-
key={game.id}
22-
onClick={() => setCurrentIndex(index)}
23-
className={`${game.result ? 'bg-engine-4' : game.result === undefined ? 'bg-button-secondary' : 'bg-human-4'} flex h-10 w-10 cursor-pointer flex-col items-center justify-center rounded-sm`}
24-
>
25-
{game.ratingDiff ? (
26-
<>
27-
<i
28-
className={`material-symbols-outlined -mt-1 ${game.ratingDiff >= 0 ? 'text-blue-200' : 'text-red-300'}`}
29-
>
30-
{game.ratingDiff >= 0 ? 'arrow_drop_up' : 'arrow_drop_down'}
31-
</i>
32-
<p
33-
className={`-mt-2 text-xs tracking-widest ${game.ratingDiff >= 0 ? 'text-blue-200' : 'text-red-300'}`}
18+
<div className="flex h-full flex-col overflow-hidden rounded bg-background-1">
19+
<div className="border-b border-white border-opacity-10 px-3 py-2">
20+
<h3 className="text-sm font-medium text-primary">Puzzle History</h3>
21+
</div>
22+
<div className="red-scrollbar flex flex-1 flex-col overflow-y-auto">
23+
{previousGameResults.length === 0 ? (
24+
<div className="flex flex-1 items-center justify-center p-4">
25+
<p className="text-xs text-secondary">No puzzles completed yet</p>
26+
</div>
27+
) : (
28+
previousGameResults.map((game, index) => {
29+
const isCurrentPuzzle = index === previousGameResults.length - 1
30+
const getStatusInfo = () => {
31+
if (game.result === true) {
32+
return {
33+
label: 'Correct',
34+
color: 'text-green-400',
35+
bgColor: 'bg-green-900/20 hover:bg-green-900/30',
36+
}
37+
} else if (game.result === false) {
38+
return {
39+
label: 'Incorrect',
40+
color: 'text-red-400',
41+
bgColor: 'bg-red-900/20 hover:bg-red-900/30',
42+
}
43+
} else {
44+
return {
45+
label: isCurrentPuzzle ? 'Current' : 'In Progress',
46+
color: 'text-secondary',
47+
bgColor: 'bg-blue-900/20 hover:bg-blue-900/30',
48+
}
49+
}
50+
}
51+
52+
const statusInfo = getStatusInfo()
53+
const puzzleNumber = index + 1
54+
55+
return (
56+
<button
57+
key={game.id}
58+
onClick={() => setCurrentIndex(index)}
59+
className={`group flex w-full cursor-pointer items-center gap-2 border-b border-white/5 px-3 py-2 text-left transition-colors ${
60+
isCurrentPuzzle
61+
? 'bg-background-2 font-medium'
62+
: `${statusInfo.bgColor} hover:bg-background-2`
63+
}`}
3464
>
35-
{game.ratingDiff >= 0 && '+'}
36-
{game.ratingDiff}
37-
</p>
38-
</>
39-
) : (
40-
<></>
41-
)}
42-
</button>
43-
))}
65+
<div className="flex min-w-0 flex-1 flex-col">
66+
<div className="flex items-center justify-between">
67+
<p className="truncate text-xs font-medium text-primary">
68+
Puzzle #{puzzleNumber}
69+
</p>
70+
<span className={`text-xs font-medium ${statusInfo.color}`}>
71+
{statusInfo.label}
72+
</span>
73+
</div>
74+
<div className="flex items-center justify-between">
75+
<p className="text-xs text-secondary">
76+
Puzzle Rating: {game.puzzle_elo}
77+
</p>
78+
{game.ratingDiff !== undefined && (
79+
<div className="flex items-center">
80+
<span
81+
className={`material-symbols-outlined text-sm ${
82+
game.ratingDiff >= 0
83+
? 'text-green-400'
84+
: 'text-red-400'
85+
}`}
86+
>
87+
{game.ratingDiff >= 0
88+
? 'arrow_drop_up'
89+
: 'arrow_drop_down'}
90+
</span>
91+
<span
92+
className={`text-xs font-medium ${
93+
game.ratingDiff >= 0
94+
? 'text-green-400'
95+
: 'text-red-400'
96+
}`}
97+
>
98+
{game.ratingDiff >= 0 ? '+' : ''}
99+
{game.ratingDiff}
100+
</span>
101+
</div>
102+
)}
103+
</div>
104+
</div>
105+
</button>
106+
)
107+
})
108+
)}
109+
</div>
44110
</div>
45111
)
46112
}

src/pages/train.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,19 @@ const TrainPage: NextPage = () => {
102102

103103
useEffect(() => {
104104
if (currentIndex == trainingGames.length - 1) {
105-
setStatus('default')
105+
// For the current puzzle, only set to 'default' if it hasn't been completed yet
106+
const currentPuzzleResult = previousGameResults[currentIndex]
107+
if (currentPuzzleResult?.result !== undefined) {
108+
// Puzzle was completed - preserve the correct status
109+
setStatus(currentPuzzleResult.result ? 'correct' : 'forfeit')
110+
} else {
111+
// Puzzle not completed yet - set to default
112+
setStatus('default')
113+
}
106114
} else {
107115
setStatus('archived')
108116
}
109-
}, [currentIndex])
117+
}, [currentIndex, previousGameResults])
110118

111119
const logGuess = useCallback(
112120
async (

0 commit comments

Comments
 (0)