All files / src/domains/hands hooks.ts

0% Statements 0/35
0% Branches 0/1
0% Functions 0/1
0% Lines 0/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80                                                                                                                                                               
/**
 * 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;
}