fix(settings): settings store initialization

This commit is contained in:
4gray committed 2024-12-21 21:35:17 +01:00
1 parent b565636189
commit b70d87faf2
3 files changed
+14 -20

No files matched your search

+8 -8
View File
@@ -1,8 +1,8 @@
import { computed, inject } from '@angular/core';
import { inject } from '@angular/core';
import {
patchState,
signalStore,
withComputed,
withHooks,
withMethods,
withState,
} from '@ngrx/signals';
@@ -28,11 +28,6 @@ const DEFAULT_SETTINGS: Settings = {
export const SettingsStore = signalStore(
{ providedIn: 'root' },
withState<Settings>(DEFAULT_SETTINGS),
withComputed((store) => ({
player: computed(() => store.player()),
showCaptions: computed(() => store.showCaptions()),
theme: computed(() => store.theme()),
})),
withMethods((store, storage = inject(StorageMap)) => ({
async loadSettings() {
const stored = await firstValueFrom(
@@ -64,5 +59,10 @@ export const SettingsStore = signalStore(
epgUrl: store.epgUrl(),
};
},
}))
})),
withHooks({
onInit(store) {
store.loadSettings();
},
})
);
+1 -2
View File
@@ -178,8 +178,7 @@ export class SettingsComponent implements OnInit {
/**
* Sets saved settings from the indexed db store
*/
async setSettings() {
await this.settingsStore.loadSettings();
setSettings() {
const currentSettings = this.settingsStore.getSettings();
this.settingsForm.patchValue(currentSettings);
@@ -167,15 +167,10 @@ export class NavigationBarComponent implements OnChanges {
}
openSettings(): void {
this.dialog
.open(SettingsComponent, {
width: '1000px',
height: '90%',
data: { isDialog: true },
})
.afterClosed()
.subscribe(() => {
this.settingsStore.loadSettings();
});
this.dialog.open(SettingsComponent, {
width: '1000px',
height: '90%',
data: { isDialog: true },
});
}
}