aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-03-01 14:25:44 +0100
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-03-01 14:25:44 +0100
commit739ef2e8a2dec94c3e10c3d26d797fe759fac7aa (patch)
tree4a2e066bf8627249f803eee16ba8e73268127fbd /src/features/workspaces/store.js
parentfixes merge conflicts with latest develop (diff)
downloadferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.gz
ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.tar.zst
ferdium-app-739ef2e8a2dec94c3e10c3d26d797fe759fac7aa.zip
finish workspaces mvp
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index 5cccb2ab7..a2997a0d2 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -1,8 +1,9 @@
1import { observable, reaction } from 'mobx'; 1import { observable, reaction, action } from 'mobx';
2import Store from '../../stores/lib/Store'; 2import Store from '../../stores/lib/Store';
3import CachedRequest from '../../stores/lib/CachedRequest'; 3import CachedRequest from '../../stores/lib/CachedRequest';
4import Workspace from './models/Workspace'; 4import Workspace from './models/Workspace';
5import { matchRoute } from '../../helpers/routing-helpers'; 5import { matchRoute } from '../../helpers/routing-helpers';
6import workspaceActions from './actions';
6 7
7const debug = require('debug')('Franz:feature:workspaces'); 8const debug = require('debug')('Franz:feature:workspaces');
8 9
@@ -48,28 +49,30 @@ export default class WorkspacesStore extends Store {
48 }, 49 },
49 ); 50 );
50 51
51 this.actions.workspace.edit.listen(this._edit); 52 workspaceActions.edit.listen(this._edit);
52 this.actions.workspace.create.listen(this._create); 53 workspaceActions.create.listen(this._create);
53 this.actions.workspace.delete.listen(this._delete); 54 workspaceActions.delete.listen(this._delete);
54 this.actions.workspace.update.listen(this._update); 55 workspaceActions.update.listen(this._update);
56 workspaceActions.activate.listen(this._setActiveWorkspace);
57 workspaceActions.deactivate.listen(this._deactivateActiveWorkspace);
55 } 58 }
56 59
57 _setWorkspaces = (workspaces) => { 60 _getWorkspaceById = id => this.state.workspaces.find(w => w.id === id);
61
62 @action _setWorkspaces = (workspaces) => {
58 debug('setting user workspaces', workspaces.slice()); 63 debug('setting user workspaces', workspaces.slice());
59 this.state.workspaces = workspaces.map(data => new Workspace(data)); 64 this.state.workspaces = workspaces.map(data => new Workspace(data));
60 }; 65 };
61 66
62 _setIsLoading = (isLoading) => { 67 @action _setIsLoading = (isLoading) => {
63 this.state.isLoading = isLoading; 68 this.state.isLoading = isLoading;
64 }; 69 };
65 70
66 _getWorkspaceById = id => this.state.workspaces.find(w => w.id === id); 71 @action _edit = ({ workspace }) => {
67
68 _edit = ({ workspace }) => {
69 this.stores.router.push(`/settings/workspaces/edit/${workspace.id}`); 72 this.stores.router.push(`/settings/workspaces/edit/${workspace.id}`);
70 }; 73 };
71 74
72 _create = async ({ name }) => { 75 @action _create = async ({ name }) => {
73 try { 76 try {
74 const result = await this.api.createWorkspace(name); 77 const result = await this.api.createWorkspace(name);
75 const workspace = new Workspace(result); 78 const workspace = new Workspace(result);
@@ -80,7 +83,7 @@ export default class WorkspacesStore extends Store {
80 } 83 }
81 }; 84 };
82 85
83 _delete = async ({ workspace }) => { 86 @action _delete = async ({ workspace }) => {
84 try { 87 try {
85 await this.api.deleteWorkspace(workspace); 88 await this.api.deleteWorkspace(workspace);
86 this.state.workspaces.remove(workspace); 89 this.state.workspaces.remove(workspace);
@@ -90,7 +93,7 @@ export default class WorkspacesStore extends Store {
90 } 93 }
91 }; 94 };
92 95
93 _update = async ({ workspace }) => { 96 @action _update = async ({ workspace }) => {
94 try { 97 try {
95 await this.api.updateWorkspace(workspace); 98 await this.api.updateWorkspace(workspace);
96 const localWorkspace = this.state.workspaces.find(ws => ws.id === workspace.id); 99 const localWorkspace = this.state.workspaces.find(ws => ws.id === workspace.id);
@@ -100,4 +103,12 @@ export default class WorkspacesStore extends Store {
100 throw error; 103 throw error;
101 } 104 }
102 }; 105 };
106
107 @action _setActiveWorkspace = ({ workspace }) => {
108 this.state.activeWorkspace = workspace;
109 };
110
111 @action _deactivateActiveWorkspace = () => {
112 this.state.activeWorkspace = null;
113 };
103} 114}