grid: consume Pike interface and scry

This commit is contained in:
tomholford 2022-11-03 22:19:36 -07:00
parent 31ed4bee6c
commit bb97306432
5 changed files with 60149 additions and 60224 deletions

23744
pkg/grid/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -86,9 +86,10 @@ const AppRoutes = () => {
fetchCharges();
fetchAllies();
const { fetchVats, fetchLag } = useKilnState.getState();
const { fetchVats, fetchLag, fetchPikes } = useKilnState.getState();
fetchVats();
fetchLag();
fetchPikes();
useContactState.getState().initialize(api);
useHarkStore.getState().initialize(api);

View File

@ -6,38 +6,53 @@ import {
Vat,
kilnInstall,
kilnPause,
kilnResume
kilnResume,
getPikes,
Pikes
} from '@urbit/api';
import create from 'zustand';
import produce from 'immer';
import { useCallback } from 'react';
import api from './api';
import { fakeRequest, useMockData } from './util';
import { mockVats } from './mock-data';
import { mockPikes, mockVats } from './mock-data';
interface KilnState {
vats: Vats;
pikes: Pikes;
loaded: boolean;
fetchVats: () => Promise<void>;
lag: boolean;
fetchLag: () => Promise<void>;
fetchPikes: () => Promise<void>;
changeOTASource: (ship: string) => Promise<void>;
toggleOTAs: (desk: string, on: boolean) => Promise<void>;
set: (s: KilnState) => void;
}
const useKilnState = create<KilnState>((set, get) => ({
vats: useMockData ? mockVats : {},
pikes: useMockData ? mockPikes : {},
lag: !!useMockData,
loaded: false,
fetchVats: async () => {
if (useMockData) {
await fakeRequest({}, 500);
// TODO: remove this loaded update in favor of fetchPikes?
set({ loaded: true });
return;
}
const vats = await api.scry<Vats>(getVats);
set({ vats, loaded: true });
},
fetchPikes: async () => {
if (useMockData) {
await fakeRequest({}, 500);
set({ loaded: true });
return;
}
const pikes = await api.scry<Pikes>(getPikes);
set({ pikes, loaded: true });
},
fetchLag: async () => {
const lag = await api.scry<boolean>(scryLag);
set({ lag });

View File

@ -13,7 +13,8 @@ import {
Contact,
Contacts,
Timebox,
harkBinToId
harkBinToId,
Pikes
} from '@urbit/api';
import _ from 'lodash';
import systemUrl from '../assets/system.png';
@ -375,3 +376,36 @@ export const mockVats = _.reduce(
},
{ base: mockVat('base', true) } as Vats
);
export const mockPikes: Pikes = {
kids: {
sync: null,
zest: 'dead',
wefts: [],
hash: '0v19.q7u27.omps3.fbhf4.53rai.co157.pben7.pu94n.63v4p.3kcb7.iafj0'
},
garden: {
sync: {
desk: 'garden',
ship: '~mister-dister-dozzod-dozzod'
},
zest: 'live',
wefts: [],
hash: '0v18.hbbs6.onu15.skjkv.qrfgl.vf4oo.0igo5.2q0d3.6r3r8.2dkmo.oa04m'
},
landscape: {
sync: {
desk: 'landscape',
ship: '~lander-dister-dozzod-dozzod'
},
zest: 'live',
wefts: [],
hash: '0v1t.qln8k.cskmt.cn6lv.gu335.jfba6.kte90.iqqn3.aj67b.t389a.8imuo'
},
base: {
sync: null,
zest: 'live',
wefts: [],
hash: '0v1e.b5auh.6u82i.hqk1r.22kli.4ubef.a1cbo.3g532.6l49k.g0i8e.t6eid'
}
};

File diff suppressed because it is too large Load Diff