Skip to content

Commit abf7856

Browse files
committed
games: Sort backups in descending order
1 parent 3abc82c commit abf7856

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/cache/games.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { GamesList } from '@/ps/games/common';
77
export type GameBackup = {
88
room: string;
99
id: string;
10+
at: number;
1011
game: string;
1112
backup: string;
1213
};

src/ps/games/game.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export class BaseGame<State extends BaseState> {
210210
backup(): void {
211211
if (this.meta.players === 'single') return; // Don't back up single-player games
212212
const backup = this.serialize();
213-
gameCache.set({ id: this.id, room: this.roomid, game: this.meta.id, backup });
213+
gameCache.set({ id: this.id, room: this.roomid, game: this.meta.id, backup, at: Date.now() });
214214
}
215215

216216
setTheme(input: string): TranslatedText {

src/ps/games/menus.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export function renderMenu(room: PSRoomTranslated, meta: Meta, isStaff: boolean)
7575
}
7676

7777
export function renderBackups(room: PSRoomTranslated, meta: Meta): ReactElement {
78-
const stashedGames = gameCache.getByGame(room.roomid, meta.id).filter(game => !PSGames[meta.id]?.[game.id]);
78+
const stashedGames = gameCache
79+
.getByGame(room.roomid, meta.id)
80+
.filter(game => !PSGames[meta.id]?.[game.id])
81+
.sortBy(game => game.at, 'desc');
7982
return (
8083
<>
8184
<hr />

0 commit comments

Comments
 (0)