Added server disconnection message (#35)
authorAjay Bura <ajbura@gmail.com>
Tue, 14 Sep 2021 04:40:11 +0000 (10:10 +0530)
committerAjay Bura <ajbura@gmail.com>
Tue, 14 Sep 2021 04:40:11 +0000 (10:10 +0530)
src/app/organisms/navigation/Drawer.jsx
src/app/organisms/navigation/Drawer.scss

index b76347e538090817838e608f39386bd1d9442f58..5e9d2fb4c2ccbb971d24bef0e6f2a98e200651d4 100644 (file)
@@ -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 (
     <div className="drawer">
       <DrawerHeader selectedTab={selectedTab} spaceId={spaceId} />
@@ -57,6 +73,11 @@ function Drawer() {
           </ScrollView>
         </div>
       </div>
+      { systemState !== null && (
+        <div className="drawer__state">
+          <Text>{systemState.status}</Text>
+        </div>
+      )}
     </div>
   );
 }
index e93761a2e97bdcc7d0c30dfd6fe4ea7d08dfa796..c16b9748bc417c55dd43accb69e092dea4af5c40 100644 (file)
     @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;