From c2509e860752e23812bb408e331c02c918aadd54 Mon Sep 17 00:00:00 2001 From: André Oliveira <37463445+SpecialAro@users.noreply.github.com> Date: Thu, 4 Aug 2022 00:12:03 +0100 Subject: chore: change values inside mobx actions to fix console warnings (#532) --- src/features/workspaces/store.js | 100 +++++++++++++++++++++++---------------- 1 file changed, 60 insertions(+), 40 deletions(-) (limited to 'src/features/workspaces') diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index a8fb493df..2323019fe 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -90,7 +90,7 @@ export default class WorkspacesStore extends FeatureStore { [workspaceActions.create, this._create], [workspaceActions.delete, this._delete], [workspaceActions.update, this._update], - [workspaceActions.activate, this._setActiveWorkspace], + [workspaceActions.activate, this._setActivateWorkspace], [workspaceActions.deactivate, this._deactivateActiveWorkspace], [ workspaceActions.toggleKeepAllWorkspacesLoadedSetting, @@ -114,10 +114,10 @@ export default class WorkspacesStore extends FeatureStore { } @action reset() { - this.activeWorkspace = null; - this.nextWorkspace = null; + this._setActiveWorkspace(null); + this._setNextWorkspace(null); this.workspaceBeingEdited = null; - this.isSwitchingWorkspace = false; + this._setIsSwitchingWorkspace(false); this.isWorkspaceDrawerOpen = false; } @@ -181,19 +181,31 @@ export default class WorkspacesStore extends FeatureStore { this.stores.router.push('/settings/workspaces'); }; - @action _setActiveWorkspace = ({ workspace }) => { - // Indicate that we are switching to another workspace - this.isSwitchingWorkspace = true; + @action _setNextWorkspace(workspace) { this.nextWorkspace = workspace; + } + + @action _setIsSwitchingWorkspace(bool) { + this.isSwitchingWorkspace = bool; + } + + @action _setActiveWorkspace(workspace) { + this.activeWorkspace = workspace; + } + + @action _setActivateWorkspace = ({ workspace }) => { + // Indicate that we are switching to another workspace + this._setIsSwitchingWorkspace(true); + this._setNextWorkspace(workspace); // Delay switching to next workspace so that the services loading does not drag down UI setTimeout(() => { - this.activeWorkspace = workspace; + this._setActiveWorkspace(workspace); this._updateSettings({ lastActiveWorkspace: workspace.id }); }, 100); // Indicate that we are done switching to the next workspace setTimeout(() => { - this.isSwitchingWorkspace = false; - this.nextWorkspace = null; + this._setIsSwitchingWorkspace(false); + this._setNextWorkspace(null); if (this.stores.settings.app.splitMode) { const serviceNames = new Set( this.getWorkspaceServices(workspace).map(service => service.name), @@ -211,16 +223,16 @@ export default class WorkspacesStore extends FeatureStore { @action _deactivateActiveWorkspace = () => { // Indicate that we are switching to default workspace - this.isSwitchingWorkspace = true; - this.nextWorkspace = null; + this._setIsSwitchingWorkspace(true); + this._setNextWorkspace(null); this._updateSettings({ lastActiveWorkspace: null }); // Delay switching to next workspace so that the services loading does not drag down UI setTimeout(() => { - this.activeWorkspace = null; + this._setActiveWorkspace(null); }, 100); // Indicate that we are done switching to the default workspace setTimeout(() => { - this.isSwitchingWorkspace = false; + this._setIsSwitchingWorkspace(false); if (this.stores.settings.app.splitMode) { for (const wrapper of document.querySelectorAll( '.services__webview-wrapper', @@ -247,6 +259,37 @@ export default class WorkspacesStore extends FeatureStore { await updateWorkspaceRequest.execute(activeWorkspace); }; + @action _setOpenDrawerWithSettings() { + const { router } = this.stores; + const isWorkspaceSettingsRoute = router.location.pathname.includes( + WORKSPACES_ROUTES.ROOT, + ); + const isSwitchingToSettingsRoute = + !this.isSettingsRouteActive && isWorkspaceSettingsRoute; + const isLeavingSettingsRoute = + !isWorkspaceSettingsRoute && this.isSettingsRouteActive; + + if (isSwitchingToSettingsRoute) { + this.isSettingsRouteActive = true; + this._wasDrawerOpenBeforeSettingsRoute = this.isWorkspaceDrawerOpen; + if (!this._wasDrawerOpenBeforeSettingsRoute) { + workspaceActions.toggleWorkspaceDrawer(); + } + } else if (isLeavingSettingsRoute) { + this.isSettingsRouteActive = false; + if ( + !this._wasDrawerOpenBeforeSettingsRoute && + this.isWorkspaceDrawerOpen + ) { + workspaceActions.toggleWorkspaceDrawer(); + } + } + } + + @action _setWorkspaceBeingEdited(match) { + this.workspaceBeingEdited = this._getWorkspaceById(match.id); + } + _toggleKeepAllWorkspacesLoadedSetting = async () => { this._updateSettings({ keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded, @@ -259,7 +302,7 @@ export default class WorkspacesStore extends FeatureStore { const { pathname } = this.stores.router.location; const match = matchRoute('/settings/workspaces/edit/:id', pathname); if (match) { - this.workspaceBeingEdited = this._getWorkspaceById(match.id); + this._setWorkspaceBeingEdited(match); } }; @@ -286,36 +329,13 @@ export default class WorkspacesStore extends FeatureStore { const { lastActiveWorkspace } = this.settings; if (lastActiveWorkspace) { const workspace = this._getWorkspaceById(lastActiveWorkspace); - if (workspace) this._setActiveWorkspace({ workspace }); + if (workspace) this._setActivateWorkspace({ workspace }); } } }; _openDrawerWithSettingsReaction = () => { - const { router } = this.stores; - const isWorkspaceSettingsRoute = router.location.pathname.includes( - WORKSPACES_ROUTES.ROOT, - ); - const isSwitchingToSettingsRoute = - !this.isSettingsRouteActive && isWorkspaceSettingsRoute; - const isLeavingSettingsRoute = - !isWorkspaceSettingsRoute && this.isSettingsRouteActive; - - if (isSwitchingToSettingsRoute) { - this.isSettingsRouteActive = true; - this._wasDrawerOpenBeforeSettingsRoute = this.isWorkspaceDrawerOpen; - if (!this._wasDrawerOpenBeforeSettingsRoute) { - workspaceActions.toggleWorkspaceDrawer(); - } - } else if (isLeavingSettingsRoute) { - this.isSettingsRouteActive = false; - if ( - !this._wasDrawerOpenBeforeSettingsRoute && - this.isWorkspaceDrawerOpen - ) { - workspaceActions.toggleWorkspaceDrawer(); - } - } + this._setOpenDrawerWithSettings(); }; _cleanupInvalidServiceReferences = () => { -- cgit v1.2.3-54-g00ecf