From 51bc754ef118b1d2e4ee9cc1ab033b09718f6522 Mon Sep 17 00:00:00 2001
From: Martin Berg Alstad <600878@stud.hvl.no>
Date: Sat, 22 Jul 2023 19:13:19 +0200
Subject: [PATCH] Fixed thisPlayerAtom giving different result than playerAtom
---
pac-man-board-game/ClientApp/src/components/navMenu.tsx | 4 +---
pac-man-board-game/ClientApp/src/utils/state.ts | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/pac-man-board-game/ClientApp/src/components/navMenu.tsx b/pac-man-board-game/ClientApp/src/components/navMenu.tsx
index 86401a9..e453c99 100644
--- a/pac-man-board-game/ClientApp/src/components/navMenu.tsx
+++ b/pac-man-board-game/ClientApp/src/components/navMenu.tsx
@@ -21,15 +21,13 @@ const NavMenu: FC = () => {
HomeLobby
{
- player === undefined ? /* TODO thisPlayerAtom contains a player object, from sessionStorage */
+ player === undefined ?
Login
:
}
-
- {/*TODO show signed in user when signed in, otherwise login button*/}
diff --git a/pac-man-board-game/ClientApp/src/utils/state.ts b/pac-man-board-game/ClientApp/src/utils/state.ts
index 8759547..e6465eb 100644
--- a/pac-man-board-game/ClientApp/src/utils/state.ts
+++ b/pac-man-board-game/ClientApp/src/utils/state.ts
@@ -39,11 +39,11 @@ export const thisPlayerAtom = atom(get => {
}
return atomValue;
}, (get, set, player: Player | undefined) => {
- set(playerAtom, player);
if (player)
sessionStorage.setItem(playerStorage, JSON.stringify(player));
else
sessionStorage.removeItem(playerStorage);
+ set(playerAtom, player);
});
/**
* All dice that have been rolled.