Skip to content

Commit 3dffa66

Browse files
committed
minor improvements to UI loading
1 parent 2148f0f commit 3dffa66

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

src/client/App.tsx

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { Box, Button, CssBaseline, Snackbar } from '@mui/material'
1+
import { Box, Button, CircularProgress, CssBaseline, Snackbar } from '@mui/material'
22
import { ThemeProvider } from '@mui/material/styles'
33
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3'
44
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
55
import { fi } from 'date-fns/locale'
66
import { SnackbarProvider } from 'notistack'
77
import React, { useEffect, useRef } from 'react'
8-
import { Outlet, useLocation, useParams } from 'react-router-dom'
8+
import { Navigate, Outlet, useLocation, useParams } from 'react-router-dom'
99
import { initShibbolethPinger } from 'unfuck-spa-shibboleth-session'
1010
import { PUBLIC_URL } from '../config'
1111
import { Feedback } from './components/Feedback'
12-
import Footer from './components/Footer'
1312
import NavBar from './components/NavBar'
1413
import { AppContext } from './contexts/AppContext'
1514
import { EmbeddedProvider, useIsEmbedded } from './contexts/EmbeddedContext'
@@ -75,23 +74,10 @@ const AdminLoggedInAsBanner = () => {
7574
const App = () => {
7675
useUpdateUrlLang()
7776
const theme = useTheme()
78-
const { courseId } = useParams()
79-
const location = useLocation()
80-
const { user, isLoading } = useCurrentUser()
8177

8278
useEffect(() => {
8379
initShibbolethPinger()
8480
}, [])
85-
const onNoAccessPage = location.pathname.includes('/noaccess')
86-
87-
if (isLoading && !onNoAccessPage) return null
88-
89-
if (!onNoAccessPage && !hasAccess(user, courseId)) {
90-
window.location.href = PUBLIC_URL + getRedirect(user)
91-
return null
92-
}
93-
94-
if (!user && !onNoAccessPage) return null
9581

9682
return (
9783
<ThemeProvider theme={theme}>
@@ -127,7 +113,7 @@ const Layout = () => {
127113
>
128114
{!isEmbedded && <NavBar />}
129115
<Box sx={{ flex: 1 }}>
130-
<Outlet />
116+
<Content />
131117
</Box>
132118
<Feedback />
133119
</Box>
@@ -136,4 +122,26 @@ const Layout = () => {
136122
)
137123
}
138124

125+
const Content = () => {
126+
const { courseId } = useParams()
127+
const location = useLocation()
128+
const { user, isLoading } = useCurrentUser()
129+
130+
const onNoAccessPage = location.pathname.includes('/noaccess')
131+
132+
if (isLoading && !onNoAccessPage) return <CircularProgress sx={{ margin: 'auto' }} />
133+
134+
if (!onNoAccessPage && !hasAccess(user, courseId)) {
135+
return <Navigate to={PUBLIC_URL + getRedirect(user)} />
136+
}
137+
138+
if (!user && !onNoAccessPage) return null
139+
140+
return (
141+
<Box sx={{ flex: 1 }}>
142+
<Outlet />
143+
</Box>
144+
)
145+
}
146+
139147
export default App

src/client/components/Feedback.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import apiClient from '../util/apiClient'
77
import { addJustInTimeFields, useAnalytics } from '../stores/analytics'
88
import type { FeedbackPost } from '../../shared/feedback'
99
import { useSnackbar } from 'notistack'
10-
import { BlueButton, OutlineButtonBlack, OutlineButtonBlue } from './ChatV2/general/Buttons'
10+
import { BlueButton, OutlineButtonBlack } from './ChatV2/general/Buttons'
1111

1212
const useSubmitFeedbackMutation = () => {
1313
const analyticsMetadata = useAnalytics()

src/client/components/NavBar/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ const NavBar = () => {
3737
const isDesktopDevice = useMediaQuery(theme.breakpoints.up('lg'))
3838
const { language } = i18n
3939
const languages = ['fi', 'sv', 'en']
40-
const { user, isLoading } = useCurrentUser()
40+
const { user } = useCurrentUser()
4141
// will be changed to use url to change language and moved up to app since language is global
4242
const handleLanguageChange = (newLanguage: string) => {
4343
i18n.changeLanguage(newLanguage)
4444
}
4545
useEffect(() => {
4646
setNavPanelOpen(false)
4747
}, [isDesktopDevice])
48-
if (isLoading) return null
49-
50-
if (!user) return null
5148

5249
return (
5350
<>
@@ -116,14 +113,16 @@ const NavItems = ({ user, t, languages, handleLanguageChange, language, vertical
116113
const { pathname } = useLocation()
117114
const [openLanguageSelect, setOpenLanguageSelect] = useState(false)
118115

116+
if (!user) return null
117+
119118
return (
120119
<>
121-
{user?.preferences?.chatVersion !== 2 && (
120+
{user.preferences?.chatVersion !== 2 && (
122121
<NavItemButton to="/v2" path="v2/*" current={pathname} icon={<GradeOutlined sx={styles.icon} />} vertical={vertical}>
123122
{t('tryNew')}
124123
</NavItemButton>
125124
)}
126-
{user?.preferences?.chatVersion !== 1 && (
125+
{user.preferences?.chatVersion !== 1 && (
127126
<NavItemButton to="/v1" path="v1/*" current={pathname} icon={<GradeOutlined sx={styles.icon} />} vertical={vertical}>
128127
{t('useOld')}
129128
</NavItemButton>

0 commit comments

Comments
 (0)