cut out garbage code and wrapped navigation container in appContent css
This commit is contained in:
parent
2442b6d4e2
commit
26595deba6
1 changed files with 28 additions and 31 deletions
|
|
@ -1,16 +1,15 @@
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import reactLogo from '../assets/react.svg'
|
|
||||||
import viteLogo from '/vite.svg'
|
|
||||||
import './App.css'
|
import './App.css'
|
||||||
import { useUserAPI } from '../providers/pond/userAPI'
|
import { useUserAPI } from '../providers/pond/userAPI'
|
||||||
import { useAuth0 } from '@auth0/auth0-react'
|
import { useAuth0 } from '@auth0/auth0-react'
|
||||||
import { or } from '../utils/types'
|
import { or } from '../utils/types'
|
||||||
import LoadingScreen from './LoadingScreen'
|
import LoadingScreen from './LoadingScreen'
|
||||||
// import { pond } from "protobuf-ts/pond";
|
|
||||||
import NavigationContainer from '../navigation/NavigationContainer'
|
import NavigationContainer from '../navigation/NavigationContainer'
|
||||||
import { GlobalState, GlobalStateAction, StateProvider } from '../providers/StateContainer'
|
import { GlobalState, GlobalStateAction, StateProvider } from '../providers/StateContainer'
|
||||||
import { User } from '../models/user'
|
import { User } from '../models/user'
|
||||||
import { Team } from '../models/team'
|
import { Team } from '../models/team'
|
||||||
|
import { makeStyles } from '@mui/styles'
|
||||||
|
import { Theme } from '@mui/material'
|
||||||
|
|
||||||
const reducer = (state: GlobalState, action: GlobalStateAction): GlobalState => {
|
const reducer = (state: GlobalState, action: GlobalStateAction): GlobalState => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -19,6 +18,27 @@ const reducer = (state: GlobalState, action: GlobalStateAction): GlobalState =>
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
|
appContent: {
|
||||||
|
marginTop: 56,
|
||||||
|
marginBottom: 56,
|
||||||
|
marginLeft: "0px",
|
||||||
|
[theme.breakpoints.up("sm")]: {
|
||||||
|
marginTop: 64,
|
||||||
|
marginBottom: 0
|
||||||
|
},
|
||||||
|
[theme.breakpoints.up("md")]: {
|
||||||
|
marginLeft: theme.spacing(9)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
container: {
|
||||||
|
backgroundColor: theme.palette.background.default,
|
||||||
|
},
|
||||||
|
helloMessage: {
|
||||||
|
marginTop: theme.spacing(2),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
const globalDefault = {
|
const globalDefault = {
|
||||||
user: User.create(),
|
user: User.create(),
|
||||||
team: Team.create(),
|
team: Team.create(),
|
||||||
|
|
@ -34,13 +54,11 @@ interface Props {
|
||||||
|
|
||||||
export default function UserWrapper(props: Props) {
|
export default function UserWrapper(props: Props) {
|
||||||
const { toggleTheme } = props;
|
const { toggleTheme } = props;
|
||||||
const [count, setCount] = useState(0)
|
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const userAPI = useUserAPI();
|
const userAPI = useUserAPI();
|
||||||
|
const classes = useStyles();
|
||||||
const useAuth = useAuth0();
|
const useAuth = useAuth0();
|
||||||
const hasFetched = useRef(false);
|
const hasFetched = useRef(false);
|
||||||
// const [user, setUser] = useState<pond.User | undefined>(undefined)
|
|
||||||
// const [message, setMessage] = useState("Loading user profile...")
|
|
||||||
const [global, setGlobal] = useState<undefined | GlobalState>(undefined)
|
const [global, setGlobal] = useState<undefined | GlobalState>(undefined)
|
||||||
|
|
||||||
let user_id = or(useAuth.user?.sub, "")
|
let user_id = or(useAuth.user?.sub, "")
|
||||||
|
|
@ -49,8 +67,6 @@ export default function UserWrapper(props: Props) {
|
||||||
if (hasFetched.current) return;
|
if (hasFetched.current) return;
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
userAPI.getUserWithTeam(user_id).then(resp => {
|
userAPI.getUserWithTeam(user_id).then(resp => {
|
||||||
console.log(resp.data.team)
|
|
||||||
// if (resp.data.user) setUser(resp.data.user)
|
|
||||||
setGlobal({
|
setGlobal({
|
||||||
user: resp.data.user ? User.create(resp.data.user) : User.create(),
|
user: resp.data.user ? User.create(resp.data.user) : User.create(),
|
||||||
team: resp.data.team ? Team.create(resp.data.team) : Team.create(),
|
team: resp.data.team ? Team.create(resp.data.team) : Team.create(),
|
||||||
|
|
@ -59,8 +75,7 @@ export default function UserWrapper(props: Props) {
|
||||||
userTeamPermissions: [],
|
userTeamPermissions: [],
|
||||||
backgroundTasksComplete: false
|
backgroundTasksComplete: false
|
||||||
})
|
})
|
||||||
}).catch(err => {
|
}).catch(() => {
|
||||||
console.log(err.toString())
|
|
||||||
setGlobal(globalDefault)
|
setGlobal(globalDefault)
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
|
@ -80,27 +95,9 @@ export default function UserWrapper(props: Props) {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StateProvider state={global} reducer={reducer}>
|
<StateProvider state={global} reducer={reducer}>
|
||||||
<NavigationContainer toggleTheme={toggleTheme}>
|
<main className={classes.appContent}>
|
||||||
<div>
|
<NavigationContainer toggleTheme={toggleTheme} />
|
||||||
<a href="https://vitejs.dev" target="_blank">
|
</main>
|
||||||
<img src={viteLogo} className="logo" alt="Vite logo" />
|
|
||||||
</a>
|
|
||||||
<a href="https://react.dev" target="_blank">
|
|
||||||
<img src={reactLogo} className="logo react" alt="React logo" />
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<h1>Vite + React</h1>
|
|
||||||
<div className="card">
|
|
||||||
<button onClick={() => setCount((count) => count + 1)}>
|
|
||||||
count is {count}
|
|
||||||
</button>
|
|
||||||
<p>
|
|
||||||
Hello, {global.user.settings?.name}!
|
|
||||||
</p>
|
|
||||||
</div><p className="read-the-docs">
|
|
||||||
Coming soon
|
|
||||||
</p>
|
|
||||||
</NavigationContainer>
|
|
||||||
</StateProvider>
|
</StateProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue