Reset overwrite url if it is invalid (does fail to reach sfu)

This commit is contained in:
Timo K
2025-11-27 15:06:36 +01:00
parent 90d4b6a6ce
commit bd3e91738e
4 changed files with 45 additions and 10 deletions

View File

@@ -34,15 +34,20 @@ export class Setting<T> {
this._value$ = new BehaviorSubject(initialValue);
this.value$ = this._value$;
this._lastUpdateReason$ = new BehaviorSubject<string | null>(null);
this.lastUpdateReason$ = this._lastUpdateReason$;
}
private readonly key: string;
private readonly _value$: BehaviorSubject<T>;
private readonly _lastUpdateReason$: BehaviorSubject<string | null>;
public readonly value$: Behavior<T>;
public readonly lastUpdateReason$: Behavior<string | null>;
public readonly setValue = (value: T): void => {
public readonly setValue = (value: T, reason?: string): void => {
this._value$.next(value);
this._lastUpdateReason$.next(reason ?? null);
localStorage.setItem(this.key, JSON.stringify(value));
};
public readonly getValue = (): T => {
@@ -57,6 +62,19 @@ export function useSetting<T>(setting: Setting<T>): [T, (value: T) => void] {
return [useBehavior(setting.value$), setting.setValue];
}
/**
* React hook that returns a settings's current value and a setter.
*/
export function useSettingWithLastUpdateReason<T>(
setting: Setting<T>,
): [T, (value: T) => void, string | null] {
return [
useBehavior(setting.value$),
setting.setValue,
useBehavior(setting.lastUpdateReason$),
];
}
// null = undecided
export const optInAnalytics = new Setting<boolean | null>(
"opt-in-analytics",