diff --git a/client-solid/index.html b/client-solid/index.html index 35ca88f..363220e 100644 --- a/client-solid/index.html +++ b/client-solid/index.html @@ -9,7 +9,7 @@ FrostByteSolid - +
diff --git a/client-solid/src/Root.tsx b/client-solid/src/Root.tsx index 60c0b15..a07f185 100644 --- a/client-solid/src/Root.tsx +++ b/client-solid/src/Root.tsx @@ -1,4 +1,4 @@ -import { createSignal } from "solid-js"; +import { Accessor, createSignal, useContext } from "solid-js"; import { createContext } from "solid-js"; import { Route, Routes, A } from "@solidjs/router"; @@ -6,30 +6,71 @@ import { Route, Routes, A } from "@solidjs/router"; import { createPost, getPosts } from "./api"; import { Post, NewPost } from "./api"; -export const TestContext = createContext("Test123"); +// Representing the state of varoious modals. +// So far we only have one modal, but we can add more later +// by adding more fields to this interface, or maybe an enum +interface ModalContextType { + loginModalOpen: Accessor; + setLoginModalOpen: (value: boolean) => void; +} + +interface LoginContextType { + token: Accessor; + setToken: (value: string) => void; + username: Accessor; + setUsername: (value: string) => void; +} + +// It is unclear to me if this is the idiomatic way to do this in Solid +export const ModalContext = createContext(); +export const LoginContext = createContext(); function Root() { + // All of these are passed into context providers + const [loginModalOpen, setLoginModalOpen] = createSignal(false); + const [token, setToken] = createSignal(""); + const [username, setUsername] = createSignal(""); + + // This may not be the best place to do this. + localStorage.getItem("token") && setToken(localStorage.getItem("token")!); + localStorage.getItem("username") && + setUsername(localStorage.getItem("username")!); + return ( <> - -
- -
- + + +
+ + +
+ +
-
- + + ); } function Navbar() { + let modal_ctx = useContext(ModalContext); + let login_ctx = useContext(LoginContext); return ( ); @@ -54,11 +95,14 @@ function Menu() { function NewPostInputArea() { const [content, setContent] = createSignal(""); + const login_ctx = useContext(LoginContext); + return (