mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-11-28 11:40:11 +03:00
interface: update for setting namespacing
This commit is contained in:
parent
d79130af47
commit
4f90df272b
@ -40,8 +40,8 @@ function delEntry(json: SettingsUpdate, state: any): SettingsState {
|
||||
return state;
|
||||
}
|
||||
|
||||
function getAll(json: any, state: SettingsState): SettingsState {
|
||||
const data = _.get(json, 'all');
|
||||
function getDesk(json: any, state: SettingsState): SettingsState {
|
||||
const data = _.get(json, 'desk');
|
||||
if(data) {
|
||||
_.mergeWith(state, data, (obj, src) => _.isArray(src) ? src : undefined);
|
||||
}
|
||||
@ -75,7 +75,7 @@ export const reduceUpdate = [
|
||||
];
|
||||
|
||||
export const reduceScry = [
|
||||
getAll,
|
||||
getDesk,
|
||||
getBucket,
|
||||
getEntry
|
||||
];
|
||||
|
@ -16,7 +16,7 @@ import {
|
||||
import { useCallback } from 'react';
|
||||
import { reduceUpdate } from '../reducers/settings-update';
|
||||
import airlock from '~/logic/api';
|
||||
import { getAll, Value } from '@urbit/api';
|
||||
import { getDeskSettings, Value } from '@urbit/api';
|
||||
import { putEntry } from '@urbit/api/settings';
|
||||
|
||||
export interface ShortcutMapping {
|
||||
@ -101,20 +101,22 @@ const useSettingsState = createState<SettingsState>(
|
||||
readGroup: 'shift+Escape'
|
||||
},
|
||||
getAll: async () => {
|
||||
const { all } = await airlock.scry(getAll);
|
||||
const { desk } = await airlock.scry(getDeskSettings((window as any).desk));
|
||||
get().set((s) => {
|
||||
Object.assign(s, all);
|
||||
for(const bucket in desk) {
|
||||
s[bucket] = { ...(s[bucket] || {}), ...desk[bucket] };
|
||||
}
|
||||
});
|
||||
},
|
||||
putEntry: (bucket: string, entry: string, value: Value) => {
|
||||
const poke = putEntry(bucket, entry, value);
|
||||
const poke = putEntry((window as any).desk, bucket, entry, value);
|
||||
pokeOptimisticallyN(useSettingsState, poke, reduceUpdate);
|
||||
}
|
||||
}),
|
||||
[],
|
||||
[
|
||||
(set, get) =>
|
||||
createSubscription('settings-store', '/all', (e) => {
|
||||
createSubscription('settings-store', `/desk/${(window as any).desk}`, (e) => {
|
||||
const data = _.get(e, 'settings-event', false);
|
||||
if (data) {
|
||||
reduceStateN(get(), data, reduceUpdate);
|
||||
|
Loading…
Reference in New Issue
Block a user