Compare commits

..

No commits in common. "df94b151a665fc70a9aac783684a473907369630" and "15c9a64de26fe903d3eca703efbb12c1ec18a59e" have entirely different histories.

6 changed files with 25 additions and 22 deletions

View File

@ -1,5 +1,6 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { apiAuth } from "./api"; import { apiAuth, baseUrl, token } from "./api";
import useAuthContext from "./AuthContext";
//const debounce = <T extends (...args: any[]) => void>( //const debounce = <T extends (...args: any[]) => void>(
// func: T, // func: T,
@ -66,7 +67,8 @@ export default function Analysis() {
setImage(data.image); setImage(data.image);
setLoading(false); setLoading(false);
}).catch((e) => { }).catch((e) => {
console.log("best to just reload... ", e); const { checkAuth } = useAuthContext();
checkAuth();
}) })
} }
@ -87,6 +89,9 @@ export default function Analysis() {
} }
} }
const { user } = useAuthContext()!
console.log(`logged in as ${user.username}`);
return ( return (
<div className="stack column dropdown"> <div className="stack column dropdown">
<button onClick={() => setShowControlPanel(!showControlPanel)}> <button onClick={() => setShowControlPanel(!showControlPanel)}>

View File

@ -19,7 +19,6 @@ body {
} }
footer { footer {
margin-top: 24px;
font-size: x-small; font-size: x-small;
} }
@ -209,10 +208,6 @@ button,
} }
.navbar { .navbar {
span {
padding: 4px;
}
button { button {
font-size: medium; font-size: medium;
margin: 4px 0.5%; margin: 4px 0.5%;

View File

@ -1,10 +1,10 @@
import Analysis from "./Analysis"; import Analysis from "./Analysis";
import "./App.css"; import "./App.css";
import { AuthProvider } from "./AuthContext";
import Footer from "./Footer"; import Footer from "./Footer";
import Header from "./Header"; import Header from "./Header";
import Rankings from "./Rankings"; import Rankings from "./Rankings";
import { BrowserRouter, Routes, Route } from "react-router"; import { BrowserRouter, Routes, Route } from "react-router";
import { SessionProvider } from "./Session";
function App() { function App() {
//const [data, setData] = useState({ nodes: [], links: [] } as SociogramData); //const [data, setData] = useState({ nodes: [], links: [] } as SociogramData);
@ -19,9 +19,9 @@ function App() {
<Routes> <Routes>
<Route index element={<Rankings />} /> <Route index element={<Rankings />} />
<Route path="/analysis" element={ <Route path="/analysis" element={
<SessionProvider> <AuthProvider>
<Analysis /> <Analysis />
</SessionProvider> </AuthProvider>
} /> } />
</Routes> </Routes>
<Footer /> <Footer />

View File

@ -1,13 +1,6 @@
import { Link } from "react-router";
export default function Footer() { export default function Footer() {
return <footer> return <footer>
<div className="navbar"> <p className="grey">
<Link to="/" ><span>Form</span></Link>
<span>|</span>
<Link to="/analysis" ><span>Trainer Analysis</span></Link>
</div>
<p className="grey extra-margin">
something not working? something not working?
<br /> <br />
message <a href="https://t.me/x0124816">me</a>. message <a href="https://t.me/x0124816">me</a>.

View File

@ -334,8 +334,7 @@ export default function Rankings() {
</button> </button>
</div> </div>
<span className="grey">assign as many or as few players as you want<br /> <span className="grey">assign as many or as few players as you want and don't forget to <b>submit</b> (💾) when you're done :)</span>
and don't forget to <b>submit</b> (💾) when you're done :)</span>
<div id="Chemistry" className="tabcontent"> <div id="Chemistry" className="tabcontent">
<Chemistry {...{ user, players }} /> <Chemistry {...{ user, players }} />

View File

@ -1,3 +1,7 @@
import { useContext } from "react";
import useAuthContext from "./AuthContext";
import { createCookie } from "react-router";
export const baseUrl = import.meta.env.VITE_BASE_URL as string; export const baseUrl = import.meta.env.VITE_BASE_URL as string;
export const token = () => localStorage.getItem("access_token") as string; export const token = () => localStorage.getItem("access_token") as string;
@ -86,8 +90,15 @@ export const login = (req: LoginRequest) => {
method: "POST", headers: { method: "POST", headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, body: new URLSearchParams(req).toString() }, body: new URLSearchParams(req).toString()
}).then(resp => resp.json() as Promise<Token>).then(token => token ? localStorage.setItem("access_token", token.access_token) : console.log("token not acquired")).catch((e) => console.log("catch error " + e + " in login")); }).then(resp => resp.json() as unknown as Token).then(token => token ? localStorage.setItem("access_token", token.access_token) : console.log("token not acquired")).catch((e) => console.log("catch error " + e + " in login"));
return Promise<void> }
export const cookielogin = (req: LoginRequest) => {
fetch(`${baseUrl}api/token`, {
method: "POST", headers: {
'Content-Type': 'application/x-www-form-urlencoded',
}, body: new URLSearchParams(req).toString()
}).then(resp => { createCookie(resp.headers.getSetCookie()) }).catch((e) => console.log("catch error " + e + " in login"));
} }
export const logout = () => localStorage.removeItem("access_token"); export const logout = () => localStorage.removeItem("access_token");