Tidy settings

This commit is contained in:
Hugh Nimmo-Smith
2024-11-07 18:24:13 +00:00
parent 190ac9be3d
commit cf3893bf52
3 changed files with 16 additions and 7 deletions

View File

@@ -70,10 +70,17 @@ export class Config {
private applyConfigToSettings(): void { private applyConfigToSettings(): void {
if (!this.config) return; if (!this.config) return;
// only the value from config if it hasn't been overridden // use the value from config if it hasn't been overridden
if (showNonMemberTiles.value === undefined) { const showNonMemberTilesSubscription = showNonMemberTiles.value.subscribe(
showNonMemberTiles.setValue(this.config.show_non_member_tiles); (val) => {
} if (val === undefined && this.config) {
// we don't persist the value to local storage so that it is set from the config
// file on every startup
showNonMemberTiles.setValue(this.config.show_non_member_tiles, false);
showNonMemberTilesSubscription.unsubscribe();
}
},
);
} }
public config?: ResolvedConfigOptions; public config?: ResolvedConfigOptions;

View File

@@ -246,7 +246,7 @@ export const SettingsModal: FC<Props> = ({
id="showNonMemberTiles" id="showNonMemberTiles"
type="checkbox" type="checkbox"
label={t("settings.show_non_member_tiles")} label={t("settings.show_non_member_tiles")}
checked={showNonMemberTiles} checked={!!showNonMemberTiles}
onChange={useCallback( onChange={useCallback(
(event: ChangeEvent<HTMLInputElement>): void => { (event: ChangeEvent<HTMLInputElement>): void => {
setShowNonMemberTiles(event.target.checked); setShowNonMemberTiles(event.target.checked);

View File

@@ -37,9 +37,11 @@ export class Setting<T> {
private readonly _value: BehaviorSubject<T>; private readonly _value: BehaviorSubject<T>;
public readonly value: Observable<T>; public readonly value: Observable<T>;
public readonly setValue = (value: T): void => { public readonly setValue = (value: T, persist = true): void => {
this._value.next(value); this._value.next(value);
localStorage.setItem(this.key, JSON.stringify(value)); if (persist) {
localStorage.setItem(this.key, JSON.stringify(value));
}
}; };
} }