@@ -3,7 +3,7 @@ import { useSettings } from '../contexts/SettingsContext';
33import { useI18n } from '../hooks/useI18n' ;
44import { useSound } from '../hooks/useSound' ;
55import { Home , Download , Upload , Trash2 , Info } from 'lucide-react' ;
6- import { UserProgress } from '../types' ;
6+ import { UserProgress , GameStats } from '../types' ;
77import { MAX_SUB_LEVELS } from '../constants' ;
88
99const 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