Skip to content

Commit

Permalink
Fix issue #403: Combat State not Updating
Browse files Browse the repository at this point in the history
  • Loading branch information
openhands-agent authored and MathiasGruber committed Feb 26, 2025
1 parent 22bf950 commit 9ff2b76
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
23 changes: 10 additions & 13 deletions app/src/layout/PusherHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,25 @@ export const usePusherHandler = (userId?: string | null) => {
if (data?.battleId) {
// NOTE: for some reason using updateUser does not work from this hook
await utils.profile.getUser.cancel();
// Update user data with battle status
utils.profile.getUser.setData(undefined, (old) => {
if (!old) return old;
return {
...old,
userData: {
...old?.userData,
...{
status: "BATTLE",
battleId: data.battleId,
updatedAt: new Date(),
},
...old.userData,
status: "BATTLE",
battleId: data.battleId,
updatedAt: new Date(),
},
} as typeof old;
});
utils.profile.getUser.setData(undefined, (old) => {
return {
...old,
notifications: [
...(old?.notifications || []),
...(old.notifications || []),
{ href: "/combat", name: "In combat", color: "red" },
],
} as typeof old;
};
});
// Invalidate user data to force a refetch
await utils.profile.getUser.invalidate();
router.push("/combat");
}
} else if (data.type === "newInbox") {
Expand Down
3 changes: 2 additions & 1 deletion app/src/libs/combat/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ export const updateUser = async (
curBattle.battleType === "ARENA" ? 1 : 0
}`,
questData: user.questData,
battleId: null,
battleId: result.didWin ? null : curBattle.id,
status: result.didWin ? "AWAKE" : "BATTLE",
regenAt: new Date(),
...(isKageChallenge
? {
Expand Down

0 comments on commit 9ff2b76

Please sign in to comment.