feat(domains): create domain-driven architecture for Phase 2
Chat Domain: - Add types.ts with Message, Conversation, Agent types - Add store.ts with Valtio-based state management - Add hooks.ts with useChatState, useMessages, etc. - Add index.ts for public API export Hands Domain: - Add types.ts with Hand, Trigger, Approval types - Add machine.ts with XState state machine - Add store.ts with Valtio-based state management - Add hooks.ts with useHands, useApprovalQueue, etc. Shared Module: - Add types.ts with Result, AsyncResult, PaginatedResponse - Add error-handling.ts with AppError, NetworkError, etc. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
79
desktop/src/domains/hands/hooks.ts
Normal file
79
desktop/src/domains/hands/hooks.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* 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(): readonly Hand[] {
|
||||
const { hands } = useSnapshot(handsStore);
|
||||
return hands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to access a specific hand by ID.
|
||||
*/
|
||||
export function useHand(id: string): Hand | undefined {
|
||||
const { hands } = useSnapshot(handsStore);
|
||||
return hands.find(h => h.id === id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to access approval queue.
|
||||
*/
|
||||
export function useApprovalQueue(): readonly ApprovalRequest[] {
|
||||
const { approvalQueue } = useSnapshot(handsStore);
|
||||
return approvalQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to access triggers.
|
||||
*/
|
||||
export function useTriggers(): readonly Trigger[] {
|
||||
const { triggers } = useSnapshot(handsStore);
|
||||
return triggers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to access a specific run.
|
||||
*/
|
||||
export function useRun(runId: string): HandRun | undefined {
|
||||
const { runs } = useSnapshot(handsStore);
|
||||
return runs[runId];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
Reference in New Issue
Block a user