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 | |
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')
-rw-r--r-- | src/features/todos/store.ts (renamed from src/features/todos/store.js) | 40 | ||||
-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 |
3 files changed, 61 insertions, 26 deletions
diff --git a/src/features/todos/store.js b/src/features/todos/store.ts index 0f195f10d..5cf5e1d75 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.ts | |||
@@ -1,5 +1,7 @@ | |||
1 | import { Webview } from 'react-electron-web-view'; | ||
1 | import { computed, action, observable, makeObservable } from 'mobx'; | 2 | import { computed, action, observable, makeObservable } from 'mobx'; |
2 | import localStorage from 'mobx-localstorage'; | 3 | import localStorage from 'mobx-localstorage'; |
4 | import { Actions } from '../../actions/lib/actions'; | ||
3 | 5 | ||
4 | import { ThemeType } from '../../themes'; | 6 | import { ThemeType } from '../../themes'; |
5 | import { todoActions } from './actions'; | 7 | import { todoActions } from './actions'; |
@@ -13,7 +15,7 @@ import { | |||
13 | } from '../../config'; | 15 | } from '../../config'; |
14 | import { isValidExternalURL } from '../../helpers/url-helpers'; | 16 | import { isValidExternalURL } from '../../helpers/url-helpers'; |
15 | import FeatureStore from '../utils/FeatureStore'; | 17 | import FeatureStore from '../utils/FeatureStore'; |
16 | import { createReactions } from '../../stores/lib/Reaction'; | 18 | import Reaction, { createReactions } from '../../stores/lib/Reaction'; |
17 | import { createActionBindings } from '../utils/ActionBinding'; | 19 | import { createActionBindings } from '../utils/ActionBinding'; |
18 | import { IPC, TODOS_ROUTES } from './constants'; | 20 | import { IPC, TODOS_ROUTES } from './constants'; |
19 | import UserAgent from '../../models/UserAgent'; | 21 | import UserAgent from '../../models/UserAgent'; |
@@ -23,16 +25,20 @@ const debug = require('../../preload-safe-debug')( | |||
23 | ); | 25 | ); |
24 | 26 | ||
25 | export default class TodoStore extends FeatureStore { | 27 | export default class TodoStore extends FeatureStore { |
26 | @observable stores = null; | 28 | @observable stores: any = null; |
27 | 29 | ||
28 | @observable isFeatureActive = false; | 30 | @observable isFeatureActive = false; |
29 | 31 | ||
30 | @observable webview = null; | 32 | @observable webview: Webview | undefined; |
31 | 33 | ||
32 | @observable userAgentModel = new UserAgent(); | 34 | @observable userAgentModel = new UserAgent(); |
33 | 35 | ||
34 | isInitialized = false; | 36 | isInitialized = false; |
35 | 37 | ||
38 | actions: Actions | undefined; | ||
39 | |||
40 | _allReactions: Reaction[] | undefined; | ||
41 | |||
36 | constructor() { | 42 | constructor() { |
37 | super(); | 43 | super(); |
38 | 44 | ||
@@ -142,7 +148,7 @@ export default class TodoStore extends FeatureStore { | |||
142 | @action stop() { | 148 | @action stop() { |
143 | super.stop(); | 149 | super.stop(); |
144 | debug('TodoStore::stop'); | 150 | debug('TodoStore::stop'); |
145 | this.reset(); | 151 | // this.reset(); // TODO - [TECH DEBT][PROP NOT IN CLASS] check it later |
146 | this.isFeatureActive = false; | 152 | this.isFeatureActive = false; |
147 | } | 153 | } |
148 | 154 | ||
@@ -184,7 +190,10 @@ export default class TodoStore extends FeatureStore { | |||
184 | } | 190 | } |
185 | }; | 191 | }; |
186 | 192 | ||
187 | @action _handleClientMessage = ({ channel, message = {} }) => { | 193 | @action _handleClientMessage = ({ |
194 | channel, | ||
195 | message = { action: '', data: { url: '', serviceId: '' } }, | ||
196 | }) => { | ||
188 | debug('_handleClientMessage', channel, message); | 197 | debug('_handleClientMessage', channel, message); |
189 | switch (message.action) { | 198 | switch (message.action) { |
190 | case 'todos:initialized': | 199 | case 'todos:initialized': |
@@ -195,7 +204,7 @@ export default class TodoStore extends FeatureStore { | |||
195 | break; | 204 | break; |
196 | default: | 205 | default: |
197 | debug('Other message received', channel, message); | 206 | debug('Other message received', channel, message); |
198 | if (this.stores.services.isTodosServiceAdded) { | 207 | if (this.stores.services.isTodosServiceAdded && this.actions) { |
199 | this.actions.service.handleIPCMessage({ | 208 | this.actions.service.handleIPCMessage({ |
200 | serviceId: this.stores.services.isTodosServiceAdded.id, | 209 | serviceId: this.stores.services.isTodosServiceAdded.id, |
201 | channel, | 210 | channel, |
@@ -206,6 +215,9 @@ export default class TodoStore extends FeatureStore { | |||
206 | }; | 215 | }; |
207 | 216 | ||
208 | _handleNewWindowEvent = ({ url }) => { | 217 | _handleNewWindowEvent = ({ url }) => { |
218 | if (!this.actions) { | ||
219 | return; | ||
220 | } | ||
209 | this.actions.app.openExternalUrl({ url }); | 221 | this.actions.app.openExternalUrl({ url }); |
210 | }; | 222 | }; |
211 | 223 | ||
@@ -222,15 +234,19 @@ export default class TodoStore extends FeatureStore { | |||
222 | _openDevTools = () => { | 234 | _openDevTools = () => { |
223 | debug('_openDevTools'); | 235 | debug('_openDevTools'); |
224 | 236 | ||
225 | const webview = document.querySelector('#todos-panel webview'); | 237 | const webview = document.querySelector<Webview>('#todos-panel webview'); |
226 | if (webview) webview.openDevTools(); | 238 | if (webview) { |
239 | webview.openDevTools(); | ||
240 | } | ||
227 | }; | 241 | }; |
228 | 242 | ||
229 | _reload = () => { | 243 | _reload = () => { |
230 | debug('_reload'); | 244 | debug('_reload'); |
231 | 245 | ||
232 | const webview = document.querySelector('#todos-panel webview'); | 246 | const webview = document.querySelector<Webview>('#todos-panel webview'); |
233 | if (webview) webview.reload(); | 247 | if (webview) { |
248 | webview.reload(); | ||
249 | } | ||
234 | }; | 250 | }; |
235 | 251 | ||
236 | // Todos client message handlers | 252 | // Todos client message handlers |
@@ -260,7 +276,9 @@ export default class TodoStore extends FeatureStore { | |||
260 | if (url) { | 276 | if (url) { |
261 | this.stores.services.one(serviceId).webview.loadURL(url); | 277 | this.stores.services.one(serviceId).webview.loadURL(url); |
262 | } | 278 | } |
263 | this.actions.service.setActive({ serviceId }); | 279 | if (this.actions) { |
280 | this.actions.service.setActive({ serviceId }); | ||
281 | } | ||
264 | }; | 282 | }; |
265 | 283 | ||
266 | // Reactions | 284 | // Reactions |
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, |