// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React, {useState, useEffect} from 'react' import { BrowserRouter as Router, Redirect, Route, Switch, } from 'react-router-dom' import {FlashMessages} from './components/flashMessages' import {getCurrentLanguage, 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} from './user' import {Utils} from './utils' import CombinedProviders from './combinedProviders' import {importNativeAppSettings} from './nativeApp' const App = React.memo((): JSX.Element => { importNativeAppSettings() 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 && } { if (initialLoad && !user) { let redirectUrl = '/' + Utils.buildURL(`/workspace/${match.params.workspaceId}/`) if (redirectUrl.indexOf('//') === 0) { redirectUrl = redirectUrl.slice(1) } const loginUrl = `/login?r=${encodeURIComponent(redirectUrl)}` return } return ( ) }} /> {initialLoad && !user && }
) }) export default App