aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-03 17:53:50 +0200
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-04-03 17:54:57 +0200
commit07d10ad573d36d460acabe282d6020487e95c090 (patch)
tree6517572b502c05bf355bdd9fcdedf76a6e41b536 /src/features/workspaces/store.js
parentgive upgrade account button a bit more padding (diff)
downloadferdium-app-07d10ad573d36d460acabe282d6020487e95c090.tar.gz
ferdium-app-07d10ad573d36d460acabe282d6020487e95c090.tar.zst
ferdium-app-07d10ad573d36d460acabe282d6020487e95c090.zip
add open last used workspace logic
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index 712945bdc..2abb91c22 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -9,7 +9,7 @@ import { FeatureStore } from '../utils/FeatureStore';
9import { 9import {
10 createWorkspaceRequest, 10 createWorkspaceRequest,
11 deleteWorkspaceRequest, 11 deleteWorkspaceRequest,
12 getUserWorkspacesRequest, 12 getUserWorkspacesRequest, getWorkspaceSettingsRequest, setWorkspaceSettingsRequest,
13 updateWorkspaceRequest, 13 updateWorkspaceRequest,
14} from './api'; 14} from './api';
15 15
@@ -37,6 +37,14 @@ export default class WorkspacesStore extends FeatureStore {
37 return getUserWorkspacesRequest.result || []; 37 return getUserWorkspacesRequest.result || [];
38 } 38 }
39 39
40 @computed get settings() {
41 return getWorkspaceSettingsRequest.result;
42 }
43
44 @computed get userHasWorkspaces() {
45 return getUserWorkspacesRequest.wasExecuted && this.workspaces.length > 0;
46 }
47
40 @computed get isPremiumUpgradeRequired() { 48 @computed get isPremiumUpgradeRequired() {
41 return this.isFeatureEnabled && !this.isFeatureActive; 49 return this.isFeatureEnabled && !this.isFeatureActive;
42 } 50 }
@@ -62,9 +70,11 @@ export default class WorkspacesStore extends FeatureStore {
62 this._setActiveServiceOnWorkspaceSwitchReaction, 70 this._setActiveServiceOnWorkspaceSwitchReaction,
63 this._setFeatureEnabledReaction, 71 this._setFeatureEnabledReaction,
64 this._setIsPremiumFeatureReaction, 72 this._setIsPremiumFeatureReaction,
73 this._activateLastUsedWorkspaceReaction,
65 ]); 74 ]);
66 75
67 getUserWorkspacesRequest.execute(); 76 getUserWorkspacesRequest.execute();
77 getWorkspaceSettingsRequest.execute();
68 this.isFeatureActive = true; 78 this.isFeatureActive = true;
69 } 79 }
70 80
@@ -94,6 +104,13 @@ export default class WorkspacesStore extends FeatureStore {
94 104
95 _getWorkspaceById = id => this.workspaces.find(w => w.id === id); 105 _getWorkspaceById = id => this.workspaces.find(w => w.id === id);
96 106
107 _updateSettings = (changes) => {
108 setWorkspaceSettingsRequest.execute({
109 ...this.settings,
110 ...changes,
111 });
112 };
113
97 // Actions 114 // Actions
98 115
99 @action _edit = ({ workspace }) => { 116 @action _edit = ({ workspace }) => {
@@ -137,7 +154,10 @@ export default class WorkspacesStore extends FeatureStore {
137 this.isSwitchingWorkspace = true; 154 this.isSwitchingWorkspace = true;
138 this.nextWorkspace = workspace; 155 this.nextWorkspace = workspace;
139 // Delay switching to next workspace so that the services loading does not drag down UI 156 // Delay switching to next workspace so that the services loading does not drag down UI
140 setTimeout(() => { this.activeWorkspace = workspace; }, 100); 157 setTimeout(() => {
158 this.activeWorkspace = workspace;
159 this._updateSettings({ lastActiveWorkspace: workspace.id });
160 }, 100);
141 // Indicate that we are done switching to the next workspace 161 // Indicate that we are done switching to the next workspace
142 setTimeout(() => { 162 setTimeout(() => {
143 this.isSwitchingWorkspace = false; 163 this.isSwitchingWorkspace = false;
@@ -149,8 +169,12 @@ export default class WorkspacesStore extends FeatureStore {
149 // Indicate that we are switching to default workspace 169 // Indicate that we are switching to default workspace
150 this.isSwitchingWorkspace = true; 170 this.isSwitchingWorkspace = true;
151 this.nextWorkspace = null; 171 this.nextWorkspace = null;
172 this._updateSettings({ lastActiveWorkspace: null });
173 getWorkspaceSettingsRequest.execute();
152 // Delay switching to next workspace so that the services loading does not drag down UI 174 // Delay switching to next workspace so that the services loading does not drag down UI
153 setTimeout(() => { this.activeWorkspace = null; }, 100); 175 setTimeout(() => {
176 this.activeWorkspace = null;
177 }, 100);
154 // Indicate that we are done switching to the default workspace 178 // Indicate that we are done switching to the default workspace
155 setTimeout(() => { this.isSwitchingWorkspace = false; }, 1000); 179 setTimeout(() => { this.isSwitchingWorkspace = false; }, 1000);
156 }; 180 };
@@ -195,4 +219,14 @@ export default class WorkspacesStore extends FeatureStore {
195 } 219 }
196 } 220 }
197 }; 221 };
222
223 _activateLastUsedWorkspaceReaction = () => {
224 if (!this.activeWorkspace && this.userHasWorkspaces) {
225 const { lastActiveWorkspace } = this.settings;
226 if (lastActiveWorkspace) {
227 const workspace = this._getWorkspaceById(lastActiveWorkspace);
228 if (workspace) this._setActiveWorkspace({ workspace });
229 }
230 }
231 };
198} 232}