feat: popular categories

This commit is contained in:
2024-05-15 15:07:10 +01:00
parent daa687957e
commit 2bc996d981
14 changed files with 237 additions and 29 deletions

View File

@ -14,9 +14,18 @@ export default class GameDatabase {
}
async getGame(id: string) {
const cacheKey = `game:${id}`;
const cached = window.sessionStorage.getItem(cacheKey);
if (cached) {
return JSON.parse(cached) as GameInfo;
}
const rsp = await fetch(`${this.url}/games/${id}`);
if (rsp.ok) {
return (await rsp.json()) as GameInfo | undefined;
const info = (await rsp.json()) as GameInfo | undefined;
if (info) {
window.sessionStorage.setItem(cacheKey, JSON.stringify(info));
}
return info;
}
}
}