aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js69
1 files changed, 58 insertions, 11 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index ea601700e..e11513d1f 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -14,6 +14,8 @@ import {
14 updateWorkspaceRequest, 14 updateWorkspaceRequest,
15} from './api'; 15} from './api';
16import { WORKSPACES_ROUTES } from './index'; 16import { WORKSPACES_ROUTES } from './index';
17import { createReactions } from '../../stores/lib/Reaction';
18import { createActionBindings } from '../utils/ActionBinding';
17 19
18const debug = require('debug')('Franz:feature:workspaces:store'); 20const debug = require('debug')('Franz:feature:workspaces:store');
19 21
@@ -51,37 +53,74 @@ export default class WorkspacesStore extends FeatureStore {
51 return getUserWorkspacesRequest.wasExecuted && this.workspaces.length > 0; 53 return getUserWorkspacesRequest.wasExecuted && this.workspaces.length > 0;
52 } 54 }
53 55
56 @computed get isUserAllowedToUseFeature() {
57 return !this.isPremiumUpgradeRequired;
58 }
59
60 // ========== PRIVATE PROPERTIES ========= //
61
62 _wasDrawerOpenBeforeSettingsRoute = null;
63
64 _freeUserActions = [];
65
66 _premiumUserActions = [];
67
68 _allActions = [];
69
70 _freeUserReactions = [];
71
72 _premiumUserReactions = [];
73
74 _allReactions = [];
75
76 // ========== PUBLIC API ========= //
77
54 start(stores, actions) { 78 start(stores, actions) {
55 debug('WorkspacesStore::start'); 79 debug('WorkspacesStore::start');
56 this.stores = stores; 80 this.stores = stores;
57 this.actions = actions; 81 this.actions = actions;
58 82
59 this._listenToActions([ 83 // ACTIONS
84
85 this._freeUserActions = createActionBindings([
86 [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer],
87 [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings],
88 ]);
89 this._premiumUserActions = createActionBindings([
60 [workspaceActions.edit, this._edit], 90 [workspaceActions.edit, this._edit],
61 [workspaceActions.create, this._create], 91 [workspaceActions.create, this._create],
62 [workspaceActions.delete, this._delete], 92 [workspaceActions.delete, this._delete],
63 [workspaceActions.update, this._update], 93 [workspaceActions.update, this._update],
64 [workspaceActions.activate, this._setActiveWorkspace], 94 [workspaceActions.activate, this._setActiveWorkspace],
65 [workspaceActions.deactivate, this._deactivateActiveWorkspace], 95 [workspaceActions.deactivate, this._deactivateActiveWorkspace],
66 [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer],
67 [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings],
68 ]); 96 ]);
97 this._allActions = this._freeUserActions.concat(this._premiumUserActions);
98 this._registerActions(this._allActions);
69 99
70 this._startReactions([ 100 // REACTIONS
71 this._setWorkspaceBeingEditedReaction, 101
72 this._setActiveServiceOnWorkspaceSwitchReaction, 102 this._freeUserReactions = createReactions([
103 this._stopPremiumActionsAndReactions,
104 this._openDrawerWithSettingsReaction,
73 this._setFeatureEnabledReaction, 105 this._setFeatureEnabledReaction,
74 this._setIsPremiumFeatureReaction, 106 this._setIsPremiumFeatureReaction,
75 this._activateLastUsedWorkspaceReaction,
76 this._openDrawerWithSettingsReaction,
77 this._cleanupInvalidServiceReferences, 107 this._cleanupInvalidServiceReferences,
78 ]); 108 ]);
109 this._premiumUserReactions = createReactions([
110 this._setActiveServiceOnWorkspaceSwitchReaction,
111 this._activateLastUsedWorkspaceReaction,
112 this._setWorkspaceBeingEditedReaction,
113 ]);
114 this._allReactions = this._freeUserReactions.concat(this._premiumUserReactions);
115
116 this._registerReactions(this._allReactions);
79 117
80 getUserWorkspacesRequest.execute(); 118 getUserWorkspacesRequest.execute();
81 this.isFeatureActive = true; 119 this.isFeatureActive = true;
82 } 120 }
83 121
84 stop() { 122 stop() {
123 super.stop();
85 debug('WorkspacesStore::stop'); 124 debug('WorkspacesStore::stop');
86 this.isFeatureActive = false; 125 this.isFeatureActive = false;
87 this.activeWorkspace = null; 126 this.activeWorkspace = null;
@@ -104,9 +143,7 @@ export default class WorkspacesStore extends FeatureStore {
104 return workspace.services.map(id => services.one(id)).filter(s => !!s); 143 return workspace.services.map(id => services.one(id)).filter(s => !!s);
105 } 144 }
106 145
107 // ========== PRIVATE ========= // 146 // ========== PRIVATE METHODS ========= //
108
109 _wasDrawerOpenBeforeSettingsRoute = null;
110 147
111 _getWorkspaceById = id => this.workspaces.find(w => w.id === id); 148 _getWorkspaceById = id => this.workspaces.find(w => w.id === id);
112 149
@@ -273,4 +310,14 @@ export default class WorkspacesStore extends FeatureStore {
273 getUserWorkspacesRequest.execute(); 310 getUserWorkspacesRequest.execute();
274 } 311 }
275 }; 312 };
313
314 _stopPremiumActionsAndReactions = () => {
315 if (!this.isUserAllowedToUseFeature) {
316 this._stopActions(this._premiumUserActions);
317 this._stopReactions(this._premiumUserReactions);
318 } else {
319 this._startActions(this._premiumUserActions);
320 this._startReactions(this._premiumUserReactions);
321 }
322 }
276} 323}