dispatch/client/js/components/App.js

96 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-05-03 07:05:16 +00:00
import React, { Suspense, lazy, useState, useEffect } from 'react';
import Route from 'containers/Route';
2018-11-06 10:13:32 +00:00
import AppInfo from 'components/AppInfo';
import TabList from 'components/TabList';
2018-11-06 10:13:32 +00:00
import cn from 'classnames';
const Modals = lazy(() => import('components/modals'));
const Chat = lazy(() => import('containers/Chat'));
2020-05-16 01:58:17 +00:00
const Connect = lazy(() =>
import(/* webpackChunkName: "connect" */ 'containers/Connect')
);
const Settings = lazy(() => import('containers/Settings'));
const App = ({
connected,
tab,
channels,
2020-06-15 08:58:51 +00:00
networks,
privateChats,
showTabList,
select,
push,
2018-11-06 10:13:32 +00:00
hideMenu,
2019-01-23 06:34:39 +00:00
openModal,
newVersionAvailable,
hasOpenModals
}) => {
const [renderModals, setRenderModals] = useState(false);
if (!renderModals && hasOpenModals) {
setRenderModals(true);
}
2020-05-03 07:05:16 +00:00
const [starting, setStarting] = useState(true);
useEffect(() => {
setTimeout(() => setStarting(false), 1000);
}, []);
2018-11-06 10:13:32 +00:00
const mainClass = cn('main-container', {
'off-canvas': showTabList
});
const handleClick = () => {
2017-05-29 01:02:39 +00:00
if (showTabList) {
hideMenu();
}
};
return (
<div className="wrap" onClick={handleClick}>
2020-05-03 07:05:16 +00:00
{!starting && !connected && (
2018-11-06 10:13:32 +00:00
<AppInfo type="error">
Connection lost, attempting to reconnect...
2018-11-06 10:13:32 +00:00
</AppInfo>
)}
{newVersionAvailable && (
<AppInfo dismissible>
A new version of dispatch just got installed, reload to start using
it!
</AppInfo>
)}
<div className="app-container">
<TabList
tab={tab}
channels={channels}
2020-06-15 08:58:51 +00:00
networks={networks}
privateChats={privateChats}
showTabList={showTabList}
select={select}
push={push}
2019-01-23 06:34:39 +00:00
openModal={openModal}
/>
<div className={mainClass}>
<Suspense fallback={<div className="suspense-fallback">...</div>}>
2018-04-05 23:46:22 +00:00
<Route name="chat">
<Chat />
</Route>
<Route name="connect">
<Connect />
</Route>
<Route name="settings">
<Settings />
</Route>
</Suspense>
2019-01-23 06:34:39 +00:00
<Suspense
fallback={<div className="suspense-modal-fallback">...</div>}
>
{renderModals && <Modals />}
</Suspense>
2017-05-29 01:02:39 +00:00
</div>
</div>
</div>
);
};
export default App;