leap, settings: store leap settings as array

This commit is contained in:
Matilde Park 2021-02-26 13:41:40 -05:00
parent 2db485705e
commit b4d82a9e8a
4 changed files with 9 additions and 9 deletions

View File

@ -18,7 +18,7 @@ export function useMigrateSettings(api: GlobalApi) {
const { display, remoteContentPolicy, calm } = useSettingsState(); const { display, remoteContentPolicy, calm } = useSettingsState();
return async () => { return async () => {
if (!localStorage.has("localReducer")) { if (!localStorage?.has("localReducer")) {
return; return;
} }

View File

@ -80,7 +80,7 @@ const otherIndex = function(config) {
logout: result('Log Out', '/~/logout', 'logout', null) logout: result('Log Out', '/~/logout', 'logout', null)
}; };
for(let cat of JSON.parse(config.categories)) { for(let cat of config.categories) {
if(idx[cat]) { if(idx[cat]) {
other.push(idx[cat]); other.push(idx[cat]);
} }

View File

@ -18,7 +18,7 @@ export interface SettingsState {
}; };
remoteContentPolicy: RemoteContentPolicy; remoteContentPolicy: RemoteContentPolicy;
leap: { leap: {
categories: string; categories: LeapCategories[];
} }
set: (fn: (state: SettingsState) => void) => void set: (fn: (state: SettingsState) => void) => void
}; };
@ -47,7 +47,7 @@ const useSettingsState = create<SettingsStateZus>((set) => ({
videoShown: true videoShown: true
}, },
leap: { leap: {
categories: JSON.stringify(leapCategories), categories: leapCategories,
}, },
set: (fn: (state: SettingsState) => void) => set(produce(fn)) set: (fn: (state: SettingsState) => void) => set(produce(fn))
})); }));

View File

@ -51,7 +51,7 @@ const settingsSel = selectSettingsState(["leap", "set"]);
export function LeapSettings(props: { api: GlobalApi; }) { export function LeapSettings(props: { api: GlobalApi; }) {
const { api } = props; const { api } = props;
const { leap, set: setSettingsState } = useSettingsState(settingsSel); const { leap, set: setSettingsState } = useSettingsState(settingsSel);
const categories = JSON.parse(leap.categories) as LeapCategories[]; const categories = leap.categories as LeapCategories[];
const missing = _.difference(leapCategories, categories); const missing = _.difference(leapCategories, categories);
console.log(categories); console.log(categories);
@ -70,7 +70,7 @@ export function LeapSettings(props: { api: GlobalApi; }) {
(acc, { display, category }) => (display ? [...acc, category] : acc), (acc, { display, category }) => (display ? [...acc, category] : acc),
[] as LeapCategories[] [] as LeapCategories[]
); );
await api.settings.putEntry('leap', 'categories', JSON.stringify(result)); await api.settings.putEntry('leap', 'categories', result);
}; };
return ( return (