aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-03-28 16:23:17 +0100
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-03-28 16:23:17 +0100
commit7941831bf773b49944001c095a1949a1bdec2cf2 (patch)
tree5dbcbf097e340c381617410e032c2db6b811096e /src/features/workspaces/store.js
parentimprove styling of workspace switch indicator (diff)
downloadferdium-app-7941831bf773b49944001c095a1949a1bdec2cf2.tar.gz
ferdium-app-7941831bf773b49944001c095a1949a1bdec2cf2.tar.zst
ferdium-app-7941831bf773b49944001c095a1949a1bdec2cf2.zip
add workspace premium notice to dashboard
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js69
1 files changed, 40 insertions, 29 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index f7df7b29c..62bf3efb4 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -3,9 +3,9 @@ import {
3 observable, 3 observable,
4 action, 4 action,
5} from 'mobx'; 5} from 'mobx';
6import Reaction from '../../stores/lib/Reaction';
7import { matchRoute } from '../../helpers/routing-helpers'; 6import { matchRoute } from '../../helpers/routing-helpers';
8import { workspaceActions } from './actions'; 7import { workspaceActions } from './actions';
8import { FeatureStore } from '../utils/FeatureStore';
9import { 9import {
10 createWorkspaceRequest, 10 createWorkspaceRequest,
11 deleteWorkspaceRequest, 11 deleteWorkspaceRequest,
@@ -15,7 +15,11 @@ import {
15 15
16const debug = require('debug')('Franz:feature:workspaces:store'); 16const debug = require('debug')('Franz:feature:workspaces:store');
17 17
18export default class WorkspacesStore { 18export default class WorkspacesStore extends FeatureStore {
19 @observable isFeatureEnabled = false;
20
21 @observable isPremiumFeature = true;
22
19 @observable isFeatureActive = false; 23 @observable isFeatureActive = false;
20 24
21 @observable activeWorkspace = null; 25 @observable activeWorkspace = null;
@@ -33,36 +37,39 @@ export default class WorkspacesStore {
33 return getUserWorkspacesRequest.result || []; 37 return getUserWorkspacesRequest.result || [];
34 } 38 }
35 39
36 constructor() { 40 @computed get isUpgradeToPremiumRequired() {
37 // Wire-up action handlers 41 return this.isFeatureEnabled && !this.isFeatureActive;
38 workspaceActions.edit.listen(this._edit);
39 workspaceActions.create.listen(this._create);
40 workspaceActions.delete.listen(this._delete);
41 workspaceActions.update.listen(this._update);
42 workspaceActions.activate.listen(this._setActiveWorkspace);
43 workspaceActions.deactivate.listen(this._deactivateActiveWorkspace);
44 workspaceActions.toggleWorkspaceDrawer.listen(this._toggleWorkspaceDrawer);
45 workspaceActions.openWorkspaceSettings.listen(this._openWorkspaceSettings);
46
47 // Register and start reactions
48 this._registerReactions([
49 this._updateWorkspaceBeingEdited,
50 this._updateActiveServiceOnWorkspaceSwitch,
51 ]);
52 } 42 }
53 43
54 start(stores, actions) { 44 start(stores, actions) {
55 debug('WorkspacesStore::start'); 45 debug('WorkspacesStore::start');
56 this.stores = stores; 46 this.stores = stores;
57 this.actions = actions; 47 this.actions = actions;
58 this._reactions.forEach(r => r.start()); 48
59 this.isFeatureActive = true; 49 this._listenToActions([
50 [workspaceActions.edit, this._edit],
51 [workspaceActions.create, this._create],
52 [workspaceActions.delete, this._delete],
53 [workspaceActions.update, this._update],
54 [workspaceActions.activate, this._setActiveWorkspace],
55 [workspaceActions.deactivate, this._deactivateActiveWorkspace],
56 [workspaceActions.toggleWorkspaceDrawer, this._toggleWorkspaceDrawer],
57 [workspaceActions.openWorkspaceSettings, this._openWorkspaceSettings],
58 ]);
59
60 this._startReactions([
61 this._setWorkspaceBeingEditedReaction,
62 this._setActiveServiceOnWorkspaceSwitchReaction,
63 this._setFeatureEnabledReaction,
64 this._setIsPremiumFeatureReaction,
65 ]);
66
60 getUserWorkspacesRequest.execute(); 67 getUserWorkspacesRequest.execute();
68 this.isFeatureActive = true;
61 } 69 }
62 70
63 stop() { 71 stop() {
64 debug('WorkspacesStore::stop'); 72 debug('WorkspacesStore::stop');
65 this._reactions.forEach(r => r.stop());
66 this.isFeatureActive = false; 73 this.isFeatureActive = false;
67 this.activeWorkspace = null; 74 this.activeWorkspace = null;
68 this.nextWorkspace = null; 75 this.nextWorkspace = null;
@@ -85,12 +92,6 @@ export default class WorkspacesStore {
85 92
86 // ========== PRIVATE ========= // 93 // ========== PRIVATE ========= //
87 94
88 _reactions = [];
89
90 _registerReactions(reactions) {
91 reactions.forEach(r => this._reactions.push(new Reaction(r)));
92 }
93
94 _getWorkspaceById = id => this.workspaces.find(w => w.id === id); 95 _getWorkspaceById = id => this.workspaces.find(w => w.id === id);
95 96
96 // Actions 97 // Actions
@@ -164,7 +165,17 @@ export default class WorkspacesStore {
164 165
165 // Reactions 166 // Reactions
166 167
167 _updateWorkspaceBeingEdited = () => { 168 _setFeatureEnabledReaction = () => {
169 const { isWorkspaceEnabled } = this.stores.features.features;
170 this.isFeatureEnabled = isWorkspaceEnabled;
171 };
172
173 _setIsPremiumFeatureReaction = () => {
174 const { isWorkspacePremiumFeature } = this.stores.features.features;
175 this.isPremiumFeature = isWorkspacePremiumFeature;
176 };
177
178 _setWorkspaceBeingEditedReaction = () => {
168 const { pathname } = this.stores.router.location; 179 const { pathname } = this.stores.router.location;
169 const match = matchRoute('/settings/workspaces/edit/:id', pathname); 180 const match = matchRoute('/settings/workspaces/edit/:id', pathname);
170 if (match) { 181 if (match) {
@@ -172,7 +183,7 @@ export default class WorkspacesStore {
172 } 183 }
173 }; 184 };
174 185
175 _updateActiveServiceOnWorkspaceSwitch = () => { 186 _setActiveServiceOnWorkspaceSwitchReaction = () => {
176 if (!this.isFeatureActive) return; 187 if (!this.isFeatureActive) return;
177 if (this.activeWorkspace) { 188 if (this.activeWorkspace) {
178 const services = this.stores.services.allDisplayed; 189 const services = this.stores.services.allDisplayed;