forked from phenom/healer-man
Release Healer Man 0.1.46
This commit is contained in:
1 parent
f82daf1c13
commit
9ff574ac0b
73 files changed
+33486
-174
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import { create } from "zustand";
|
||||
import { fetchDungeonRouteApprovals } from "../app/dungeonSimulationClient";
|
||||
import type { DungeonRouteApproval, DungeonRouteDefinitionV1 } from "./dungeonSimulationTypes";
|
||||
import {
|
||||
cacheDungeonRouteApprovals,
|
||||
readCachedDungeonRouteApprovals,
|
||||
routeHasExactApproval,
|
||||
} from "./dungeonRoutes";
|
||||
|
||||
export interface DungeonRouteState {
|
||||
approvals: readonly DungeonRouteApproval[];
|
||||
loading: boolean;
|
||||
refreshedAt: number | null;
|
||||
refresh: () => Promise<void>;
|
||||
isApproved: (route: DungeonRouteDefinitionV1 | null) => boolean;
|
||||
}
|
||||
|
||||
export const useDungeonRouteStore = create<DungeonRouteState>((set, get) => ({
|
||||
approvals: readCachedDungeonRouteApprovals(),
|
||||
loading: false,
|
||||
refreshedAt: null,
|
||||
refresh: async () => {
|
||||
if (get().loading) return;
|
||||
set({ loading: true });
|
||||
try {
|
||||
const approvals = await fetchDungeonRouteApprovals();
|
||||
cacheDungeonRouteApprovals(approvals);
|
||||
set({ approvals, refreshedAt: Date.now(), loading: false });
|
||||
} catch {
|
||||
// An exact-hash cached approval is intentionally usable during outages.
|
||||
set({ loading: false });
|
||||
}
|
||||
},
|
||||
isApproved: (route) => routeHasExactApproval(route, get().approvals),
|
||||
}));
|
||||
Reference in new issue
Block a user