From c1be57b205666bb0082fa36b9e263885e53d5b59 Mon Sep 17 00:00:00 2001 From: Ajay Bura <32841439+ajbura@users.noreply.github.com> Date: Sat, 17 Sep 2022 15:48:45 +0530 Subject: [PATCH] Add clear cache btn in loading screen --- src/app/organisms/settings/Settings.jsx | 5 ++--- src/app/templates/client/Client.jsx | 22 ++++++++++++++++++---- src/app/templates/client/Client.scss | 8 ++++---- src/client/action/logout.js | 16 ---------------- src/client/initMatrix.js | 23 +++++++++++++++++++++-- src/client/state/settings.js | 8 -------- 6 files changed, 45 insertions(+), 37 deletions(-) delete mode 100644 src/client/action/logout.js diff --git a/src/app/organisms/settings/Settings.jsx b/src/app/organisms/settings/Settings.jsx index 8baf589..a0869b6 100644 --- a/src/app/organisms/settings/Settings.jsx +++ b/src/app/organisms/settings/Settings.jsx @@ -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() {
- +
@@ -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(); } }; diff --git a/src/app/templates/client/Client.jsx b/src/app/templates/client/Client.jsx index 8610b62..d83845b 100644 --- a/src/app/templates/client/Client.jsx +++ b/src/app/templates/client/Client.jsx @@ -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 (
- +
+ + initMatrix.clearCacheAndReload()}> + Clear cache & reload + + initMatrix.logout()}>Logout + + )} + render={(toggle) => } + /> +
{loadingMsg} diff --git a/src/app/templates/client/Client.scss b/src/app/templates/client/Client.scss index 67d5dfd..cdb8fcc 100644 --- a/src/app/templates/client/Client.scss +++ b/src/app/templates/client/Client.scss @@ -45,12 +45,12 @@ 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 index c4047bb..0000000 --- a/src/client/action/logout.js +++ /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; diff --git a/src/client/initMatrix.js b/src/client/initMatrix.js index fccfe51..cd96157 100644 --- a/src/client/initMatrix.js +++ b/src/client/initMatrix.js @@ -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(); diff --git a/src/client/state/settings.js b/src/client/state/settings.js index 7b9635d..32f55fc 100644 --- a/src/client/state/settings.js +++ b/src/client/state/settings.js @@ -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]: () => {