You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Ombi/src/Ombi/ClientApp/src/app/state/customization/customization.state.ts

34 lines
1.1 KiB

import { Action, State, StateContext } from "@ngxs/store";
import { LoadSettings, UpdateSettings } from "./customization.actions";
import { CUSTOMIZATION_STATE_TOKEN } from "./types";
import { ICustomizationSettings } from "../../interfaces";
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { SettingsService } from "../../services";
import { produce } from 'immer';
import { tap } from "rxjs/operators";
@State({
name: CUSTOMIZATION_STATE_TOKEN
})
@Injectable()
export class CustomizationState {
constructor(private settingsService: SettingsService) { }
@Action(LoadSettings)
public load({ setState }: StateContext<ICustomizationSettings>): Observable<ICustomizationSettings> {
return this.settingsService.getCustomization().pipe(
tap(settings =>
setState(settings)
)
);
}
@Action(UpdateSettings)
public update({ setState }: StateContext<ICustomizationSettings>, { settings }: UpdateSettings): Observable<boolean> {
return this.settingsService.saveCustomization(settings).pipe(
tap(() => setState(settings))
);
}
}