/** * 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; }