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();
return async () => {
if (!localStorage.has("localReducer")) {
if (!localStorage?.has("localReducer")) {
return;
}

View File

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

View File

@ -18,14 +18,14 @@ export interface SettingsState {
};
remoteContentPolicy: RemoteContentPolicy;
leap: {
categories: string;
categories: LeapCategories[];
}
set: (fn: (state: SettingsState) => void) => void
};
export type SettingsStateZus = SettingsState & State;
export const selectSettingsState =
export const selectSettingsState =
<K extends keyof SettingsState>(keys: K[]) => f.pick<SettingsState, K>(keys);
export const selectCalmState = (s: SettingsState) => s.calm;
@ -47,14 +47,14 @@ const useSettingsState = create<SettingsStateZus>((set) => ({
videoShown: true
},
leap: {
categories: JSON.stringify(leapCategories),
categories: leapCategories,
},
set: (fn: (state: SettingsState) => void) => set(produce(fn))
}));
}));
function withSettingsState<P, S extends keyof SettingsState>(Component: any, stateMemberKeys?: S[]) {
return React.forwardRef((props: Omit<P, S>, ref) => {
const localState = stateMemberKeys
const localState = stateMemberKeys
? useSettingsState(selectSettingsState(stateMemberKeys))
: useSettingsState();
return <Component ref={ref} {...localState} {...props} />

View File

@ -51,7 +51,7 @@ const settingsSel = selectSettingsState(["leap", "set"]);
export function LeapSettings(props: { api: GlobalApi; }) {
const { api } = props;
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);
console.log(categories);
@ -70,7 +70,7 @@ export function LeapSettings(props: { api: GlobalApi; }) {
(acc, { display, category }) => (display ? [...acc, category] : acc),
[] as LeapCategories[]
);
await api.settings.putEntry('leap', 'categories', JSON.stringify(result));
await api.settings.putEntry('leap', 'categories', result);
};
return (