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.ts45
1 files changed, 25 insertions, 20 deletions
diff --git a/packages/main/src/stores/Profile.ts b/packages/main/src/stores/Profile.ts
index 4705862..eaf23c4 100644
--- a/packages/main/src/stores/Profile.ts
+++ b/packages/main/src/stores/Profile.ts
@@ -18,34 +18,39 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import type { ProfileSnapshotIn } from '@sophie/shared'; 21import {
22 profile as originalProfile,
23 ProfileSettingsSnapshotIn,
24} from '@sophie/shared';
25import { getSnapshot, Instance } from 'mobx-state-tree';
22 26
27import SettingsWithId from '../utils/SettingsWithId';
23import generateId from '../utils/generateId'; 28import generateId from '../utils/generateId';
24 29
25export interface PartialProfileSnapshotIn 30export interface ProfileConfig extends ProfileSettingsSnapshotIn {
26 extends Omit<ProfileSnapshotIn, 'id'> {
27 id?: string | undefined; 31 id?: string | undefined;
28} 32}
29 33
34export const profile = originalProfile.views((self) => ({
35 get config(): ProfileConfig {
36 const { id, settings } = self;
37 return { ...getSnapshot(settings), id };
38 },
39}));
40
41export interface Profile extends Instance<typeof profile> {}
42
43export type ProfileSettingsSnapshotWithId =
44 SettingsWithId<ProfileSettingsSnapshotIn>;
45
30export function addMissingProfileIds( 46export function addMissingProfileIds(
31 partialProfiles: PartialProfileSnapshotIn[] | undefined, 47 profileConfigs: ProfileConfig[] | undefined,
32): ProfileSnapshotIn[] { 48): ProfileSettingsSnapshotWithId[] {
33 return (partialProfiles ?? []).map((profile) => { 49 return (profileConfigs ?? []).map((profileConfig) => {
34 const { name } = profile; 50 const { id, ...settings } = profileConfig;
35 let { id } = profile;
36 if (typeof id === 'undefined') {
37 id = generateId(name);
38 }
39 return { 51 return {
40 ...profile, 52 id: typeof id === 'undefined' ? generateId(settings.name) : id,
41 id, 53 settings,
42 }; 54 };
43 }); 55 });
44} 56}
45
46export type {
47 Profile,
48 ProfileSnapshotOut,
49 ProfileSnapshotIn,
50} from '@sophie/shared';
51export { profile } from '@sophie/shared';