From 4e0f93d21c89abf1b278f2a3877eb8d4f564ce08 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Fri, 18 Apr 2025 11:11:58 -0700 Subject: [PATCH] Load (canned) proposal from IPC --- src/components/chat/ChatInput.tsx | 106 +++++++++++++++----------- src/db/schema.ts | 3 + src/hooks/useProposal.ts | 44 +++++++++++ src/ipc/handlers/proposal_handlers.ts | 47 ++++++++++++ src/ipc/ipc_client.ts | 13 ++++ src/ipc/ipc_host.ts | 2 + src/lib/schemas.ts | 20 +++++ src/preload.ts | 1 + 8 files changed, 191 insertions(+), 45 deletions(-) create mode 100644 src/hooks/useProposal.ts create mode 100644 src/ipc/handlers/proposal_handlers.ts diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx index 8d622a5..f67c6ad 100644 --- a/src/components/chat/ChatInput.tsx +++ b/src/components/chat/ChatInput.tsx @@ -23,6 +23,15 @@ import { useLoadApp } from "@/hooks/useLoadApp"; import { Button } from "@/components/ui/button"; import { Label } from "@/components/ui/label"; import { Switch } from "@/components/ui/switch"; +import { useProposal } from "@/hooks/useProposal"; +import { Proposal } from "@/lib/schemas"; + +interface ChatInputActionsProps { + proposal: Proposal; + onApprove: () => void; + onReject: () => void; + isApprovable: boolean; // Can be used to enable/disable buttons +} interface ChatInputProps { chatId?: number; @@ -38,6 +47,13 @@ export function ChatInput({ chatId, onSubmit }: ChatInputProps) { const [selectedAppId] = useAtom(selectedAppIdAtom); const [showError, setShowError] = useState(true); + // Use the hook to fetch the proposal + const { + proposal, + isLoading: isProposalLoading, + error: proposalError, + } = useProposal(chatId); + const adjustHeight = () => { const textarea = textareaRef.current; if (textarea) { @@ -86,6 +102,16 @@ export function ChatInput({ chatId, onSubmit }: ChatInputProps) { setShowError(false); }; + const handleApprove = () => { + console.log("Approve clicked"); + // Add approve logic here + }; + + const handleReject = () => { + console.log("Reject clicked"); + // Add reject logic here + }; + if (!settings) { return null; // Or loading state } @@ -105,9 +131,28 @@ export function ChatInput({ chatId, onSubmit }: ChatInputProps) { )} + {/* Display loading or error state for proposal */} + {isProposalLoading && ( +
+ Loading proposal... +
+ )} + {proposalError && ( +
+ Error loading proposal: {proposalError} +
+ )}
- + {/* Only render ChatInputActions if proposal is loaded */} + {proposal && ( + + )}