Files
factorio-clusterio/packages/web_ui/src/model/host.ts
T
Danielv123 2e1710d3a9 Show the same page for missing, deleted and unloadable resources
Every view page handled a resource that can't be shown its own way, and
users without the subscribe permission were left on a spinner forever.

Adds useResourceState and a ResourceState component, used by the host,
instance, mod pack, icon reference, user, role and plugin pages and
exported for plugin pages. The single item hooks now also return the
subscription error.

Resolves #1165
2026-11-01 17:40:22 +01:00

21 lines
925 B
TypeScript

import { useCallback, useContext, useSyncExternalStore } from "react";
import ControlContext from "../components/ControlContext";
export function useHost(id?: number) {
const [hosts, synced, error] = useHosts();
return [id !== undefined ? hosts.get(id) : undefined, synced, error] as const;
}
export function useHosts() {
const control = useContext(ControlContext);
const subscribe = useCallback((callback: () => void) => control.hosts.subscribe(callback), [control]);
return useSyncExternalStore(subscribe, () => control.hosts.getSnapshot());
}
/** Requests from hosts waiting to be approved, empty if the account may not approve hosts */
export function useHostPairings() {
const control = useContext(ControlContext);
const subscribe = useCallback((callback: () => void) => control.hostPairings.subscribe(callback), [control]);
return useSyncExternalStore(subscribe, () => control.hostPairings.getSnapshot());
}