-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ceb96b3
commit 40783cd
Showing
6 changed files
with
151 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {BrowserRouter, Route, Routes} from "react-router"; | ||
import ApiConsole from "./ApiConsole.tsx"; | ||
import Login from "./Login.tsx"; | ||
import {useEffect, useState} from "react"; | ||
import {User} from "./model/user.ts"; | ||
|
||
const App = () => { | ||
const [user, setUser] = useState(null as User); | ||
|
||
useEffect(() => { | ||
const checkUser = () => { | ||
const user = localStorage.getItem("user"); | ||
if(user) { | ||
console.log(user); | ||
setUser(JSON.parse(user)); | ||
console.log("reloaded user", user); | ||
} | ||
} | ||
checkUser(); | ||
}, []); | ||
|
||
const login = (user: User) => { | ||
setUser(user); | ||
} | ||
|
||
const logout = () => { | ||
setUser(null); | ||
localStorage.clear(); | ||
} | ||
|
||
const consoleRoot = user ? <ApiConsole user={user} logout={logout} /> : <Login onLogin={login} /> | ||
|
||
return ( | ||
<BrowserRouter> | ||
<Routes> | ||
<Route index element={consoleRoot} /> | ||
</Routes> | ||
</BrowserRouter> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,14 @@ | ||
import "./index.css"; | ||
import {StrictMode} from "react"; | ||
import {createRoot} from "react-dom/client"; | ||
import ApiConsole from "./ApiConsole.tsx"; | ||
import {ThemeProvider} from "@mui/material"; | ||
import {theme} from "./model/theme.ts"; | ||
import {BrowserRouter, Route, Routes} from "react-router"; | ||
import Login from "./Login.tsx"; | ||
import App from "./App.tsx"; | ||
|
||
createRoot(document.getElementById('root')!).render( | ||
<StrictMode> | ||
<ThemeProvider theme={theme}> | ||
<BrowserRouter> | ||
<Routes> | ||
<Route index element={<ApiConsole />} /> | ||
<Route path="login" element={<Login />} /> | ||
</Routes> | ||
</BrowserRouter> | ||
<App /> | ||
</ThemeProvider> | ||
</StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface User { | ||
email: string; | ||
token: string; | ||
} |