mirror of
https://github.com/urbit/shrub.git
synced 2024-12-22 10:21:31 +03:00
leap, settings: store leap settings as array
This commit is contained in:
parent
2db485705e
commit
b4d82a9e8a
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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]);
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,14 @@ 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
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SettingsStateZus = SettingsState & State;
|
export type SettingsStateZus = SettingsState & State;
|
||||||
|
|
||||||
export const selectSettingsState =
|
export const selectSettingsState =
|
||||||
<K extends keyof SettingsState>(keys: K[]) => f.pick<SettingsState, K>(keys);
|
<K extends keyof SettingsState>(keys: K[]) => f.pick<SettingsState, K>(keys);
|
||||||
|
|
||||||
export const selectCalmState = (s: SettingsState) => s.calm;
|
export const selectCalmState = (s: SettingsState) => s.calm;
|
||||||
@ -47,14 +47,14 @@ 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))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
function withSettingsState<P, S extends keyof SettingsState>(Component: any, stateMemberKeys?: S[]) {
|
function withSettingsState<P, S extends keyof SettingsState>(Component: any, stateMemberKeys?: S[]) {
|
||||||
return React.forwardRef((props: Omit<P, S>, ref) => {
|
return React.forwardRef((props: Omit<P, S>, ref) => {
|
||||||
const localState = stateMemberKeys
|
const localState = stateMemberKeys
|
||||||
? useSettingsState(selectSettingsState(stateMemberKeys))
|
? useSettingsState(selectSettingsState(stateMemberKeys))
|
||||||
: useSettingsState();
|
: useSettingsState();
|
||||||
return <Component ref={ref} {...localState} {...props} />
|
return <Component ref={ref} {...localState} {...props} />
|
||||||
|
@ -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 (
|
||||||
|
Loading…
Reference in New Issue
Block a user