From 29f42aff1f364304d025d4dc91e2230b42f21ef8 Mon Sep 17 00:00:00 2001 From: tomholford Date: Fri, 4 Nov 2022 00:05:43 -0700 Subject: [PATCH] grid: clean up kiln state initialization --- ui/src/app.tsx | 6 ++---- ui/src/state/kiln.ts | 33 +++++++++++---------------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/ui/src/app.tsx b/ui/src/app.tsx index 41d5f94..8c8bb0d 100644 --- a/ui/src/app.tsx +++ b/ui/src/app.tsx @@ -86,10 +86,8 @@ const AppRoutes = () => { fetchCharges(); fetchAllies(); - const { fetchVats, fetchLag, fetchPikes } = useKilnState.getState(); - fetchVats(); - fetchLag(); - fetchPikes(); + const { initializeKiln } = useKilnState.getState(); + initializeKiln(); useContactState.getState().initialize(api); useHarkState.getState().start(); diff --git a/ui/src/state/kiln.ts b/ui/src/state/kiln.ts index 8849e23..89e3c0d 100644 --- a/ui/src/state/kiln.ts +++ b/ui/src/state/kiln.ts @@ -22,23 +22,19 @@ interface KilnState { vats: Vats; pikes: Pikes; loaded: boolean; - fetchVats: () => Promise; lag: boolean; fetchLag: () => Promise; fetchPikes: () => Promise; changeOTASource: (ship: string) => Promise; toggleOTAs: (desk: string, on: boolean) => Promise; set: (s: KilnState) => void; + initializeKiln: () => Promise; } const useKilnState = create((set, get) => ({ vats: {}, pikes: useMockData ? mockPikes : {}, lag: false, loaded: false, - fetchVats: async () => { - const vats = await api.scry(getVats); - set({ vats, loaded: true }); - }, fetchPikes: async () => { if (useMockData) { await fakeRequest({}, 500); @@ -58,31 +54,24 @@ const useKilnState = create((set, get) => ({ toggleOTAs: async (desk: string, on: boolean) => { set( produce((draft: KilnState) => { - const { arak } = draft.vats[desk]; - if (!arak.rail) { + const pike = draft.pikes[desk]; + if (!pike) { return; } - if (on) { - arak.rail.paused = false; - } else { - arak.rail.paused = true; - } + + pike.zest = on ? 'live' : 'held'; }) ); await api.poke(on ? kilnResume(desk) : kilnPause(desk)); - await get().fetchVats(); // refresh vat state + await get().fetchPikes(); // refresh pikes state }, - set: produce(set) -})); - -api.subscribe({ - app: 'hood', - path: '/kiln/vats', - event: () => { - useKilnState.getState().fetchVats(); + set: produce(set), + initializeKiln: async () => { + await get().fetchLag(); + await get().fetchPikes(); } -}); +})); const selBlockers = (s: KilnState) => getBlockers(s.vats); export function useBlockers() {