added settings bindings
This commit is contained in:
parent
24ed03f66a
commit
97976a1f68
|
@ -17,7 +17,7 @@
|
|||
<input class="sub-section__checkbox" [(ngModel)]="disableAvatarNotificationsEnabled"
|
||||
(change)="onDisableAvatarNotificationsChanged()" type="checkbox" name="disableAvatarNotifications"
|
||||
value="disableAvatarNotifications" id="disableAvatarNotifications">
|
||||
<label class="noselect sub-section__label" for="disableAvatarNotifications">disable avatar(s) notifications</label>
|
||||
<label class="noselect sub-section__label" for="disableAvatarNotifications">disable all avatar(s) notifications</label>
|
||||
<br>
|
||||
|
||||
<input class="sub-section__checkbox" [(ngModel)]="disableSoundsEnabled"
|
||||
|
|
|
@ -31,11 +31,17 @@ export class SettingsComponent implements OnInit {
|
|||
ngOnInit() {
|
||||
this.version = environment.VERSION;
|
||||
|
||||
const settings = this.toolsService.getSettings();
|
||||
|
||||
this.notificationSounds = this.userNotificationsService.getAllNotificationSounds();
|
||||
this.notificationSoundId = this.toolsService.getSettings().notificationSoundFileId;
|
||||
this.notificationSoundId = settings.notificationSoundFileId;
|
||||
this.notificationForm = this.formBuilder.group({
|
||||
countryControl: [this.notificationSounds[this.notificationSoundId].id]
|
||||
});
|
||||
|
||||
this.disableAutofocusEnabled = settings.disableAutofocus;
|
||||
this.disableAvatarNotificationsEnabled = settings.disableAvatarNotifications;
|
||||
this.disableSoundsEnabled = settings.disableSounds;
|
||||
}
|
||||
|
||||
onChange(soundId: string) {
|
||||
|
@ -57,15 +63,21 @@ export class SettingsComponent implements OnInit {
|
|||
}
|
||||
|
||||
onDisableAutofocusChanged(){
|
||||
|
||||
let settings = this.toolsService.getSettings();
|
||||
settings.disableAutofocus = this.disableAutofocusEnabled;
|
||||
this.toolsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
onDisableAvatarNotificationsChanged(){
|
||||
|
||||
let settings = this.toolsService.getSettings();
|
||||
settings.disableAvatarNotifications = this.disableAvatarNotificationsEnabled;
|
||||
this.toolsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
onDisableSoundsEnabledChanged(){
|
||||
|
||||
let settings = this.toolsService.getSettings();
|
||||
settings.disableSounds = this.disableSoundsEnabled;
|
||||
this.toolsService.saveSettings(settings);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,8 +17,11 @@ export class SaveSettings {
|
|||
|
||||
export class AccountSettings {
|
||||
accountId: string;
|
||||
displayMention: boolean = true;
|
||||
displayMention: boolean = true;
|
||||
displayNotifications: boolean = true;
|
||||
|
||||
disableAvatarNotifications = false;
|
||||
|
||||
lastMentionCreationDate: string;
|
||||
lastNotificationCreationDate: string;
|
||||
|
||||
|
@ -27,7 +30,10 @@ export class AccountSettings {
|
|||
}
|
||||
|
||||
export class GlobalSettings {
|
||||
disableAllNotifications = false;
|
||||
disableAutofocus = false;
|
||||
disableAvatarNotifications = false;
|
||||
disableSounds = false;
|
||||
|
||||
notificationSoundFileId: string = '0';
|
||||
accountSettings: AccountSettings[] = [];
|
||||
}
|
||||
|
@ -53,9 +59,9 @@ export class SettingsState {
|
|||
@Action(RemoveAccountSettings)
|
||||
RemoveAccountSettings(ctx: StateContext<SettingsStateModel>, action: RemoveAccountSettings){
|
||||
const state = ctx.getState();
|
||||
const newSettings = new GlobalSettings();
|
||||
let newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = state.settings.disableAllNotifications;
|
||||
newSettings = this.setGlobalSettingsValues(newSettings, state.settings);
|
||||
newSettings.accountSettings = [...state.settings.accountSettings.filter(x => x.accountId !== action.accountId)];
|
||||
|
||||
ctx.patchState({
|
||||
|
@ -66,9 +72,9 @@ export class SettingsState {
|
|||
@Action(SaveAccountSettings)
|
||||
SaveAccountSettings(ctx: StateContext<SettingsStateModel>, action: SaveAccountSettings){
|
||||
const state = ctx.getState();
|
||||
const newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = state.settings.disableAllNotifications;
|
||||
let newSettings = new GlobalSettings();
|
||||
newSettings = this.setGlobalSettingsValues(newSettings, state.settings);
|
||||
newSettings.accountSettings = [...state.settings.accountSettings.filter(x => x.accountId !== action.accountSettings.accountId), action.accountSettings];
|
||||
|
||||
ctx.patchState({
|
||||
|
@ -79,14 +85,23 @@ export class SettingsState {
|
|||
@Action(SaveSettings)
|
||||
SaveSettings(ctx: StateContext<SettingsStateModel>, action: SaveSettings){
|
||||
const state = ctx.getState();
|
||||
const newSettings = new GlobalSettings();
|
||||
|
||||
newSettings.disableAllNotifications = action.settings.disableAllNotifications;
|
||||
newSettings.notificationSoundFileId = action.settings.notificationSoundFileId;
|
||||
let newSettings = new GlobalSettings();
|
||||
newSettings = this.setGlobalSettingsValues(newSettings, action.settings);
|
||||
newSettings.accountSettings = [...state.settings.accountSettings];
|
||||
|
||||
ctx.patchState({
|
||||
settings: newSettings
|
||||
});
|
||||
}
|
||||
|
||||
private setGlobalSettingsValues(newSettings: GlobalSettings, oldSettings: GlobalSettings): GlobalSettings {
|
||||
|
||||
newSettings.disableAutofocus = oldSettings.disableAutofocus;
|
||||
newSettings.disableAvatarNotifications = oldSettings.disableAvatarNotifications;
|
||||
newSettings.disableSounds = oldSettings.disableSounds;
|
||||
newSettings.notificationSoundFileId = oldSettings.notificationSoundFileId;
|
||||
|
||||
return newSettings;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue