2020-10-20 21:50:53 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
2021-04-09 19:34:35 +02:00
|
|
|
import React, {useState, useEffect} from 'react'
|
2020-10-09 17:10:26 +02:00
|
|
|
import {
|
2020-10-20 21:50:53 +02:00
|
|
|
BrowserRouter as Router,
|
2020-12-04 16:03:09 +01:00
|
|
|
Redirect,
|
2021-01-21 19:16:40 +01:00
|
|
|
Route,
|
|
|
|
Switch,
|
2020-10-20 21:52:56 +02:00
|
|
|
} from 'react-router-dom'
|
2020-10-09 17:10:26 +02:00
|
|
|
|
2020-10-28 17:56:27 +01:00
|
|
|
import {FlashMessages} from './components/flashMessages'
|
2021-04-12 17:47:47 +02:00
|
|
|
import {getCurrentLanguage, storeLanguage} from './i18n'
|
2021-03-26 19:01:54 +01:00
|
|
|
import {default as client} from './octoClient'
|
2021-01-21 19:16:40 +01:00
|
|
|
import BoardPage from './pages/boardPage'
|
|
|
|
import ChangePasswordPage from './pages/changePasswordPage'
|
2021-03-26 19:01:54 +01:00
|
|
|
import ErrorPage from './pages/errorPage'
|
2020-10-20 21:52:56 +02:00
|
|
|
import LoginPage from './pages/loginPage'
|
2020-12-04 16:03:09 +01:00
|
|
|
import RegisterPage from './pages/registerPage'
|
2021-04-12 17:47:47 +02:00
|
|
|
import {IUser} from './user'
|
2021-04-16 13:42:37 +02:00
|
|
|
import {Utils} from './utils'
|
2021-04-12 17:47:47 +02:00
|
|
|
import CombinedProviders from './combinedProviders'
|
2020-10-09 17:10:26 +02:00
|
|
|
|
2021-04-09 19:34:35 +02:00
|
|
|
const App = React.memo((): JSX.Element => {
|
|
|
|
const [language, setLanguage] = useState(getCurrentLanguage())
|
|
|
|
const [user, setUser] = useState<IUser|undefined>(undefined)
|
|
|
|
const [initialLoad, setInitialLoad] = useState(false)
|
2020-12-07 20:40:16 +01:00
|
|
|
|
2021-04-09 19:34:35 +02:00
|
|
|
useEffect(() => {
|
|
|
|
client.getMe().then((loadedUser?: IUser) => {
|
|
|
|
setUser(loadedUser)
|
|
|
|
setInitialLoad(true)
|
2020-12-07 20:40:16 +01:00
|
|
|
})
|
2021-04-09 19:34:35 +02:00
|
|
|
}, [])
|
2020-12-07 20:40:16 +01:00
|
|
|
|
2021-04-09 19:34:35 +02:00
|
|
|
const setAndStoreLanguage = (lang: string): void => {
|
2020-10-23 13:40:39 +02:00
|
|
|
storeLanguage(lang)
|
2021-04-09 19:34:35 +02:00
|
|
|
setLanguage(lang)
|
2020-12-07 20:40:16 +01:00
|
|
|
}
|
|
|
|
|
2021-04-09 19:34:35 +02:00
|
|
|
return (
|
2021-04-12 17:47:47 +02:00
|
|
|
<CombinedProviders
|
|
|
|
language={language}
|
|
|
|
user={user}
|
|
|
|
setLanguage={setAndStoreLanguage}
|
2021-04-09 19:34:35 +02:00
|
|
|
>
|
2021-04-12 17:47:47 +02:00
|
|
|
<FlashMessages milliseconds={2000}/>
|
2021-04-16 13:42:37 +02:00
|
|
|
<Router
|
|
|
|
forceRefresh={true}
|
|
|
|
basename={Utils.getBaseURL()}
|
|
|
|
>
|
2021-04-12 17:47:47 +02:00
|
|
|
<div id='frame'>
|
|
|
|
<div id='main'>
|
|
|
|
<Switch>
|
|
|
|
<Route path='/error'>
|
|
|
|
<ErrorPage/>
|
|
|
|
</Route>
|
|
|
|
<Route path='/login'>
|
|
|
|
<LoginPage/>
|
|
|
|
</Route>
|
|
|
|
<Route path='/register'>
|
|
|
|
<RegisterPage/>
|
|
|
|
</Route>
|
|
|
|
<Route path='/change_password'>
|
|
|
|
<ChangePasswordPage/>
|
|
|
|
</Route>
|
|
|
|
<Route path='/shared'>
|
2021-04-16 13:42:37 +02:00
|
|
|
<BoardPage readonly={true}/>
|
2021-04-12 17:47:47 +02:00
|
|
|
</Route>
|
|
|
|
<Route path='/board'>
|
|
|
|
{initialLoad && !user && <Redirect to='/login'/>}
|
2021-04-16 13:42:37 +02:00
|
|
|
<BoardPage/>
|
|
|
|
</Route>
|
|
|
|
<Route path='/workspace/:workspaceId/shared'>
|
|
|
|
<BoardPage readonly={true}/>
|
2021-04-12 17:47:47 +02:00
|
|
|
</Route>
|
|
|
|
<Route
|
|
|
|
path='/workspace/:workspaceId/'
|
|
|
|
render={({match}) => {
|
|
|
|
if (initialLoad && !user) {
|
2021-04-16 13:42:37 +02:00
|
|
|
const redirectUrl = '/' + Utils.buildURL(`/workspace/${match.params.workspaceId}/`)
|
2021-04-12 17:47:47 +02:00
|
|
|
const loginUrl = `/login?r=${encodeURIComponent(redirectUrl)}`
|
|
|
|
return <Redirect to={loginUrl}/>
|
|
|
|
}
|
|
|
|
return (
|
2021-04-16 13:42:37 +02:00
|
|
|
<BoardPage/>
|
2021-04-12 17:47:47 +02:00
|
|
|
)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Route path='/'>
|
|
|
|
{initialLoad && !user && <Redirect to='/login'/>}
|
2021-04-16 13:42:37 +02:00
|
|
|
<BoardPage/>
|
2021-04-12 17:47:47 +02:00
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Router>
|
|
|
|
</CombinedProviders>
|
2021-04-09 19:34:35 +02:00
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
export default App
|