aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/workspaces/store.js
diff options
context:
space:
mode:
authorLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-01-14 19:01:46 +0100
committerLibravatar Dominik Guzei <dominik.guzei@gmail.com>2019-02-12 13:39:05 +0100
commite6da59b728bf44342428531a2c7e4024829234ed (patch)
treec00dea3ae961dcee4110df52b5f842211ed50ba3 /src/features/workspaces/store.js
parentadd styles for workspace table (diff)
downloadferdium-app-e6da59b728bf44342428531a2c7e4024829234ed.tar.gz
ferdium-app-e6da59b728bf44342428531a2c7e4024829234ed.tar.zst
ferdium-app-e6da59b728bf44342428531a2c7e4024829234ed.zip
setup logic to display workspace edit page
Diffstat (limited to 'src/features/workspaces/store.js')
-rw-r--r--src/features/workspaces/store.js32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js
index 2b6d55cc7..aab66708b 100644
--- a/src/features/workspaces/store.js
+++ b/src/features/workspaces/store.js
@@ -2,6 +2,7 @@ import { observable, reaction } 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';
5 6
6const debug = require('debug')('Franz:feature:workspaces'); 7const debug = require('debug')('Franz:feature:workspaces');
7 8
@@ -14,17 +15,40 @@ export default class WorkspacesStore extends Store {
14 } 15 }
15 16
16 setup() { 17 setup() {
17 debug('fetching user workspaces'); 18 debug('fetching workspaces');
18 this.allWorkspacesRequest.execute(); 19 this.allWorkspacesRequest.execute();
19 20
21 /**
22 * Update the state workspaces array when workspaces request has results.
23 */
20 reaction( 24 reaction(
21 () => this.allWorkspacesRequest.result, 25 () => this.allWorkspacesRequest.result,
22 workspaces => this._setWorkspaces(workspaces), 26 workspaces => this._setWorkspaces(workspaces),
23 ); 27 );
28 /**
29 * Update the loading state when workspace request is executing.
30 */
24 reaction( 31 reaction(
25 () => this.allWorkspacesRequest.isExecuting, 32 () => this.allWorkspacesRequest.isExecuting,
26 isExecuting => this._setIsLoading(isExecuting), 33 isExecuting => this._setIsLoading(isExecuting),
27 ); 34 );
35 /**
36 * Update the state with the workspace to be edited when route matches.
37 */
38 reaction(
39 () => ({
40 pathname: this.stores.router.location.pathname,
41 workspaces: this.state.workspaces,
42 }),
43 ({ pathname }) => {
44 const match = matchRoute('/settings/workspaces/edit/:id', pathname);
45 if (match) {
46 this.state.workspaceBeingEdited = this._getWorkspaceById(match.id);
47 }
48 },
49 );
50
51 this.actions.workspace.edit.listen(this._edit);
28 } 52 }
29 53
30 _setWorkspaces = (workspaces) => { 54 _setWorkspaces = (workspaces) => {
@@ -35,4 +59,10 @@ export default class WorkspacesStore extends Store {
35 _setIsLoading = (isLoading) => { 59 _setIsLoading = (isLoading) => {
36 this.state.isLoading = isLoading; 60 this.state.isLoading = isLoading;
37 }; 61 };
62
63 _getWorkspaceById = id => this.state.workspaces.find(w => w.id === id);
64
65 _edit = ({ workspace }) => {
66 this.stores.router.push(`/settings/workspaces/edit/${workspace.id}`);
67 }
38} 68}