Files
zclaw_openfang/desktop/src/domains/hands/hooks.ts
iven 5513d5d8e4 fix(domains): resolve TypeScript type errors in domain hooks
- Add type assertions for Valtio snapshot readonly arrays
- Remove unused fromPromise import from hands machine
- Ensures type compatibility with Valtio's useSnapshot

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-21 19:52:14 +08:00

80 lines
1.7 KiB
TypeScript

/**
* Hands Domain Hooks
*
* React hooks for accessing hands state with Valtio.
*/
import { useSnapshot } from 'valtio';
import { handsStore } from './store';
import type { Hand, ApprovalRequest, Trigger, HandRun } from './types';
/**
* Hook to access the full hands state snapshot.
*/
export function useHandsState() {
return useSnapshot(handsStore);
}
/**
* Hook to access hands list.
*/
export function useHands() {
const { hands } = useSnapshot(handsStore);
return hands as readonly Hand[];
}
/**
* Hook to access a specific hand by ID.
*/
export function useHand(id: string) {
const { hands } = useSnapshot(handsStore);
return hands.find(h => h.id === id) as Hand | undefined;
}
/**
* Hook to access approval queue.
*/
export function useApprovalQueue() {
const { approvalQueue } = useSnapshot(handsStore);
return approvalQueue as readonly ApprovalRequest[];
}
/**
* Hook to access triggers.
*/
export function useTriggers() {
const { triggers } = useSnapshot(handsStore);
return triggers as readonly Trigger[];
}
/**
* Hook to access a specific run.
*/
export function useRun(runId: string) {
const { runs } = useSnapshot(handsStore);
return runs[runId] as HandRun | undefined;
}
/**
* Hook to check if any hand is loading.
*/
export function useHandsLoading(): boolean {
const { isLoading } = useSnapshot(handsStore);
return isLoading;
}
/**
* Hook to access hands error.
*/
export function useHandsError(): string | null {
const { error } = useSnapshot(handsStore);
return error;
}
/**
* Hook to access hands actions.
* Returns the store directly for calling actions.
*/
export function useHandsActions() {
return handsStore;
}