summaryrefslogtreecommitdiffhomepage
path: root/src/routes/index.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/index.tsx')
-rw-r--r--src/routes/index.tsx40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/routes/index.tsx b/src/routes/index.tsx
new file mode 100644
index 0000000..9a5f11b
--- /dev/null
+++ b/src/routes/index.tsx
@@ -0,0 +1,40 @@
+import { useState, useEffect } from "react";
+import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
+import Home from "../components/Home";
+import Blogs from "../components/Blogs";
+import Games from "../components/Games";
+import UploadGame from "../components/UploadGame";
+import Game from "../components/Game";
+import Layout from "../components/Layout";
+
+export default function Index()
+{
+ const [userData, setUserData] = useState({});
+ useEffect(() => {
+ const url = `${import.meta.env.VITE_API_TITLE}/api/v1/auth/data`;
+ fetch(url, {
+ credentials: "include"
+}).then((response) => {
+ if(response.ok) {
+ return response.json();
+ }
+ throw new Error("Network response was not ok.");
+ }).then((response) => setUserData(response.user_data));}, []);
+ // get user data here
+ // then pass it in as 'props' into the components
+ return (<>
+ {/*<h1>{userData.login}</h1>*/}
+ <Router>
+ <Routes>
+ <Route path="/" element = {<Layout userData={userData}/>}>
+ <Route index element={<Home />} />
+ <Route path="/blogs" element={<Blogs />} />
+ <Route path="/games" element={<Games />} />
+ <Route path="/games/upload" element={<UploadGame />} />
+ {/*<Route path="/games/upload" element={<GamesUpload />} />*/}
+ <Route path="/game/:game" element={<Game />} />
+ </Route>
+ </Routes>
+ </Router>
+ </>);
+}