feat: refactor achievement listeners

This commit is contained in:
Zamitto 2024-10-07 20:16:12 -03:00
parent f5445b00f4
commit 63aee44982
6 changed files with 45 additions and 18 deletions

View file

@ -132,13 +132,14 @@ export function GameDetailsContextProvider({
setIsLoading(false);
});
window.electron.getGameStats(objectId!, shop as GameShop).then((result) => {
window.electron.getGameStats(objectId, shop as GameShop).then((result) => {
setStats(result);
});
window.electron
.getGameAchievements(objectId!, shop as GameShop)
.getGameAchievements(objectId, shop as GameShop)
.then((achievements) => {
// TODO: race condition
setAchievements(achievements);
})
.catch(() => {
@ -175,14 +176,11 @@ export function GameDetailsContextProvider({
}, [game?.id, isGameRunning, updateGame]);
useEffect(() => {
const unsubscribe = window.electron.onAchievementUnlocked(
(objectId, shop) => {
if (objectId !== objectId || shop !== shop) return;
window.electron
.getGameAchievements(objectId!, shop as GameShop)
.then(setAchievements)
.catch(() => {});
const unsubscribe = window.electron.onUpdateAchievements(
objectId,
shop,
(achievements) => {
setAchievements(achievements);
}
);

View file

@ -76,6 +76,11 @@ declare global {
achievements?: { displayName: string; iconUrl: string }[]
) => void
) => () => Electron.IpcRenderer;
onUpdateAchievements: (
objectId: string,
shop: GameShop,
cb: (achievements: GameAchievement[]) => void
) => () => Electron.IpcRenderer;
/* Library */
addGameToLibrary: (

View file

@ -82,7 +82,6 @@ export function Sidebar() {
>
<span>
<Link to={buildGameAchievementPath()}>Ver todas</Link>
<a></a>
</span>
<div
style={{