feat: added game active page

This commit is contained in:
Lala, Shahd
2026-05-14 23:54:26 +00:00
parent 490e2cb760
commit b48060c6cb
9 changed files with 708 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import { Injectable } from '@angular/core';
const STORAGE_KEY = 'nowchess.games';
const MAX_ENTRIES = 50;
interface GameEntry {
id: string;
addedAt: number;
}
@Injectable({ providedIn: 'root' })
export class GameHistoryService {
recordGame(gameId: string): void {
const entries = this.load().filter((e) => e.id !== gameId);
entries.unshift({ id: gameId, addedAt: Date.now() });
this.save(entries.slice(0, MAX_ENTRIES));
}
getGameIds(): string[] {
return this.load().map((e) => e.id);
}
removeGame(gameId: string): void {
this.save(this.load().filter((e) => e.id !== gameId));
}
private load(): GameEntry[] {
try {
const raw = localStorage.getItem(STORAGE_KEY);
return raw ? (JSON.parse(raw) as GameEntry[]) : [];
} catch {
return [];
}
}
private save(entries: GameEntry[]): void {
localStorage.setItem(STORAGE_KEY, JSON.stringify(entries));
}
}