diff --git a/src/Model/Global/settingsModel.ts b/src/Model/Global/settingsModel.ts index 62179640..9c075d0d 100644 --- a/src/Model/Global/settingsModel.ts +++ b/src/Model/Global/settingsModel.ts @@ -1,9 +1,8 @@ import StorageModel, { StorageModelSubPaths, filePaths } from "./storageModel"; import { UUID } from "../../react"; +import ContactListModel from "./contactListModel"; export default class SettingsModel { - readonly storageModel: StorageModel; - // data username: string = ""; userid: string = ""; @@ -30,95 +29,94 @@ export default class SettingsModel { readonly setName = (newValue: string): void => { this.username = newValue; - this.storeSetting("username", newValue); + this.storeSetting("username", newValue); + this.contactListModel.storeContact(this.userid,newValue); }; readonly setFirstDayOfWeek = (newValue: string): void => { - this.firstDayOfWeek = newValue; - this.storeSetting("firstDayOfWeek", newValue); + this.firstDayOfWeek = newValue; + this.storeSetting("firstDayOfWeek", newValue); }; readonly setLanguage = (newValue: string): void => { - this.language = newValue; - this.storeSetting("language", newValue); + this.language = newValue; + this.storeSetting("language", newValue); }; readonly setTheme = (newValue: string): void => { - this.theme = newValue; - this.storeSetting("theme", newValue); + this.theme = newValue; + this.storeSetting("theme", newValue); }; // load private readonly readSetting = ( - pathName: keyof typeof filePaths.settingsModel, + pathName: keyof typeof filePaths.settingsModel, ): string | null => { - const path = StorageModel.getPath( - StorageModelSubPaths.SettingsModel, - filePaths.settingsModel[pathName], - ); - return this.storageModel.read(path); + const path = StorageModel.getPath( + StorageModelSubPaths.SettingsModel, + filePaths.settingsModel[pathName], + ); + return this.storageModel.read(path); }; readonly loadId = (): void => { - const content: string | null = this.readSetting("userid"); - const id = content ?? UUID(); - if (content) this.userid = content; - else this.setId(id); + const content: string | null = this.readSetting("userid"); + const id = content ?? UUID(); + if (content) this.userid = content; + else this.setId(id); }; readonly loadUsername = (): void => { - const content: string | null = this.readSetting("username"); - this.username = content ?? ""; + const content: string | null = this.readSetting("username"); + this.username = content ?? ""; }; readonly loadFirstDayofWeek = (): void => { - const content: string | null = this.readSetting("firstDayOfWeek"); - this.firstDayOfWeek = content ?? "0"; + const content: string | null = this.readSetting("firstDayOfWeek"); + this.firstDayOfWeek = content ?? "0"; }; readonly loadLanguage = (): void => { - const content: string | null = this.readSetting("language"); - this.language = content ?? SettingsModel.getSystemLanguage(); + const content: string | null = this.readSetting("language"); + this.language = content ?? SettingsModel.getSystemLanguage(); }; readonly loadTheme = (): void => { - const content: string | null = this.readSetting("theme"); - this.theme = content ?? ThemeSettings.System; + const content: string | null = this.readSetting("theme"); + this.theme = content ?? ThemeSettings.System; }; // init - constructor(storageModel: StorageModel) { - this.storageModel = storageModel; - - this.loadId(); - this.loadUsername(); - this.loadFirstDayofWeek(); - this.loadLanguage(); - this.loadTheme(); + constructor(public storageModel: StorageModel, public contactListModel: ContactListModel) { + this.loadId(); + this.loadUsername(); + this.loadFirstDayofWeek(); + this.loadLanguage(); + this.loadTheme(); } static getSystemLanguage(): Languages { - switch (navigator.language.substring(0, 2)) { - case "de": - return Languages.German; - case "es": - return Languages.Spanish; - default: - return Languages.English; - } + switch (navigator.language.substring(0, 2)) { + case "de": + return Languages.German; + case "es": + return Languages.Spanish; + default: + return Languages.English; + } } } export enum Languages { English = "en", - German = "de", - Spanish = "es", + German = "de", + Spanish = "es", } export enum ThemeSettings { Dark = "dark", - Light = "light", - System = "system", - Dynamic = "dynamic", - Black = "black", + Light = "light", + System = "system", + Dynamic = "dynamic", + Black = "black", } diff --git a/src/index.tsx b/src/index.tsx index a0346eea..6edcd023 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -25,8 +25,8 @@ import ContactListViewModel from "./ViewModel/Global/contactViewModel"; // models const storageModel = new StorageModel(); -const settingsModel = new SettingsModel(storageModel); const contactListModel = new ContactListModel(storageModel); +const settingsModel = new SettingsModel(storageModel, contactListModel); const connectionModel = new ConnectionModel(storageModel); const chatListModel = new ChatListModel( storageModel, @@ -46,8 +46,8 @@ const coreViewModel = new CoreViewModel( ); const storageViewModel = new StorageViewModel(coreViewModel); -const settingsViewModel = new SettingsViewModel(coreViewModel, settingsModel); const contactListViewModel = new ContactListViewModel(contactListModel); +const settingsViewModel = new SettingsViewModel(coreViewModel, settingsModel); const connectionViewModel = new ConnectionViewModel(coreViewModel); const chatListViewModel = new ChatListViewModel( coreViewModel,