Skip to content

Commit

Permalink
Merge pull request #33 from hcp-uw/hash-router
Browse files Browse the repository at this point in the history
hash router!!!
  • Loading branch information
elimelt authored Aug 6, 2024
2 parents 9bb82d5 + b892ce6 commit a5dc7f4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 98 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ dist
/starter-frontend/public/tinymce

# Account key
serviceAccountKey.json
serviceAccountKey.json

*build*
2 changes: 1 addition & 1 deletion starter-frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "green-notes",
"homepage": "https://hcp-uw.github.io/green-notes",
"homepage": "https://hcp-uw.github.io/",
"version": "0.1.0",
"private": true,
"dependencies": {
Expand Down
52 changes: 26 additions & 26 deletions starter-frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import './App.css';
import { useEffect, useState } from 'react';
import axios from 'axios';
import { Routes, Route } from 'react-router-dom';
import Navbar from './components/navbar/Navbar';
import { Outlet } from 'react-router-dom';
import { AuthProvider } from "./contexts/AuthContext";
import ErrorMessage from "./components/auth/ErrorMessage"


const baseURL: string = 'http://localhost:3001';
import ErrorMessage from "./components/auth/ErrorMessage";
import ErrorPage from "./pages/error-page/error-page";
import AboutUs from './pages/about-us/about-us';
import Collaboration from './pages/collaboration/collaboration';
import HomeScreen from './pages/home/Home';
import { Note } from './pages/editor/editor';
import { Notes } from './pages/notes/notes';
import Profile from './pages/profile/profile';
import Login from './pages/auth-pages/login';
import Register from './pages/auth-pages/register';
import NewProfile from './pages/edit-profile/EditProfile';
import PrivateRoute from './components/auth/PrivateRoute';

function App(): JSX.Element {
const [message, setMessage] = useState('');

// useEffect(() => {
// axios.get(`${baseURL}/hello`)
// .then(res => {
// setMessage(res.data);
// })
// .catch(error => {
// console.error('error fetching data: ', error);
// });
// }, []);

// console.log(message);
return (
<>
{/* wrapped everything in AuthProvider so
everything has access to authentication context */}
<AuthProvider>
<Navbar />
<Outlet />
<Routes>
<Route path="/" element={<HomeScreen />} />
<Route path="/about-us" element={<AboutUs />} />
<Route path="/collaboration" element={<PrivateRoute><Collaboration /></PrivateRoute>} />
<Route path="/note" element={<PrivateRoute><Note /></PrivateRoute>} />
<Route path="/notes" element={<PrivateRoute><Notes /></PrivateRoute>} />
<Route path="/profile" element={<PrivateRoute><Profile /></PrivateRoute>} />
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
<Route path="/new-profile" element={<PrivateRoute><NewProfile /></PrivateRoute>} />
<Route path="*" element={<ErrorPage />} />
</Routes>
<ErrorMessage />
</AuthProvider>
</>
);
}

export default App;
export default App;
75 changes: 5 additions & 70 deletions starter-frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { HashRouter } from 'react-router-dom';
import App from './App';
import {
createBrowserRouter,
RouterProvider,
} from "react-router-dom";
import ErrorPage from "./pages/error-page/error-page";
// import "./App.css";
import AboutUs from './pages/about-us/about-us';
import Collaboration from './pages/collaboration/collaboration'
import HomeScreen from './pages/home/Home';
import { Note } from './pages/editor/editor';
import { Notes } from './pages/notes/notes';
import Profile from './pages/profile/profile';
import Login from './pages/auth-pages/login';
import Register from './pages/auth-pages/register';
import NewProfile from'./pages/edit-profile/EditProfile';
import PrivateRoute from './components/auth/PrivateRoute';

// Private route element redirects people to login first
// No real authentication yet, any fake email and password will do
const router = createBrowserRouter([
{
path: "/",
element: <App />,
errorElement: <ErrorPage />,
children: [
{ index: true, element: <HomeScreen />},
{
path: "about-us",
element: <AboutUs />,
},
{
path: "collaboration",
element: <PrivateRoute><Collaboration /></PrivateRoute>,
},
{
path: "note",
// Later change to
// path: "note/:noteId",
element: <PrivateRoute><Note /></PrivateRoute>,
},
{
//Later change to
//path: "notes/:folderId",
path: "notes",
element: <PrivateRoute><Notes /></PrivateRoute>,
},
{
path: "profile",
// Later change to
// path: "profile/:profileId",
element: <PrivateRoute><Profile /></PrivateRoute>,
},
{
path: "login",
element: <Login />
},
{
path: "register",
element: <Register />
},
{
path: "new-profile",
element: <PrivateRoute><NewProfile /></PrivateRoute>
},


]
},
]);

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<RouterProvider router={router} />
<HashRouter>
<App />
</HashRouter>
</React.StrictMode>
);
);

0 comments on commit a5dc7f4

Please sign in to comment.