Skip to content

Commit

Permalink
rebase fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanmcreynolds committed Aug 23, 2023
1 parent 2303685 commit a96e096
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions web-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {AxiosInterceptor} from './client';
import Container from "@mui/material/Container";
import ErrorBoundary from "./components/error-boundary";
import Login from "./routes/login";
import { Outlet } from "react-router-dom";
import TiledAppBar from "./components/tiled-app-bar";
import { useEffect, useState } from "react";
Expand All @@ -10,10 +11,8 @@ import { SettingsContext, emptySettings } from "./context/settings"
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Suspense, lazy } from "react";
import Skeleton from "@mui/material/Skeleton";

const Browse = lazy(() => import("./routes/browse"));
import UserContext, {userObjectContext} from './context/user';

const Browse = lazy(() => import("./routes/browse"));


function MainContainer() {
Expand All @@ -27,31 +26,28 @@ function MainContainer() {
)
}

// attempt to do user contextg for authentication
const [userContext, setUserContext] = React.useState(userObjectContext)

// Create funtion to update the current context, prioritizing new over old changed properties
const updateContext = (contextUpdates = {}) =>
setUserContext(currentContext => ({ ...currentContext, ...contextUpdates }))
// This is set in vite.config.js. It is the base path of the ui.
const basename = import.meta.env.BASE_URL;

// useEffect prevents the entire context for rerendering when component rerenders
React.useEffect(() => {
if (userContext?.updateUser === userUpdateFunctionTemplate) {
updateContext({ </AxiosInterceptor>
</UserContext.Provider>
updateStatus: (value: string) => updateContext({ status: value }),
})
}
}, [userContext?.updateUser])
function App() {
const [userContext, setUserContext] = React.useState(userObjectContext)
const [user, setUser] = React.useState({user: ""});
const value = { user, setUser };
// Create function to update the current context, prioritizing new over old changed properties
const updateContext = (contextUpdates = {}) =>
setUserContext(currentContext => ({ ...currentContext, ...contextUpdates }))

// end authentication
// useEffect prevents the entire context for rerendering when component rerenders
React.useEffect(() => {

updateContext({
updateStatus: (value: string) => updateContext({ user: value }),
})

}, [])

// This is set in vite.config.js. It is the base path of the ui.
const basename = import.meta.env.BASE_URL;

function App() {

const [settings, setSettings] = useState(emptySettings)
useEffect( () => {
const controller = new AbortController()
Expand All @@ -62,26 +58,16 @@ function App() {
initSettingsContext()
} , []);
return (
<Container>
{/* <UserContext.Provider value={user.user} > */}
<AxiosInterceptor>
<TiledAppBar />
<ErrorBoundary>
<Outlet />
</ErrorBoundary>
</AxiosInterceptor>
{/* </UserContext.Provider> */}
</Container>
);
<UserContext.Provider value={userContext} >
<AxiosInterceptor>
<SettingsContext.Provider value={settings}>
<BrowserRouter basename={basename}>
<ErrorBoundary>
<Suspense fallback={<Skeleton variant="rectangular" />}>
<SettingsContext.Provider value={settings}>
<BrowserRouter basename={basename}>
<ErrorBoundary>
<Suspense fallback={<Skeleton variant="rectangular" />}>
<AxiosInterceptor>
<Routes>
<Route path="/" element={<MainContainer />}>
<Route path="/browse/*" element={<Browse />} />
<Route path="/login" element={<Login/>} />
</Route>
<Route
path="*"
Expand All @@ -92,13 +78,13 @@ function App() {
}
/>
</Routes>
</Suspense>
</ErrorBoundary>
</BrowserRouter>
</SettingsContext.Provider>
</AxiosInterceptor>
</UserContext.Provider>
</AxiosInterceptor>
</Suspense>
</ErrorBoundary>
</BrowserRouter>
</SettingsContext.Provider>
</UserContext.Provider>
)
}

export default App;
export default App;

0 comments on commit a96e096

Please sign in to comment.