twittok/ui/src/App.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-10-22 13:27:48 +00:00
import Test from "./test";
import Cookies from "./cookies/Cookies";
import spinner from "./assets/icons/spinner.svg";
import "./App.css";
import "./thai.css";
import Loader from "./timeline/Entry";
import Modal from "./modals/Modal";
import { useGlobalState } from "./logic/state";
import { useEffect, useState } from "react";
import { useHistory, Router, Route } from "./logic/router";
import { useQueryClient } from "@tanstack/react-query";
import { twatterCookieQ } from "./logic/queries";
2024-10-22 14:45:57 +00:00
import { PROCESS_ID } from "./logic/constants";
2024-10-22 13:27:48 +00:00
function App() {
const [loading, setLoading] = useState(true);
const { init, modal } = useGlobalState();
const qc = useQueryClient();
async function pref() {
await qc.prefetchQuery(twatterCookieQ);
}
useEffect(() => {
2024-10-22 14:45:57 +00:00
init().then((_) => {
2024-10-22 13:27:48 +00:00
setLoading(false);
});
pref();
}, []);
// const { init } = useGlobalState();
2024-10-22 14:45:57 +00:00
if (loading) return <img className="spinner gc" src={spinner} />;
2024-10-22 13:27:48 +00:00
return (
<>
2024-10-22 14:45:57 +00:00
<Router basePath={`/${PROCESS_ID}`}>
2024-10-22 13:27:48 +00:00
<Route path="/" component={Nav} />
<Route path="/cookies" component={Cookies} />
<Route path="/main" component={Loader} />
</Router>
{modal && <Modal>{modal}</Modal>}
</>
);
}
function Nav() {
const { navigate } = useHistory();
return (
<>
<h1>TwitTok</h1>
<a onClick={() => navigate("/cookies")} className="button">
Set Cookies
</a>
<a onClick={() => navigate("/main")} className="button">
Go Browse
</a>
2024-10-22 14:45:57 +00:00
<Test />
2024-10-22 13:27:48 +00:00
</>
);
}
export default App;