change own contact when name setting changes
This commit is contained in:
@@ -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",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user