aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/stores/Profile.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/stores/Profile.ts')
-rw-r--r--packages/main/src/stores/Profile.ts30
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
21import { 21import { Profile as ProfileBase } from '@sophie/shared';
22 Profile as ProfileBase,
23 ProfileSettingsSnapshotIn,
24} from '@sophie/shared';
25import { getSnapshot, Instance } from 'mobx-state-tree'; 22import { getSnapshot, Instance } from 'mobx-state-tree';
26 23
27import generateId from '../utils/generateId'; 24import overrideProps from '../utils/overrideProps';
28 25
29export interface ProfileConfig extends ProfileSettingsSnapshotIn { 26import ProfileSettings from './ProfileSettings';
30 id?: string | undefined; 27import type ProfileConfig from './config/ProfileConfig';
31}
32 28
33const Profile = ProfileBase.views((self) => ({ 29const 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) => ({
44interface Profile extends Instance<typeof Profile> {} 42interface Profile extends Instance<typeof Profile> {}
45 43
46export default Profile; 44export default Profile;
47
48export type ProfileSettingsSnapshotWithId = [string, ProfileSettingsSnapshotIn];
49
50export 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}