2019-01-05 06:08:34 +00:00
|
|
|
import React, { Suspense, lazy, useState } from 'react';
|
2017-06-21 06:40:28 +00:00
|
|
|
import Route from 'containers/Route';
|
2018-11-06 10:13:32 +00:00
|
|
|
import AppInfo from 'components/AppInfo';
|
2017-06-21 06:40:28 +00:00
|
|
|
import TabList from 'components/TabList';
|
2018-11-06 10:13:32 +00:00
|
|
|
import cn from 'classnames';
|
2017-05-27 05:30:22 +00:00
|
|
|
|
2019-01-05 06:08:34 +00:00
|
|
|
const Modals = lazy(() => import('components/modals'));
|
2018-11-04 06:22:46 +00:00
|
|
|
const Chat = lazy(() => import('containers/Chat'));
|
|
|
|
const Connect = lazy(() => import('containers/Connect'));
|
|
|
|
const Settings = lazy(() => import('containers/Settings'));
|
|
|
|
|
|
|
|
const App = ({
|
|
|
|
connected,
|
|
|
|
tab,
|
|
|
|
channels,
|
|
|
|
servers,
|
|
|
|
privateChats,
|
|
|
|
showTabList,
|
|
|
|
select,
|
|
|
|
push,
|
2018-11-06 10:13:32 +00:00
|
|
|
hideMenu,
|
2019-01-23 06:34:39 +00:00
|
|
|
openModal,
|
2019-01-05 06:08:34 +00:00
|
|
|
newVersionAvailable,
|
|
|
|
hasOpenModals
|
2018-11-04 06:22:46 +00:00
|
|
|
}) => {
|
2019-01-05 06:08:34 +00:00
|
|
|
const [renderModals, setRenderModals] = useState(false);
|
|
|
|
if (!renderModals && hasOpenModals) {
|
|
|
|
setRenderModals(true);
|
|
|
|
}
|
|
|
|
|
2018-11-06 10:13:32 +00:00
|
|
|
const mainClass = cn('main-container', {
|
2018-11-04 06:22:46 +00:00
|
|
|
'off-canvas': showTabList
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleClick = () => {
|
2017-05-29 01:02:39 +00:00
|
|
|
if (showTabList) {
|
|
|
|
hideMenu();
|
|
|
|
}
|
|
|
|
};
|
2017-05-27 05:30:22 +00:00
|
|
|
|
2018-11-04 06:22:46 +00:00
|
|
|
return (
|
|
|
|
<div className="wrap" onClick={handleClick}>
|
|
|
|
{!connected && (
|
2018-11-06 10:13:32 +00:00
|
|
|
<AppInfo type="error">
|
2018-11-04 06:22:46 +00:00
|
|
|
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>
|
2018-11-04 06:22:46 +00:00
|
|
|
)}
|
|
|
|
<div className="app-container">
|
|
|
|
<TabList
|
|
|
|
tab={tab}
|
|
|
|
channels={channels}
|
|
|
|
servers={servers}
|
|
|
|
privateChats={privateChats}
|
|
|
|
showTabList={showTabList}
|
|
|
|
select={select}
|
|
|
|
push={push}
|
2019-01-23 06:34:39 +00:00
|
|
|
openModal={openModal}
|
2018-11-04 06:22:46 +00:00
|
|
|
/>
|
|
|
|
<div className={mainClass}>
|
2019-01-05 06:08:34 +00:00
|
|
|
<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>
|
2018-11-04 06:22:46 +00:00
|
|
|
</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>
|
2017-05-27 05:30:22 +00:00
|
|
|
</div>
|
2018-11-04 06:22:46 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|