diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-09-18 11:15:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-18 11:15:25 +0200 |
commit | d4101a48b3eee8b1fb177831aa02a4b4fbec2588 (patch) | |
tree | c92f2fbe91197fde8589207463d0d6526b4ff76b /src/features/workspaces | |
parent | 5.6.3-nightly.6 [skip ci] (diff) | |
download | ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.gz ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.tar.zst ferdium-app-d4101a48b3eee8b1fb177831aa02a4b4fbec2588.zip |
chore: convert various files from JS to TS (#1959)
Diffstat (limited to 'src/features/workspaces')
-rw-r--r-- | src/features/workspaces/actions.js | 27 | ||||
-rw-r--r-- | src/features/workspaces/actions.ts | 30 | ||||
-rw-r--r-- | src/features/workspaces/api.ts (renamed from src/features/workspaces/api.js) | 44 | ||||
-rw-r--r-- | src/features/workspaces/constants.ts (renamed from src/features/workspaces/constants.js) | 0 | ||||
-rw-r--r-- | src/features/workspaces/index.ts (renamed from src/features/workspaces/index.js) | 6 | ||||
-rw-r--r-- | src/features/workspaces/models/Workspace.ts (renamed from src/features/workspaces/models/Workspace.js) | 4 |
6 files changed, 67 insertions, 44 deletions
diff --git a/src/features/workspaces/actions.js b/src/features/workspaces/actions.js deleted file mode 100644 index 5b5db422e..000000000 --- a/src/features/workspaces/actions.js +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import Workspace from './models/Workspace'; | ||
3 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | ||
4 | |||
5 | export const workspaceActions = createActionsFromDefinitions({ | ||
6 | edit: { | ||
7 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
8 | }, | ||
9 | create: { | ||
10 | name: PropTypes.string.isRequired, | ||
11 | }, | ||
12 | delete: { | ||
13 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
14 | }, | ||
15 | update: { | ||
16 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
17 | }, | ||
18 | activate: { | ||
19 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
20 | }, | ||
21 | deactivate: {}, | ||
22 | toggleWorkspaceDrawer: {}, | ||
23 | openWorkspaceSettings: {}, | ||
24 | toggleKeepAllWorkspacesLoadedSetting: {}, | ||
25 | }, PropTypes.checkPropTypes); | ||
26 | |||
27 | export default workspaceActions; | ||
diff --git a/src/features/workspaces/actions.ts b/src/features/workspaces/actions.ts new file mode 100644 index 000000000..5e7e6e721 --- /dev/null +++ b/src/features/workspaces/actions.ts | |||
@@ -0,0 +1,30 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import Workspace from './models/Workspace'; | ||
3 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | ||
4 | |||
5 | export const workspaceActions = createActionsFromDefinitions( | ||
6 | { | ||
7 | edit: { | ||
8 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
9 | }, | ||
10 | create: { | ||
11 | name: PropTypes.string.isRequired, | ||
12 | }, | ||
13 | delete: { | ||
14 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
15 | }, | ||
16 | update: { | ||
17 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
18 | }, | ||
19 | activate: { | ||
20 | workspace: PropTypes.instanceOf(Workspace).isRequired, | ||
21 | }, | ||
22 | deactivate: {}, | ||
23 | toggleWorkspaceDrawer: {}, | ||
24 | openWorkspaceSettings: {}, | ||
25 | toggleKeepAllWorkspacesLoadedSetting: {}, | ||
26 | }, | ||
27 | PropTypes.checkPropTypes, | ||
28 | ); | ||
29 | |||
30 | export default workspaceActions; | ||
diff --git a/src/features/workspaces/api.js b/src/features/workspaces/api.ts index 322695ed2..8447fc247 100644 --- a/src/features/workspaces/api.js +++ b/src/features/workspaces/api.ts | |||
@@ -12,12 +12,14 @@ export const workspaceApi = { | |||
12 | debug('getUserWorkspaces GET', url); | 12 | debug('getUserWorkspaces GET', url); |
13 | const result = await sendAuthRequest(url, { method: 'GET' }); | 13 | const result = await sendAuthRequest(url, { method: 'GET' }); |
14 | debug('getUserWorkspaces RESULT', result); | 14 | debug('getUserWorkspaces RESULT', result); |
15 | if (!result.ok) throw result; | 15 | if (!result.ok) { |
16 | throw new Error("Couldn't getUserWorkspaces"); | ||
17 | } | ||
16 | const workspaces = await result.json(); | 18 | const workspaces = await result.json(); |
17 | return workspaces.map((data) => new Workspace(data)); | 19 | return workspaces.map(data => new Workspace(data)); |
18 | }, | 20 | }, |
19 | 21 | ||
20 | createWorkspace: async (name) => { | 22 | createWorkspace: async name => { |
21 | const url = `${apiBase()}/workspace`; | 23 | const url = `${apiBase()}/workspace`; |
22 | const options = { | 24 | const options = { |
23 | method: 'POST', | 25 | method: 'POST', |
@@ -26,20 +28,24 @@ export const workspaceApi = { | |||
26 | debug('createWorkspace POST', url, options); | 28 | debug('createWorkspace POST', url, options); |
27 | const result = await sendAuthRequest(url, options); | 29 | const result = await sendAuthRequest(url, options); |
28 | debug('createWorkspace RESULT', result); | 30 | debug('createWorkspace RESULT', result); |
29 | if (!result.ok) throw result; | 31 | if (!result.ok) { |
32 | throw new Error("Couldn't createWorkspace"); | ||
33 | } | ||
30 | return new Workspace(await result.json()); | 34 | return new Workspace(await result.json()); |
31 | }, | 35 | }, |
32 | 36 | ||
33 | deleteWorkspace: async (workspace) => { | 37 | deleteWorkspace: async workspace => { |
34 | const url = `${apiBase()}/workspace/${workspace.id}`; | 38 | const url = `${apiBase()}/workspace/${workspace.id}`; |
35 | debug('deleteWorkspace DELETE', url); | 39 | debug('deleteWorkspace DELETE', url); |
36 | const result = await sendAuthRequest(url, { method: 'DELETE' }); | 40 | const result = await sendAuthRequest(url, { method: 'DELETE' }); |
37 | debug('deleteWorkspace RESULT', result); | 41 | debug('deleteWorkspace RESULT', result); |
38 | if (!result.ok) throw result; | 42 | if (!result.ok) { |
43 | throw new Error("Couldn't deleteWorkspace"); | ||
44 | } | ||
39 | return true; | 45 | return true; |
40 | }, | 46 | }, |
41 | 47 | ||
42 | updateWorkspace: async (workspace) => { | 48 | updateWorkspace: async workspace => { |
43 | const url = `${apiBase()}/workspace/${workspace.id}`; | 49 | const url = `${apiBase()}/workspace/${workspace.id}`; |
44 | const options = { | 50 | const options = { |
45 | method: 'PUT', | 51 | method: 'PUT', |
@@ -48,15 +54,29 @@ export const workspaceApi = { | |||
48 | debug('updateWorkspace UPDATE', url, options); | 54 | debug('updateWorkspace UPDATE', url, options); |
49 | const result = await sendAuthRequest(url, options); | 55 | const result = await sendAuthRequest(url, options); |
50 | debug('updateWorkspace RESULT', result); | 56 | debug('updateWorkspace RESULT', result); |
51 | if (!result.ok) throw result; | 57 | if (!result.ok) { |
58 | throw new Error("Couldn't updateWorkspace"); | ||
59 | } | ||
52 | return new Workspace(await result.json()); | 60 | return new Workspace(await result.json()); |
53 | }, | 61 | }, |
54 | }; | 62 | }; |
55 | 63 | ||
56 | export const getUserWorkspacesRequest = new Request(workspaceApi, 'getUserWorkspaces'); | 64 | export const getUserWorkspacesRequest = new Request( |
57 | export const createWorkspaceRequest = new Request(workspaceApi, 'createWorkspace'); | 65 | workspaceApi, |
58 | export const deleteWorkspaceRequest = new Request(workspaceApi, 'deleteWorkspace'); | 66 | 'getUserWorkspaces', |
59 | export const updateWorkspaceRequest = new Request(workspaceApi, 'updateWorkspace'); | 67 | ); |
68 | export const createWorkspaceRequest = new Request( | ||
69 | workspaceApi, | ||
70 | 'createWorkspace', | ||
71 | ); | ||
72 | export const deleteWorkspaceRequest = new Request( | ||
73 | workspaceApi, | ||
74 | 'deleteWorkspace', | ||
75 | ); | ||
76 | export const updateWorkspaceRequest = new Request( | ||
77 | workspaceApi, | ||
78 | 'updateWorkspace', | ||
79 | ); | ||
60 | 80 | ||
61 | export const resetApiRequests = () => { | 81 | export const resetApiRequests = () => { |
62 | getUserWorkspacesRequest.reset(); | 82 | getUserWorkspacesRequest.reset(); |
diff --git a/src/features/workspaces/constants.js b/src/features/workspaces/constants.ts index 2d1416ee0..2d1416ee0 100644 --- a/src/features/workspaces/constants.js +++ b/src/features/workspaces/constants.ts | |||
diff --git a/src/features/workspaces/index.js b/src/features/workspaces/index.ts index 83e4d9049..ecca64b41 100644 --- a/src/features/workspaces/index.js +++ b/src/features/workspaces/index.ts | |||
@@ -12,10 +12,8 @@ export default function initWorkspaces(stores, actions) { | |||
12 | 12 | ||
13 | // Toggle workspace feature | 13 | // Toggle workspace feature |
14 | reaction( | 14 | reaction( |
15 | () => ( | 15 | () => features.features.isWorkspaceEnabled, |
16 | features.features.isWorkspaceEnabled | 16 | isEnabled => { |
17 | ), | ||
18 | (isEnabled) => { | ||
19 | if (isEnabled && !workspaceStore.isFeatureActive) { | 17 | if (isEnabled && !workspaceStore.isFeatureActive) { |
20 | debug('Initializing `workspaces` feature'); | 18 | debug('Initializing `workspaces` feature'); |
21 | workspaceStore.start(stores, actions); | 19 | workspaceStore.start(stores, actions); |
diff --git a/src/features/workspaces/models/Workspace.js b/src/features/workspaces/models/Workspace.ts index 14add9437..cd3918fba 100644 --- a/src/features/workspaces/models/Workspace.js +++ b/src/features/workspaces/models/Workspace.ts | |||
@@ -28,8 +28,10 @@ export default class Workspace { | |||
28 | services.push(KEEP_WS_LOADED_USID); | 28 | services.push(KEEP_WS_LOADED_USID); |
29 | } else if (data.saving && data.services.includes(KEEP_WS_LOADED_USID)) { | 29 | } else if (data.saving && data.services.includes(KEEP_WS_LOADED_USID)) { |
30 | // Don't keep loaded | 30 | // Don't keep loaded |
31 | services = services.filter((e) => e !== KEEP_WS_LOADED_USID); | 31 | services = services.filter(e => e !== KEEP_WS_LOADED_USID); |
32 | } | 32 | } |
33 | |||
34 | // @ts-expect-error Property 'replace' does not exist on type 'never[]'. | ||
33 | this.services.replace(services); | 35 | this.services.replace(services); |
34 | 36 | ||
35 | this.userId = data.userId; | 37 | this.userId = data.userId; |