Skip to content

Commit 754945b

Browse files
committed
Restores recent-games persistence for the home page list
1 parent eb3bbc6 commit 754945b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

internal/templates/game.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@
725725
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
726726
const CLIENT_ID_KEY = "tinychess:clientId";
727727
const RECENT_EMOJI_KEY = "tinychess:recentEmojis:v1";
728+
const RECENT_GAMES_KEY = "tinychess:games:v1";
728729

729730
const ACCENTS = ["#6ee7ff", "#a78bfa", "#f472b6", "#f59e0b", "#10b981"];
730731

@@ -795,6 +796,33 @@
795796
} catch {}
796797
}
797798

799+
function saveRecentGame(gameId, st) {
800+
if (!gameId || !st) return;
801+
let map = {};
802+
try {
803+
map = JSON.parse(localStorage.getItem(RECENT_GAMES_KEY) || "{}");
804+
} catch {
805+
map = {};
806+
}
807+
808+
const now = Date.now();
809+
const status = st.status || "";
810+
const match = status.match(/(1-0|0-1|1\/2-1\/2)/);
811+
const result = match ? match[1] : "";
812+
const prev = map[gameId] || {};
813+
814+
map[gameId] = {
815+
id: gameId,
816+
createdAt: prev.createdAt || now,
817+
lastSeen: st.lastSeen || now,
818+
lastSeenLocal: now,
819+
status,
820+
result: result || prev.result || "",
821+
};
822+
823+
saveJSON(RECENT_GAMES_KEY, map);
824+
}
825+
798826
function countsFromFEN(fen) {
799827
const boardOnly = (fen || START_FEN).split(" ")[0] || "";
800828
const c = {
@@ -1041,6 +1069,7 @@
10411069
return;
10421070
}
10431071
if (st.kind !== "state") return;
1072+
saveRecentGame(gameId, st);
10441073

10451074
// client id assignment
10461075
if (!clientId && st.clientId) {

0 commit comments

Comments
 (0)