-
Notifications
You must be signed in to change notification settings - Fork 13
/
App.state.ts
129 lines (115 loc) · 3.74 KB
/
App.state.ts
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Action, Selector, State, StateContext } from '@ngxs/store';
import { ThemeService } from 'src/app/services/theme.service';
import { Theme } from 'src/app/shared/models/enumerables/Theme';
export class ServiceWorkerNotificationDisplayed {
public static readonly type: string = '[App State] Service Worker Notification displayed';
}
export class SetVersion {
public static readonly type: string = '[App State] Set Version';
constructor(public version: string) {}
}
export class SetDisplayedNotificationVersion {
public static readonly type: string = '[App State] Set Displayed Notification Version';
constructor(public version: number) {}
}
export class SetSendFeedback {
public static readonly type: string = '[App State] Set Send Feedback';
constructor(public sendFeedback: boolean) {}
}
export class SetTheme {
public static readonly type: string = '[App State] Set activeTheme';
constructor(public activeTheme: Theme) {}
}
export class InitTheme {
public static readonly type: string = '[App State] Init activeTheme';
}
export interface AppStateModel {
serviceWorkerNotificationDisplayed: boolean;
version: string;
displayedNotificationVersion: number;
/**
* Please note that this string is also used by Sentry (Raven-js) in order to determine if it is allowed to send BugReports
* If you want to edit this Property please also change it in app.modules.ts
*/
sendFeedback: boolean | null;
activeTheme: Theme;
}
@State<AppStateModel>({
name: 'appstate',
defaults: {
serviceWorkerNotificationDisplayed: false,
version: '0.0.0',
displayedNotificationVersion: 0,
sendFeedback: null,
activeTheme: Theme.magenta_light_theme
}
})
export class AppState {
constructor(private themeService: ThemeService) {}
@Selector()
public static serviceWorkerNotificationDisplayed(state: AppStateModel): boolean {
return state.serviceWorkerNotificationDisplayed;
}
@Selector()
public static version(state: AppStateModel): string {
return state.version;
}
@Selector()
public static activeTheme(state: AppStateModel): Theme {
return state.activeTheme;
}
@Selector()
public static displayedNotificationVersion(state: AppStateModel): number {
return state.displayedNotificationVersion;
}
@Selector()
public static sendFeedback(state: AppStateModel): boolean | null {
return state.sendFeedback;
}
@Action(ServiceWorkerNotificationDisplayed)
public serviceWorkerNotificationDisplayed(ctx: StateContext<AppStateModel>) {
const state = ctx.getState();
ctx.setState({
...state,
serviceWorkerNotificationDisplayed: true
});
}
@Action(SetVersion)
public setVersion(ctx: StateContext<AppStateModel>, action: SetVersion) {
const state = ctx.getState();
ctx.setState({
...state,
version: action.version
});
}
@Action(SetDisplayedNotificationVersion)
public setDisplayedNotificationVersion(ctx: StateContext<AppStateModel>, action: SetDisplayedNotificationVersion) {
const state = ctx.getState();
ctx.setState({
...state,
displayedNotificationVersion: action.version
});
}
@Action(SetSendFeedback)
public setSendFeedback(ctx: StateContext<AppStateModel>, action: SetSendFeedback) {
const state = ctx.getState();
ctx.setState({
...state,
sendFeedback: action.sendFeedback
});
}
@Action(SetTheme)
public setTheme(ctx: StateContext<AppStateModel>, action: SetTheme) {
const state = ctx.getState();
this.themeService.setTheme(action.activeTheme);
ctx.setState({
...state,
activeTheme: action.activeTheme
});
}
@Action(InitTheme)
public initTheme(ctx: StateContext<AppStateModel>) {
const state = ctx.getState();
this.themeService.setTheme(state.activeTheme);
}
}