Fixed thisPlayerAtom giving different result than playerAtom

This commit is contained in:
Martin Berg Alstad 2023-07-22 19:13:19 +02:00
parent fc5f553042
commit 51bc754ef1
2 changed files with 2 additions and 4 deletions

View File

@ -21,15 +21,13 @@ const NavMenu: FC = () => {
<NavItem to="/">Home</NavItem>
<NavItem to={"/lobby"}>Lobby</NavItem>
{
player === undefined ? /* TODO thisPlayerAtom contains a player object, from sessionStorage */
player === undefined ?
<NavItem className={"mx-2"} to={"/login"}>Login</NavItem>
:
<li className={"mx-2"}>
<button onClick={logout} className={"hover:underline"}>Logout</button>
</li>
}
{/*TODO show signed in user when signed in, otherwise login button*/}
</ul>
</nav>
</header>

View File

@ -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.