// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useState, useEffect} from 'react' import {IntlProvider} from 'react-intl' import { BrowserRouter as Router, Redirect, Route, Switch, } from 'react-router-dom' import {DndProvider} from 'react-dnd' import {HTML5Backend} from 'react-dnd-html5-backend' import {TouchBackend} from 'react-dnd-touch-backend' import {FlashMessages} from './components/flashMessages' import {getCurrentLanguage, getMessages, storeLanguage} from './i18n' import {default as client} from './octoClient' import BoardPage from './pages/boardPage' import ChangePasswordPage from './pages/changePasswordPage' import ErrorPage from './pages/errorPage' import LoginPage from './pages/loginPage' import RegisterPage from './pages/registerPage' import {IUser, UserContext} from './user' import {Utils} from './utils' const App = React.memo((): JSX.Element => { const [language, setLanguage] = useState(getCurrentLanguage()) const [user, setUser] = useState(undefined) const [initialLoad, setInitialLoad] = useState(false) useEffect(() => { client.getMe().then((loadedUser?: IUser) => { setUser(loadedUser) setInitialLoad(true) }) }, []) const setAndStoreLanguage = (lang: string): void => { storeLanguage(lang) setLanguage(lang) } return (
{initialLoad && !user && } { return ( ) }} /> { if (initialLoad && !user) { const redirectUrl = `/workspace/${match.params.workspaceId}/` const loginUrl = `/login?r=${encodeURIComponent(redirectUrl)}` return } return ( ) }} /> {initialLoad && !user && }
) }) export default App