diff options
author | Dominik Guzei <dominik.guzei@gmail.com> | 2019-01-14 19:01:46 +0100 |
---|---|---|
committer | Dominik Guzei <dominik.guzei@gmail.com> | 2019-02-12 13:39:05 +0100 |
commit | e6da59b728bf44342428531a2c7e4024829234ed (patch) | |
tree | c00dea3ae961dcee4110df52b5f842211ed50ba3 /src/features/workspaces | |
parent | add styles for workspace table (diff) | |
download | ferdium-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')
-rw-r--r-- | src/features/workspaces/state.js | 1 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 32 |
2 files changed, 32 insertions, 1 deletions
diff --git a/src/features/workspaces/state.js b/src/features/workspaces/state.js index ed3fe9f00..f938c1470 100644 --- a/src/features/workspaces/state.js +++ b/src/features/workspaces/state.js | |||
@@ -3,6 +3,7 @@ import { observable } from 'mobx'; | |||
3 | const defaultState = { | 3 | const defaultState = { |
4 | isLoading: false, | 4 | isLoading: false, |
5 | workspaces: [], | 5 | workspaces: [], |
6 | workspaceBeingEdited: null, | ||
6 | }; | 7 | }; |
7 | 8 | ||
8 | export const state = observable(defaultState); | 9 | export const state = observable(defaultState); |
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'; | |||
2 | import Store from '../../stores/lib/Store'; | 2 | import Store from '../../stores/lib/Store'; |
3 | import CachedRequest from '../../stores/lib/CachedRequest'; | 3 | import CachedRequest from '../../stores/lib/CachedRequest'; |
4 | import Workspace from '../../models/Workspace'; | 4 | import Workspace from '../../models/Workspace'; |
5 | import { matchRoute } from '../../helpers/routing-helpers'; | ||
5 | 6 | ||
6 | const debug = require('debug')('Franz:feature:workspaces'); | 7 | const 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 | } |