diff options
author | Muhamed <unknown> | 2022-11-24 02:56:10 +0530 |
---|---|---|
committer | Vijay Aravamudhan <vraravam@users.noreply.github.com> | 2022-11-25 05:04:25 +0530 |
commit | f92933c396db9e94ffd297c41add86de88dfc6c6 (patch) | |
tree | 57789f7f64c618086c3792833d076244d879aa75 /src/features/workspaces | |
parent | fix: use 'Route' from 'react-router-dom' package (diff) | |
download | ferdium-app-f92933c396db9e94ffd297c41add86de88dfc6c6.tar.gz ferdium-app-f92933c396db9e94ffd297c41add86de88dfc6c6.tar.zst ferdium-app-f92933c396db9e94ffd297c41add86de88dfc6c6.zip |
chore: transform workspace action store and todo store into ts
Diffstat (limited to 'src/features/workspaces')
-rw-r--r-- | src/features/workspaces/actions.ts | 7 | ||||
-rw-r--r-- | src/features/workspaces/store.ts (renamed from src/features/workspaces/store.js) | 40 |
2 files changed, 32 insertions, 15 deletions
diff --git a/src/features/workspaces/actions.ts b/src/features/workspaces/actions.ts index b32bd7c86..5f3fefec4 100644 --- a/src/features/workspaces/actions.ts +++ b/src/features/workspaces/actions.ts | |||
@@ -2,12 +2,17 @@ import PropTypes from 'prop-types'; | |||
2 | import Workspace from './models/Workspace'; | 2 | import Workspace from './models/Workspace'; |
3 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | 3 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; |
4 | 4 | ||
5 | type WorkspaceArg = { workspace: Workspace }; | ||
5 | export interface WorkspaceActions { | 6 | export interface WorkspaceActions { |
6 | openWorkspaceSettings: () => void; | 7 | openWorkspaceSettings: () => void; |
7 | toggleWorkspaceDrawer: () => void; | 8 | toggleWorkspaceDrawer: () => void; |
8 | deactivate: () => void; | 9 | deactivate: () => void; |
9 | activate: (options: any) => void; | 10 | activate: (options: any) => void; |
10 | edit: ({ workspace }: { workspace: Workspace }) => void; | 11 | edit: (workspaceArg: WorkspaceArg) => void; |
12 | create: ({ name }: { name: string }) => void; | ||
13 | delete: (workspaceArg: WorkspaceArg) => void; | ||
14 | update: (workspaceArg: WorkspaceArg) => void; | ||
15 | toggleKeepAllWorkspacesLoadedSetting: () => void; | ||
11 | } | 16 | } |
12 | 17 | ||
13 | export default createActionsFromDefinitions<WorkspaceActions>( | 18 | export default createActionsFromDefinitions<WorkspaceActions>( |
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.ts index 2323019fe..d63feb1f8 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.ts | |||
@@ -14,6 +14,8 @@ import { createReactions } from '../../stores/lib/Reaction'; | |||
14 | import { createActionBindings } from '../utils/ActionBinding'; | 14 | import { createActionBindings } from '../utils/ActionBinding'; |
15 | 15 | ||
16 | import { KEEP_WS_LOADED_USID } from '../../config'; | 16 | import { KEEP_WS_LOADED_USID } from '../../config'; |
17 | import Workspace from './models/Workspace'; | ||
18 | import { Actions } from '../../actions/lib/actions'; | ||
17 | 19 | ||
18 | const debug = require('../../preload-safe-debug')( | 20 | const debug = require('../../preload-safe-debug')( |
19 | 'Ferdium:feature:workspaces:store', | 21 | 'Ferdium:feature:workspaces:store', |
@@ -22,17 +24,21 @@ const debug = require('../../preload-safe-debug')( | |||
22 | export default class WorkspacesStore extends FeatureStore { | 24 | export default class WorkspacesStore extends FeatureStore { |
23 | @observable isFeatureActive = false; | 25 | @observable isFeatureActive = false; |
24 | 26 | ||
25 | @observable activeWorkspace = null; | 27 | @observable activeWorkspace: Workspace | undefined; |
26 | 28 | ||
27 | @observable nextWorkspace = null; | 29 | @observable nextWorkspace: Workspace | undefined; |
28 | 30 | ||
29 | @observable workspaceBeingEdited = null; | 31 | @observable workspaceBeingEdited: any = null; // TODO - [TS DEBT] fix type later |
30 | 32 | ||
31 | @observable isSwitchingWorkspace = false; | 33 | @observable isSwitchingWorkspace = false; |
32 | 34 | ||
33 | @observable isWorkspaceDrawerOpen = false; | 35 | @observable isWorkspaceDrawerOpen = false; |
34 | 36 | ||
35 | @observable isSettingsRouteActive = null; | 37 | @observable isSettingsRouteActive = false; |
38 | |||
39 | stores: any; // TODO - [TS DEBT] fix type later | ||
40 | |||
41 | actions: Actions | undefined; | ||
36 | 42 | ||
37 | constructor() { | 43 | constructor() { |
38 | super(); | 44 | super(); |
@@ -68,7 +74,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
68 | 74 | ||
69 | // ========== PRIVATE PROPERTIES ========= // | 75 | // ========== PRIVATE PROPERTIES ========= // |
70 | 76 | ||
71 | _wasDrawerOpenBeforeSettingsRoute = null; | 77 | _wasDrawerOpenBeforeSettingsRoute = false; |
72 | 78 | ||
73 | _allActions = []; | 79 | _allActions = []; |
74 | 80 | ||
@@ -159,13 +165,13 @@ export default class WorkspacesStore extends FeatureStore { | |||
159 | }; | 165 | }; |
160 | 166 | ||
161 | @action _create = async ({ name }) => { | 167 | @action _create = async ({ name }) => { |
162 | const workspace = await createWorkspaceRequest.execute(name); | 168 | const workspace = await createWorkspaceRequest.execute(name).promise; |
163 | await getUserWorkspacesRequest.result.push(workspace); | 169 | await getUserWorkspacesRequest.result.push(workspace); |
164 | this._edit({ workspace }); | 170 | this._edit({ workspace }); |
165 | }; | 171 | }; |
166 | 172 | ||
167 | @action _delete = async ({ workspace }) => { | 173 | @action _delete = async ({ workspace }) => { |
168 | await deleteWorkspaceRequest.execute(workspace); | 174 | await deleteWorkspaceRequest.execute(workspace).promise; |
169 | await getUserWorkspacesRequest.result.remove(workspace); | 175 | await getUserWorkspacesRequest.result.remove(workspace); |
170 | this.stores.router.push('/settings/workspaces'); | 176 | this.stores.router.push('/settings/workspaces'); |
171 | if (this.activeWorkspace === workspace) { | 177 | if (this.activeWorkspace === workspace) { |
@@ -174,7 +180,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
174 | }; | 180 | }; |
175 | 181 | ||
176 | @action _update = async ({ workspace }) => { | 182 | @action _update = async ({ workspace }) => { |
177 | await updateWorkspaceRequest.execute(workspace); | 183 | await updateWorkspaceRequest.execute(workspace).promise; |
178 | // Path local result optimistically | 184 | // Path local result optimistically |
179 | const localWorkspace = this._getWorkspaceById(workspace.id); | 185 | const localWorkspace = this._getWorkspaceById(workspace.id); |
180 | Object.assign(localWorkspace, workspace); | 186 | Object.assign(localWorkspace, workspace); |
@@ -210,7 +216,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
210 | const serviceNames = new Set( | 216 | const serviceNames = new Set( |
211 | this.getWorkspaceServices(workspace).map(service => service.name), | 217 | this.getWorkspaceServices(workspace).map(service => service.name), |
212 | ); | 218 | ); |
213 | for (const wrapper of document.querySelectorAll( | 219 | for (const wrapper of document.querySelectorAll<HTMLDivElement>( |
214 | '.services__webview-wrapper', | 220 | '.services__webview-wrapper', |
215 | )) { | 221 | )) { |
216 | wrapper.style.display = serviceNames.has(wrapper.dataset.name) | 222 | wrapper.style.display = serviceNames.has(wrapper.dataset.name) |
@@ -234,7 +240,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
234 | setTimeout(() => { | 240 | setTimeout(() => { |
235 | this._setIsSwitchingWorkspace(false); | 241 | this._setIsSwitchingWorkspace(false); |
236 | if (this.stores.settings.app.splitMode) { | 242 | if (this.stores.settings.app.splitMode) { |
237 | for (const wrapper of document.querySelectorAll( | 243 | for (const wrapper of document.querySelectorAll<HTMLDivElement>( |
238 | '.services__webview-wrapper', | 244 | '.services__webview-wrapper', |
239 | )) { | 245 | )) { |
240 | wrapper.style.display = ''; | 246 | wrapper.style.display = ''; |
@@ -248,15 +254,21 @@ export default class WorkspacesStore extends FeatureStore { | |||
248 | }; | 254 | }; |
249 | 255 | ||
250 | @action _openWorkspaceSettings = () => { | 256 | @action _openWorkspaceSettings = () => { |
257 | if (!this.actions) { | ||
258 | return; | ||
259 | } | ||
251 | this.actions.ui.openSettings({ path: 'workspaces' }); | 260 | this.actions.ui.openSettings({ path: 'workspaces' }); |
252 | }; | 261 | }; |
253 | 262 | ||
254 | @action reorderServicesOfActiveWorkspace = async ({ oldIndex, newIndex }) => { | 263 | @action reorderServicesOfActiveWorkspace = async ({ oldIndex, newIndex }) => { |
255 | const { activeWorkspace } = this; | 264 | if (!this.activeWorkspace) { |
256 | const { services } = activeWorkspace; | 265 | return; |
266 | } | ||
267 | |||
268 | const { services = [] } = this.activeWorkspace; | ||
257 | // Move services from the old to the new position | 269 | // Move services from the old to the new position |
258 | services.splice(newIndex, 0, services.splice(oldIndex, 1)[0]); | 270 | services.splice(newIndex, 0, services.splice(oldIndex, 1)[0]); |
259 | await updateWorkspaceRequest.execute(activeWorkspace); | 271 | await updateWorkspaceRequest.execute(this.activeWorkspace).promise; |
260 | }; | 272 | }; |
261 | 273 | ||
262 | @action _setOpenDrawerWithSettings() { | 274 | @action _setOpenDrawerWithSettings() { |
@@ -314,7 +326,7 @@ export default class WorkspacesStore extends FeatureStore { | |||
314 | if (workspaceServices.length <= 0) return; | 326 | if (workspaceServices.length <= 0) return; |
315 | const isActiveServiceInWorkspace = | 327 | const isActiveServiceInWorkspace = |
316 | workspaceServices.includes(activeService); | 328 | workspaceServices.includes(activeService); |
317 | if (!isActiveServiceInWorkspace) { | 329 | if (!isActiveServiceInWorkspace && this.actions) { |
318 | this.actions.service.setActive({ | 330 | this.actions.service.setActive({ |
319 | serviceId: workspaceServices[0].id, | 331 | serviceId: workspaceServices[0].id, |
320 | keepActiveRoute: true, | 332 | keepActiveRoute: true, |