mirror of
https://github.com/tloncorp/landscape.git
synced 2024-12-19 06:41:35 +03:00
grid: clean up kiln state initialization
This commit is contained in:
parent
ac3dc72983
commit
29f42aff1f
@ -86,10 +86,8 @@ const AppRoutes = () => {
|
|||||||
fetchCharges();
|
fetchCharges();
|
||||||
fetchAllies();
|
fetchAllies();
|
||||||
|
|
||||||
const { fetchVats, fetchLag, fetchPikes } = useKilnState.getState();
|
const { initializeKiln } = useKilnState.getState();
|
||||||
fetchVats();
|
initializeKiln();
|
||||||
fetchLag();
|
|
||||||
fetchPikes();
|
|
||||||
|
|
||||||
useContactState.getState().initialize(api);
|
useContactState.getState().initialize(api);
|
||||||
useHarkState.getState().start();
|
useHarkState.getState().start();
|
||||||
|
@ -22,23 +22,19 @@ interface KilnState {
|
|||||||
vats: Vats;
|
vats: Vats;
|
||||||
pikes: Pikes;
|
pikes: Pikes;
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
fetchVats: () => Promise<void>;
|
|
||||||
lag: boolean;
|
lag: boolean;
|
||||||
fetchLag: () => Promise<void>;
|
fetchLag: () => Promise<void>;
|
||||||
fetchPikes: () => Promise<void>;
|
fetchPikes: () => Promise<void>;
|
||||||
changeOTASource: (ship: string) => Promise<void>;
|
changeOTASource: (ship: string) => Promise<void>;
|
||||||
toggleOTAs: (desk: string, on: boolean) => Promise<void>;
|
toggleOTAs: (desk: string, on: boolean) => Promise<void>;
|
||||||
set: (s: KilnState) => void;
|
set: (s: KilnState) => void;
|
||||||
|
initializeKiln: () => Promise<void>;
|
||||||
}
|
}
|
||||||
const useKilnState = create<KilnState>((set, get) => ({
|
const useKilnState = create<KilnState>((set, get) => ({
|
||||||
vats: {},
|
vats: {},
|
||||||
pikes: useMockData ? mockPikes : {},
|
pikes: useMockData ? mockPikes : {},
|
||||||
lag: false,
|
lag: false,
|
||||||
loaded: false,
|
loaded: false,
|
||||||
fetchVats: async () => {
|
|
||||||
const vats = await api.scry<Vats>(getVats);
|
|
||||||
set({ vats, loaded: true });
|
|
||||||
},
|
|
||||||
fetchPikes: async () => {
|
fetchPikes: async () => {
|
||||||
if (useMockData) {
|
if (useMockData) {
|
||||||
await fakeRequest({}, 500);
|
await fakeRequest({}, 500);
|
||||||
@ -58,31 +54,24 @@ const useKilnState = create<KilnState>((set, get) => ({
|
|||||||
toggleOTAs: async (desk: string, on: boolean) => {
|
toggleOTAs: async (desk: string, on: boolean) => {
|
||||||
set(
|
set(
|
||||||
produce((draft: KilnState) => {
|
produce((draft: KilnState) => {
|
||||||
const { arak } = draft.vats[desk];
|
const pike = draft.pikes[desk];
|
||||||
if (!arak.rail) {
|
if (!pike) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (on) {
|
|
||||||
arak.rail.paused = false;
|
pike.zest = on ? 'live' : 'held';
|
||||||
} else {
|
|
||||||
arak.rail.paused = true;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
await api.poke(on ? kilnResume(desk) : kilnPause(desk));
|
await api.poke(on ? kilnResume(desk) : kilnPause(desk));
|
||||||
await get().fetchVats(); // refresh vat state
|
await get().fetchPikes(); // refresh pikes state
|
||||||
},
|
},
|
||||||
set: produce(set)
|
set: produce(set),
|
||||||
}));
|
initializeKiln: async () => {
|
||||||
|
await get().fetchLag();
|
||||||
api.subscribe({
|
await get().fetchPikes();
|
||||||
app: 'hood',
|
|
||||||
path: '/kiln/vats',
|
|
||||||
event: () => {
|
|
||||||
useKilnState.getState().fetchVats();
|
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|
||||||
const selBlockers = (s: KilnState) => getBlockers(s.vats);
|
const selBlockers = (s: KilnState) => getBlockers(s.vats);
|
||||||
export function useBlockers() {
|
export function useBlockers() {
|
||||||
|
Loading…
Reference in New Issue
Block a user