Skip to content

Commit 30d14ab

Browse files
committed
fix bug
1 parent 490a03d commit 30d14ab

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

components/Statistics.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const Statistics: React.FC<StatisticsProps> = ({ stages, progress, onBack }) =>
7676
const errorCountByChar = progress.errorCountByChar ?? {};
7777
const topErrorChars = useMemo(() => {
7878
return Object.entries(errorCountByChar)
79-
.sort((a, b) => b[1] - a[1])
79+
.sort((a, b) => Number(b[1]) - Number(a[1]))
8080
.slice(0, 10);
8181
}, [errorCountByChar]);
8282

pages/Settings.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useSettings } from '../contexts/SettingsContext';
33
import { useI18n } from '../hooks/useI18n';
44
import { useSound } from '../hooks/useSound';
55
import { Home, Download, Upload, Trash2, Info } from 'lucide-react';
6-
import { UserProgress } from '../types';
6+
import { UserProgress, GameStats } from '../types';
77
import { MAX_SUB_LEVELS } from '../constants';
88

99
const PROGRESS_STORAGE_KEY = 'tippsy_progress';
@@ -24,7 +24,13 @@ function parseProgressJson(raw: unknown): UserProgress | null {
2424
const averageWpm = typeof st.averageWpm === 'number' ? st.averageWpm : 0;
2525
const averageAccuracy = typeof st.averageAccuracy === 'number' ? st.averageAccuracy : 0;
2626
const stats = { totalCharsTyped, totalTimePlayed, gamesPlayed, highestWpm, averageWpm, averageAccuracy };
27-
const lastSessionByKey = p.lastSessionByKey && typeof p.lastSessionByKey === 'object' ? (p.lastSessionByKey as Record<string, unknown>) : {};
27+
const rawLastSessionByKey = p.lastSessionByKey && typeof p.lastSessionByKey === 'object' ? (p.lastSessionByKey as Record<string, unknown>) : {};
28+
const lastSessionByKey: Record<string, GameStats> = {};
29+
for (const [k, v] of Object.entries(rawLastSessionByKey)) {
30+
if (v && typeof v === 'object' && typeof (v as GameStats).wpm === 'number' && typeof (v as GameStats).accuracy === 'number' && typeof (v as GameStats).errors === 'number' && typeof (v as GameStats).totalChars === 'number' && typeof (v as GameStats).timeElapsed === 'number') {
31+
lastSessionByKey[k] = v as GameStats;
32+
}
33+
}
2834
const sessionHistory = Array.isArray(p.sessionHistory) ? p.sessionHistory : [];
2935
const perStageBest = p.perStageBest && typeof p.perStageBest === 'object' ? (p.perStageBest as Record<string, unknown>) : {};
3036
const errorCountByChar = p.errorCountByChar && typeof p.errorCountByChar === 'object' ? (p.errorCountByChar as Record<string, number>) : {};

0 commit comments

Comments
 (0)