forked from Yadro/time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsStore.ts
More file actions
51 lines (42 loc) · 1.37 KB
/
SettingsStore.ts
File metadata and controls
51 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { makeAutoObservable } from 'mobx';
import SettingsModel, { DEFAULT_SETTINGS } from './models/SettingsModel';
import SettingsService from './SettingsService';
import { RootStore } from '../RootStore';
import { ISettings } from './models/ISettings';
export default class SettingsStore {
settings: SettingsModel = new SettingsModel(DEFAULT_SETTINGS);
private service: SettingsService = new SettingsService();
constructor(private rootStore: RootStore) {
makeAutoObservable(this);
}
addProfile(profile: string) {
this.settings.profiles.push(profile);
this.service.save(this.settings);
}
setSettings(newSettings: ISettings) {
const {
currentProfile,
numberOfWorkingHours,
showNotifications,
} = newSettings;
this.settings.numberOfWorkingHours = numberOfWorkingHours;
this.settings.showNotifications = showNotifications;
this.rootStore.tasksStore.removeReminder();
this.setActiveProfile(currentProfile);
this.service.save(this.settings);
}
setActiveProfile(profile: string) {
if (profile === this.settings.currentProfile) {
return;
}
this.rootStore.tasksStore.stopTimer();
this.settings.currentProfile = profile;
this.service.save(this.settings);
setTimeout(() => {
this.rootStore.loadTaskAndProjects();
});
}
restore() {
this.settings = this.service.getAll();
}
}