Fix lobby filter reset persistence

pull/9164/head
Benedikt Werner 2021-06-13 07:00:14 +02:00
parent df23ba3a6c
commit f8ef8a5c2b
No known key found for this signature in database
GPG Key ID: 1DBFF0F8E9E121EB
3 changed files with 7 additions and 4 deletions

View File

@ -33,9 +33,10 @@ export default class Filter {
};
};
save = (form: HTMLFormElement) => {
const lines = toFormLines(form);
this.store.set(lines);
save = (form: HTMLFormElement | null) => {
const lines = form && toFormLines(form);
if (lines) this.store.set(lines);
else this.store.remove();
this.set(lines);
this.root.onSetFilter();
};

View File

@ -7,6 +7,7 @@ export interface FormObject {
export interface FormStore {
get: () => FormLines | null;
set: (lines: FormLines) => void;
remove: () => void;
}
export const toFormLines = (form: HTMLFormElement): FormLines =>
@ -24,4 +25,5 @@ export const toFormObject = (lines: FormLines): FormObject =>
export const makeStore = (storage: LichessStorage): FormStore => ({
get: () => JSON.parse(storage.get() || 'null') as FormLines,
set: lines => storage.set(JSON.stringify(lines)),
remove: () => storage.remove(),
});

View File

@ -27,7 +27,7 @@ function initialize(ctrl: LobbyController, el: HTMLElement) {
.find('form')
.on('reset', (e: Event) => {
e.preventDefault();
ctrl.filter.set(null);
ctrl.filter.save(null);
ctrl.filter.open = false;
ctrl.redraw();
})