diff --git a/client-solid/src/GlobalState.tsx b/client-solid/src/GlobalState.tsx index 4cb3476..0929729 100644 --- a/client-solid/src/GlobalState.tsx +++ b/client-solid/src/GlobalState.tsx @@ -20,7 +20,6 @@ interface LoginContextType { username: Accessor; setUsername: (value: string) => void; loggedIn: () => boolean; - logOut: () => void; } // It is unclear to me if this is the idiomatic way to do this in Solid @@ -46,18 +45,11 @@ export function GlobalStateProvider(props: { return token() != "" && username() != ""; } - function logOut(): void { - localStorage.removeItem("token"); - localStorage.removeItem("username"); - setToken(""); - setUsername(""); - } - return ( <> {props.children} diff --git a/client-solid/src/Icons.tsx b/client-solid/src/Icons.tsx index be7549b..b7195da 100644 --- a/client-solid/src/Icons.tsx +++ b/client-solid/src/Icons.tsx @@ -115,40 +115,3 @@ export function Home(): JSXElement { ); } - -export function ThumbUp(): JSXElement { - return ( - - - - ); -} -export function ThumbDown(): JSXElement { - return ( - - - - ); -} diff --git a/client-solid/src/Navbar.tsx b/client-solid/src/Navbar.tsx index fed39b0..2803a87 100644 --- a/client-solid/src/Navbar.tsx +++ b/client-solid/src/Navbar.tsx @@ -17,34 +17,41 @@ function MenuItem(props: { href: string; children: JSXElement }): JSXElement { // Represents the menu bar at the top of the page function Menu(): JSXElement { - const login_ctx = useContext(LoginContext)!; + const login_ctx = useContext(LoginContext); return ( - - ); } export function Navbar(): JSXElement { - const modal_ctx = useContext(ModalContext)!; - const login_ctx = useContext(LoginContext)!; + const modal_ctx = useContext(ModalContext); + const login_ctx = useContext(LoginContext); + + const logout = (): void => { + localStorage.removeItem("token"); + localStorage.removeItem("username"); + login_ctx?.setToken(""); + login_ctx?.setUsername(""); + }; const clickHandler = (): void => { - if (login_ctx.loggedIn()) login_ctx.logOut(); - else modal_ctx.setLoginModalOpen(true); + if (login_ctx?.token() != "") logout(); + else modal_ctx?.setLoginModalOpen(true); }; return (