diff options
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r-- | src/features/workspaces/store.js | 100 |
1 files changed, 60 insertions, 40 deletions
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 { | |||
90 | [workspaceActions.create, this._create], | 90 | [workspaceActions.create, this._create], |
91 | [workspaceActions.delete, this._delete], | 91 | [workspaceActions.delete, this._delete], |
92 | [workspaceActions.update, this._update], | 92 | [workspaceActions.update, this._update], |
93 | [workspaceActions.activate, this._setActiveWorkspace], | 93 | [workspaceActions.activate, this._setActivateWorkspace], |
94 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], | 94 | [workspaceActions.deactivate, this._deactivateActiveWorkspace], |
95 | [ | 95 | [ |
96 | workspaceActions.toggleKeepAllWorkspacesLoadedSetting, | 96 | workspaceActions.toggleKeepAllWorkspacesLoadedSetting, |
@@ -114,10 +114,10 @@ export default class WorkspacesStore extends FeatureStore { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | @action reset() { | 116 | @action reset() { |
117 | this.activeWorkspace = null; | 117 | this._setActiveWorkspace(null); |
118 | this.nextWorkspace = null; | 118 | this._setNextWorkspace(null); |
119 | this.workspaceBeingEdited = null; | 119 | this.workspaceBeingEdited = null; |
120 | this.isSwitchingWorkspace = false; | 120 | this._setIsSwitchingWorkspace(false); |
121 | this.isWorkspaceDrawerOpen = false; | 121 | this.isWorkspaceDrawerOpen = false; |
122 | } | 122 | } |
123 | 123 | ||
@@ -181,19 +181,31 @@ export default class WorkspacesStore extends FeatureStore { | |||
181 | this.stores.router.push('/settings/workspaces'); | 181 | this.stores.router.push('/settings/workspaces'); |
182 | }; | 182 | }; |
183 | 183 | ||
184 | @action _setActiveWorkspace = ({ workspace }) => { | 184 | @action _setNextWorkspace(workspace) { |
185 | // Indicate that we are switching to another workspace | ||
186 | this.isSwitchingWorkspace = true; | ||
187 | this.nextWorkspace = workspace; | 185 | this.nextWorkspace = workspace; |
186 | } | ||
187 | |||
188 | @action _setIsSwitchingWorkspace(bool) { | ||
189 | this.isSwitchingWorkspace = bool; | ||
190 | } | ||
191 | |||
192 | @action _setActiveWorkspace(workspace) { | ||
193 | this.activeWorkspace = workspace; | ||
194 | } | ||
195 | |||
196 | @action _setActivateWorkspace = ({ workspace }) => { | ||
197 | // Indicate that we are switching to another workspace | ||
198 | this._setIsSwitchingWorkspace(true); | ||
199 | this._setNextWorkspace(workspace); | ||
188 | // Delay switching to next workspace so that the services loading does not drag down UI | 200 | // Delay switching to next workspace so that the services loading does not drag down UI |
189 | setTimeout(() => { | 201 | setTimeout(() => { |
190 | this.activeWorkspace = workspace; | 202 | this._setActiveWorkspace(workspace); |
191 | this._updateSettings({ lastActiveWorkspace: workspace.id }); | 203 | this._updateSettings({ lastActiveWorkspace: workspace.id }); |
192 | }, 100); | 204 | }, 100); |
193 | // Indicate that we are done switching to the next workspace | 205 | // Indicate that we are done switching to the next workspace |
194 | setTimeout(() => { | 206 | setTimeout(() => { |
195 | this.isSwitchingWorkspace = false; | 207 | this._setIsSwitchingWorkspace(false); |
196 | this.nextWorkspace = null; | 208 | this._setNextWorkspace(null); |
197 | if (this.stores.settings.app.splitMode) { | 209 | if (this.stores.settings.app.splitMode) { |
198 | const serviceNames = new Set( | 210 | const serviceNames = new Set( |
199 | this.getWorkspaceServices(workspace).map(service => service.name), | 211 | this.getWorkspaceServices(workspace).map(service => service.name), |
@@ -211,16 +223,16 @@ export default class WorkspacesStore extends FeatureStore { | |||
211 | 223 | ||
212 | @action _deactivateActiveWorkspace = () => { | 224 | @action _deactivateActiveWorkspace = () => { |
213 | // Indicate that we are switching to default workspace | 225 | // Indicate that we are switching to default workspace |
214 | this.isSwitchingWorkspace = true; | 226 | this._setIsSwitchingWorkspace(true); |
215 | this.nextWorkspace = null; | 227 | this._setNextWorkspace(null); |
216 | this._updateSettings({ lastActiveWorkspace: null }); | 228 | this._updateSettings({ lastActiveWorkspace: null }); |
217 | // Delay switching to next workspace so that the services loading does not drag down UI | 229 | // Delay switching to next workspace so that the services loading does not drag down UI |
218 | setTimeout(() => { | 230 | setTimeout(() => { |
219 | this.activeWorkspace = null; | 231 | this._setActiveWorkspace(null); |
220 | }, 100); | 232 | }, 100); |
221 | // Indicate that we are done switching to the default workspace | 233 | // Indicate that we are done switching to the default workspace |
222 | setTimeout(() => { | 234 | setTimeout(() => { |
223 | this.isSwitchingWorkspace = false; | 235 | this._setIsSwitchingWorkspace(false); |
224 | if (this.stores.settings.app.splitMode) { | 236 | if (this.stores.settings.app.splitMode) { |
225 | for (const wrapper of document.querySelectorAll( | 237 | for (const wrapper of document.querySelectorAll( |
226 | '.services__webview-wrapper', | 238 | '.services__webview-wrapper', |
@@ -247,6 +259,37 @@ export default class WorkspacesStore extends FeatureStore { | |||
247 | await updateWorkspaceRequest.execute(activeWorkspace); | 259 | await updateWorkspaceRequest.execute(activeWorkspace); |
248 | }; | 260 | }; |
249 | 261 | ||
262 | @action _setOpenDrawerWithSettings() { | ||
263 | const { router } = this.stores; | ||
264 | const isWorkspaceSettingsRoute = router.location.pathname.includes( | ||
265 | WORKSPACES_ROUTES.ROOT, | ||
266 | ); | ||
267 | const isSwitchingToSettingsRoute = | ||
268 | !this.isSettingsRouteActive && isWorkspaceSettingsRoute; | ||
269 | const isLeavingSettingsRoute = | ||
270 | !isWorkspaceSettingsRoute && this.isSettingsRouteActive; | ||
271 | |||
272 | if (isSwitchingToSettingsRoute) { | ||
273 | this.isSettingsRouteActive = true; | ||
274 | this._wasDrawerOpenBeforeSettingsRoute = this.isWorkspaceDrawerOpen; | ||
275 | if (!this._wasDrawerOpenBeforeSettingsRoute) { | ||
276 | workspaceActions.toggleWorkspaceDrawer(); | ||
277 | } | ||
278 | } else if (isLeavingSettingsRoute) { | ||
279 | this.isSettingsRouteActive = false; | ||
280 | if ( | ||
281 | !this._wasDrawerOpenBeforeSettingsRoute && | ||
282 | this.isWorkspaceDrawerOpen | ||
283 | ) { | ||
284 | workspaceActions.toggleWorkspaceDrawer(); | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | |||
289 | @action _setWorkspaceBeingEdited(match) { | ||
290 | this.workspaceBeingEdited = this._getWorkspaceById(match.id); | ||
291 | } | ||
292 | |||
250 | _toggleKeepAllWorkspacesLoadedSetting = async () => { | 293 | _toggleKeepAllWorkspacesLoadedSetting = async () => { |
251 | this._updateSettings({ | 294 | this._updateSettings({ |
252 | keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded, | 295 | keepAllWorkspacesLoaded: !this.settings.keepAllWorkspacesLoaded, |
@@ -259,7 +302,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
259 | const { pathname } = this.stores.router.location; | 302 | const { pathname } = this.stores.router.location; |
260 | const match = matchRoute('/settings/workspaces/edit/:id', pathname); | 303 | const match = matchRoute('/settings/workspaces/edit/:id', pathname); |
261 | if (match) { | 304 | if (match) { |
262 | this.workspaceBeingEdited = this._getWorkspaceById(match.id); | 305 | this._setWorkspaceBeingEdited(match); |
263 | } | 306 | } |
264 | }; | 307 | }; |
265 | 308 | ||
@@ -286,36 +329,13 @@ export default class WorkspacesStore extends FeatureStore { | |||
286 | const { lastActiveWorkspace } = this.settings; | 329 | const { lastActiveWorkspace } = this.settings; |
287 | if (lastActiveWorkspace) { | 330 | if (lastActiveWorkspace) { |
288 | const workspace = this._getWorkspaceById(lastActiveWorkspace); | 331 | const workspace = this._getWorkspaceById(lastActiveWorkspace); |
289 | if (workspace) this._setActiveWorkspace({ workspace }); | 332 | if (workspace) this._setActivateWorkspace({ workspace }); |
290 | } | 333 | } |
291 | } | 334 | } |
292 | }; | 335 | }; |
293 | 336 | ||
294 | _openDrawerWithSettingsReaction = () => { | 337 | _openDrawerWithSettingsReaction = () => { |
295 | const { router } = this.stores; | 338 | this._setOpenDrawerWithSettings(); |
296 | const isWorkspaceSettingsRoute = router.location.pathname.includes( | ||
297 | WORKSPACES_ROUTES.ROOT, | ||
298 | ); | ||
299 | const isSwitchingToSettingsRoute = | ||
300 | !this.isSettingsRouteActive && isWorkspaceSettingsRoute; | ||
301 | const isLeavingSettingsRoute = | ||
302 | !isWorkspaceSettingsRoute && this.isSettingsRouteActive; | ||
303 | |||
304 | if (isSwitchingToSettingsRoute) { | ||
305 | this.isSettingsRouteActive = true; | ||
306 | this._wasDrawerOpenBeforeSettingsRoute = this.isWorkspaceDrawerOpen; | ||
307 | if (!this._wasDrawerOpenBeforeSettingsRoute) { | ||
308 | workspaceActions.toggleWorkspaceDrawer(); | ||
309 | } | ||
310 | } else if (isLeavingSettingsRoute) { | ||
311 | this.isSettingsRouteActive = false; | ||
312 | if ( | ||
313 | !this._wasDrawerOpenBeforeSettingsRoute && | ||
314 | this.isWorkspaceDrawerOpen | ||
315 | ) { | ||
316 | workspaceActions.toggleWorkspaceDrawer(); | ||
317 | } | ||
318 | } | ||
319 | }; | 339 | }; |
320 | 340 | ||
321 | _cleanupInvalidServiceReferences = () => { | 341 | _cleanupInvalidServiceReferences = () => { |