diff options
Diffstat (limited to 'packages/main/src/stores/Profile.ts')
-rw-r--r-- | packages/main/src/stores/Profile.ts | 30 |
1 files changed, 7 insertions, 23 deletions
diff --git a/packages/main/src/stores/Profile.ts b/packages/main/src/stores/Profile.ts index ec2a64b..0fd486e 100644 --- a/packages/main/src/stores/Profile.ts +++ b/packages/main/src/stores/Profile.ts | |||
@@ -18,19 +18,17 @@ | |||
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | 20 | ||
21 | import { | 21 | import { Profile as ProfileBase } from '@sophie/shared'; |
22 | Profile as ProfileBase, | ||
23 | ProfileSettingsSnapshotIn, | ||
24 | } from '@sophie/shared'; | ||
25 | import { getSnapshot, Instance } from 'mobx-state-tree'; | 22 | import { getSnapshot, Instance } from 'mobx-state-tree'; |
26 | 23 | ||
27 | import generateId from '../utils/generateId'; | 24 | import overrideProps from '../utils/overrideProps'; |
28 | 25 | ||
29 | export interface ProfileConfig extends ProfileSettingsSnapshotIn { | 26 | import ProfileSettings from './ProfileSettings'; |
30 | id?: string | undefined; | 27 | import type ProfileConfig from './config/ProfileConfig'; |
31 | } | ||
32 | 28 | ||
33 | const Profile = ProfileBase.views((self) => ({ | 29 | const Profile = overrideProps(ProfileBase, { |
30 | settings: ProfileSettings, | ||
31 | }).views((self) => ({ | ||
34 | get config(): ProfileConfig { | 32 | get config(): ProfileConfig { |
35 | const { id, settings } = self; | 33 | const { id, settings } = self; |
36 | return { ...getSnapshot(settings), id }; | 34 | return { ...getSnapshot(settings), id }; |
@@ -44,17 +42,3 @@ const Profile = ProfileBase.views((self) => ({ | |||
44 | interface Profile extends Instance<typeof Profile> {} | 42 | interface Profile extends Instance<typeof Profile> {} |
45 | 43 | ||
46 | export default Profile; | 44 | export default Profile; |
47 | |||
48 | export type ProfileSettingsSnapshotWithId = [string, ProfileSettingsSnapshotIn]; | ||
49 | |||
50 | export function addMissingProfileIds( | ||
51 | profileConfigs: ProfileConfig[] | undefined, | ||
52 | ): ProfileSettingsSnapshotWithId[] { | ||
53 | return (profileConfigs ?? []).map((profileConfig) => { | ||
54 | const { id, ...settings } = profileConfig; | ||
55 | return [ | ||
56 | typeof id === 'undefined' ? generateId(settings.name) : id, | ||
57 | settings, | ||
58 | ]; | ||
59 | }); | ||
60 | } | ||