Add clear cache btn in loading screen
authorAjay Bura <32841439+ajbura@users.noreply.github.com>
Sat, 17 Sep 2022 10:18:45 +0000 (15:48 +0530)
committerAjay Bura <32841439+ajbura@users.noreply.github.com>
Sat, 17 Sep 2022 10:18:45 +0000 (15:48 +0530)
src/app/organisms/settings/Settings.jsx
src/app/templates/client/Client.jsx
src/app/templates/client/Client.scss
src/client/action/logout.js [deleted file]
src/client/initMatrix.js
src/client/state/settings.js

index 8baf589c743a658910d7c783ff28d47eadbc2d3e..a0869b6154afa5fcbfb757e11a63918b6c19dde2 100644 (file)
@@ -9,7 +9,6 @@ import {
   toggleSystemTheme, toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents,
   toggleNotifications, toggleNotificationSounds,
 } from '../../../client/action/settings';
-import logout from '../../../client/action/logout';
 import { usePermission } from '../../hooks/usePermission';
 
 import Text from '../../atoms/text/Text';
@@ -239,7 +238,7 @@ function AboutSection() {
             <div className="settings-about__btns">
               <Button onClick={() => window.open('https://github.com/ajbura/cinny')}>Source code</Button>
               <Button onClick={() => window.open('https://cinny.in/#sponsor')}>Support</Button>
-              <Button onClick={() => settings.clearCacheAndReload()} variant="danger">Clear cache & reload</Button>
+              <Button onClick={() => initMatrix.clearCacheAndReload()} variant="danger">Clear cache & reload</Button>
             </div>
           </div>
         </div>
@@ -328,7 +327,7 @@ function Settings() {
   const handleTabChange = (tabItem) => setSelectedTab(tabItem);
   const handleLogout = async () => {
     if (await confirmDialog('Logout', 'Are you sure that you want to logout your session?', 'Logout', 'danger')) {
-      logout();
+      initMatrix.logout();
     }
   };
 
index 8610b62ccdd4642ada1c50639b9c2e1838eb0497..d83845b8b1e503ae63918108aa8cf5a7328a7407 100644 (file)
@@ -7,18 +7,21 @@ import { initRoomListListener } from '../../../client/event/roomList';
 import Text from '../../atoms/text/Text';
 import Spinner from '../../atoms/spinner/Spinner';
 import Navigation from '../../organisms/navigation/Navigation';
+import ContextMenu, { MenuItem } from '../../atoms/context-menu/ContextMenu';
+import IconButton from '../../atoms/button/IconButton';
 import ReusableContextMenu from '../../atoms/context-menu/ReusableContextMenu';
 import Room from '../../organisms/room/Room';
 import Windows from '../../organisms/pw/Windows';
 import Dialogs from '../../organisms/pw/Dialogs';
 import EmojiBoardOpener from '../../organisms/emoji-board/EmojiBoardOpener';
-import logout from '../../../client/action/logout';
 
 import initMatrix from '../../../client/initMatrix';
 import navigation from '../../../client/state/navigation';
 import cons from '../../../client/state/cons';
 import DragDrop from '../../organisms/drag-drop/DragDrop';
 
+import VerticalMenuIC from '../../../../public/res/ic/outlined/vertical-menu.svg';
+
 function Client() {
   const [isLoading, changeLoading] = useState(true);
   const [loadingMsg, setLoadingMsg] = useState('Heating up');
@@ -74,9 +77,20 @@ function Client() {
   if (isLoading) {
     return (
       <div className="loading-display">
-        <button className="loading__logout" onClick={logout} type="button">
-          <Text variant="b3">Logout</Text>
-        </button>
+        <div className="loading__menu">
+          <ContextMenu
+            placement="bottom"
+            content={(
+              <>
+                <MenuItem onClick={() => initMatrix.clearCacheAndReload()}>
+                  Clear cache & reload
+                </MenuItem>
+                <MenuItem onClick={() => initMatrix.logout()}>Logout</MenuItem>
+              </>
+            )}
+            render={(toggle) => <IconButton size="extra-small" onClick={toggle} src={VerticalMenuIC} />}
+          />
+        </div>
         <Spinner />
         <Text className="loading__message" variant="b2">{loadingMsg}</Text>
 
index 67d5dfd5288a643915bb35f8d85ec7d1ed7a5d59..cdb8fcc94d48907683f1a867efb82807ba3f1130 100644 (file)
   position: absolute;
   bottom: var(--sp-normal);
 }
-.loading__logout {
+.loading__menu {
   position: absolute;
-  bottom: var(--sp-extra-tight);
+  top: var(--sp-extra-tight);
   right: var(--sp-extra-tight);
   cursor: pointer;
-  .text {
-    color: var(--tc-link);
+  .context-menu__item .text {
+    margin: 0 !important;
   }
 }
diff --git a/src/client/action/logout.js b/src/client/action/logout.js
deleted file mode 100644 (file)
index c4047bb..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-import initMatrix from '../initMatrix';
-
-async function logout() {
-  const mx = initMatrix.matrixClient;
-  mx.stopClient();
-  try {
-    await mx.logout();
-  } catch {
-    // ignore if failed to logout
-  }
-  mx.clearStores();
-  window.localStorage.clear();
-  window.location.reload();
-}
-
-export default logout;
index fccfe5148b22d9e22b08836f8690cf3dc141c682..cd961573878fc08bd134ed1b2cd7883c6aff5daa 100644 (file)
@@ -98,13 +98,32 @@ class InitMatrix extends EventEmitter {
   }
 
   listenEvents() {
-    this.matrixClient.on('Session.logged_out', () => {
+    this.matrixClient.on('Session.logged_out', async () => {
       this.matrixClient.stopClient();
-      this.matrixClient.clearStores();
+      await this.matrixClient.clearStores();
       window.localStorage.clear();
       window.location.reload();
     });
   }
+
+  async logout() {
+    this.matrixClient.stopClient();
+    try {
+      await this.matrixClient.logout();
+    } catch {
+      // ignore if failed to logout
+    }
+    await this.matrixClient.clearStores();
+    window.localStorage.clear();
+    window.location.reload();
+  }
+
+  clearCacheAndReload() {
+    this.matrixClient.stopClient();
+    this.matrixClient.store.deleteAllData().then(() => {
+      window.location.reload();
+    });
+  }
 }
 
 const initMatrix = new InitMatrix();
index 7b9635d333c7d932e4dc5d31d849e28d59fa67e9..32f55fcc611ed9cec8c0c983d650f44b53e327ed 100644 (file)
@@ -147,14 +147,6 @@ class Settings extends EventEmitter {
     return settings.isNotificationSounds;
   }
 
-  clearCacheAndReload() {
-    const mx = initMatrix.matrixClient;
-    mx.stopClient()
-    mx.store.deleteAllData().then(() => {
-        window.location.reload();
-    });
-}
-
   setter(action) {
     const actions = {
       [cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => {