From 05d13dea31861df7366dfe40395c1b04462d02ce Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Fri, 5 Apr 2019 20:46:10 +0200 Subject: ensure drawer is open on workspace settings routes --- src/features/workspaces/store.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/features/workspaces/store.js') diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 7bd969be0..2e1764f99 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js @@ -13,6 +13,7 @@ import { getUserWorkspacesRequest, updateWorkspaceRequest, } from './api'; +import { WORKSPACES_ROUTES } from './index'; const debug = require('debug')('Franz:feature:workspaces:store'); @@ -70,6 +71,7 @@ export default class WorkspacesStore extends FeatureStore { this._setFeatureEnabledReaction, this._setIsPremiumFeatureReaction, this._activateLastUsedWorkspaceReaction, + this._openDrawerWithSettingsReaction, ]); getUserWorkspacesRequest.execute(); @@ -100,6 +102,10 @@ export default class WorkspacesStore extends FeatureStore { // ========== PRIVATE ========= // + _wasDrawerOpenBeforeSettingsRoute = null; + + _isSettingsRouteActive = null; + _getWorkspaceById = id => this.workspaces.find(w => w.id === id); _updateSettings = (changes) => { @@ -229,4 +235,24 @@ export default class WorkspacesStore extends FeatureStore { } } }; + + _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(); + } + } + }; } -- cgit v1.2.3-54-g00ecf