add settingsModel

This commit is contained in:
marlon-erler
2024-07-20 00:22:53 +02:00
parent d7d4f399a2
commit d209291f37
2 changed files with 45 additions and 2 deletions
+43
View File
@@ -1 +1,44 @@
// this file is responsible for all settings.
import StorageModel, { storageKeys } from "./storageModel";
export default class SettingsModel {
storageModel: StorageModel;
username: string;
firstDayOfWeek: number;
// set
setName(newValue: string): void {
this.username = newValue;
const path = storageKeys.username;
this.storageModel.store(path, newValue);
}
setFirstDayOfWeek(newValue: number): void {
this.firstDayOfWeek = newValue;
const path = storageKeys.firstDayOfWeek;
this.storageModel.storeStringifiable(path, newValue);
}
// restore
restoreUsername(): void {
const path = storageKeys.username;
const content = this.storageModel.restore(path);
this.username == content ?? "";
}
restoreFirstDayofWeek(): void {
const path = storageKeys.firstDayOfWeek;
const content = this.storageModel.restoreStringifiable(path);
this.firstDayOfWeek == content ?? 0;
}
// init
constructor(storageModel: StorageModel) {
this.storageModel = storageModel;
this.restoreUsername();
this.restoreFirstDayofWeek();
}
}
+1 -1
View File
@@ -95,7 +95,7 @@ export const storageKeys = {
socketAddress: `${DATA_VERSION}/connection/socket-address`,
// settings
userName: `${DATA_VERSION}/settings/user-name`,
username: `${DATA_VERSION}/settings/user-name`,
firstDayOfWeek: `${DATA_VERSION}/settings/first-day-of-week`,
// history