Enhance winner management with localStorage updates

Refactored winner storage logic by introducing `clearWinnerLS` and replacing outdated functions with `getWinnerLS` and `setWinnerLS`. Added a `WinnerBadge` component to display the winner's status and updated game lifecycle handling to ensure proper winner reset and management.
This commit is contained in:
2026-02-06 10:02:11 +01:00
parent 7024a681da
commit 74de7bf4dd
3 changed files with 88 additions and 23 deletions

View File

@@ -0,0 +1,28 @@
// frontend/src/utils/winnerStorage.js
function winnerKey(gameId) {
return `winner:${gameId}`;
}
export function getWinnerLS(gameId) {
if (!gameId) return "";
try {
return localStorage.getItem(winnerKey(gameId)) || "";
} catch {
return "";
}
}
export function setWinnerLS(gameId, name) {
if (!gameId) return;
try {
localStorage.setItem(winnerKey(gameId), (name || "").trim());
} catch {}
}
export function clearWinnerLS(gameId) {
if (!gameId) return;
try {
localStorage.removeItem(winnerKey(gameId));
} catch {}
}