Improve settings page

This commit is contained in:
Andras Schmelczer 2023-05-27 13:35:41 +01:00
commit cd9aff0362
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
4 changed files with 89 additions and 26 deletions

View file

@ -1,9 +1,8 @@
export const persist = <T extends Record<string, number>>(wrapee: T): T => {
const initialState = { ...wrapee };
const keys = Object.keys(wrapee);
const keysToShortKeys = Object.fromEntries(
keys.map((key, i) => [key, String.fromCharCode(65 + i)])
keys.map((key, i) => [key, String.fromCharCode(97 + i)])
);
const params = new URLSearchParams(window.location.search);
@ -25,11 +24,7 @@ export const persist = <T extends Record<string, number>>(wrapee: T): T => {
set: (target, key: string, value: number) => {
const params = new URLSearchParams(window.location.search);
if (initialState[key] === value) {
params.delete(keysToShortKeys[key]);
} else {
params.set(keysToShortKeys[key], value.toString());
}
params.set(keysToShortKeys[key], value.toString());
(target as any)[key] = value;