From 5a17badfaee60345f6ce8df6c10c238ab8cffa03 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Tue, 14 Sep 2021 10:10:11 +0530 Subject: [PATCH] Added server disconnection message (#35) --- src/app/organisms/navigation/Drawer.jsx | 21 +++++++++++++++++++++ src/app/organisms/navigation/Drawer.scss | 11 +++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/app/organisms/navigation/Drawer.jsx b/src/app/organisms/navigation/Drawer.jsx index b76347e..5e9d2fb 100644 --- a/src/app/organisms/navigation/Drawer.jsx +++ b/src/app/organisms/navigation/Drawer.jsx @@ -6,6 +6,7 @@ import cons from '../../../client/state/cons'; import navigation from '../../../client/state/navigation'; import { selectTab, selectSpace } from '../../../client/action/navigation'; +import Text from '../../atoms/text/Text'; import ScrollView from '../../atoms/scroll/ScrollView'; import DrawerHeader from './DrawerHeader'; @@ -14,6 +15,7 @@ import Home from './Home'; import Directs from './Directs'; function Drawer() { + const [systemState, setSystemState] = useState(null); const [selectedTab, setSelectedTab] = useState(navigation.selectedTab); const [spaceId, setSpaceId] = useState(navigation.selectedSpaceId); @@ -30,6 +32,13 @@ function Drawer() { else selectSpace(navigation.selectedSpacePath[lRoomIndex - 1]); } + function handleSystemState(state) { + if (state === 'ERROR' || state === 'RECONNECTING' || state === 'STOPPED') { + setSystemState({ status: 'Connection lost!' }); + } + if (systemState !== null) setSystemState(null); + } + useEffect(() => { navigation.on(cons.events.navigation.TAB_SELECTED, onTabSelected); navigation.on(cons.events.navigation.SPACE_SELECTED, onSpaceSelected); @@ -40,6 +49,13 @@ function Drawer() { initMatrix.roomList.removeListener(cons.events.roomList.ROOM_LEAVED, onRoomLeaved); }; }, []); + useEffect(() => { + initMatrix.matrixClient.on('sync', handleSystemState); + return () => { + initMatrix.matrixClient.removeListener('sync', handleSystemState); + }; + }, [systemState]); + return (
@@ -57,6 +73,11 @@ function Drawer() {
+ { systemState !== null && ( +
+ {systemState.status} +
+ )} ); } diff --git a/src/app/organisms/navigation/Drawer.scss b/src/app/organisms/navigation/Drawer.scss index e93761a..c16b974 100644 --- a/src/app/organisms/navigation/Drawer.scss +++ b/src/app/organisms/navigation/Drawer.scss @@ -26,6 +26,17 @@ @extend .drawer-flexItem; @extend .drawer-flexBox; } + + &__state { + padding: var(--sp-extra-tight); + border-top: 1px solid var(--bg-surface-border); + display: flex; + justify-content: center; + + & .text { + color: var(--tc-danger-high); + } + } } .rooms__wrapper { @extend .drawer-flexItem;