// 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 {IntlProvider} from 'react-intl' import {DndProvider} from 'react-dnd' import {HTML5Backend} from 'react-dnd-html5-backend' import {TouchBackend} from 'react-dnd-touch-backend' import {getMessages} from './i18n' import {FlashMessages} from './components/flashMessages' import BoardPage from './pages/boardPage' import ChangePasswordPage from './pages/changePasswordPage' import DashboardPage from './pages/dashboardPage' import ErrorPage from './pages/errorPage' import LoginPage from './pages/loginPage' import RegisterPage from './pages/registerPage' import {IUser} from './user' import {Utils} from './utils' import wsClient from './wsclient' import {importNativeAppSettings} from './nativeApp' import {fetchCurrentUser, getCurrentUser} from './store/currentUser' import {getLanguage, fetchLanguage} from './store/language' import {useAppSelector, useAppDispatch} from './store/hooks' const App = React.memo((): JSX.Element => { importNativeAppSettings() const language = useAppSelector(getLanguage) const user = useAppSelector(getCurrentUser) const dispatch = useAppDispatch() const [initialLoad, setInitialLoad] = useState(false) useEffect(() => { dispatch(fetchLanguage()) dispatch(fetchCurrentUser()).then(() => { setInitialLoad(true) }) }, []) useEffect(() => { wsClient.open() return () => { wsClient.close() } }, []) 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