Auto-submit error with fix error in preview iframe (#68)

This commit is contained in:
Will Chen
2025-05-01 23:10:11 -07:00
committed by GitHub
parent a0165cdf5f
commit d1df8b10e8

View File

@@ -17,7 +17,7 @@ import {
ChevronDown, ChevronDown,
Lightbulb, Lightbulb,
} from "lucide-react"; } from "lucide-react";
import { chatInputValueAtom } from "@/atoms/chatAtoms"; import { selectedChatIdAtom } from "@/atoms/chatAtoms";
import { IpcClient } from "@/ipc/ipc_client"; import { IpcClient } from "@/ipc/ipc_client";
import { useLoadApp } from "@/hooks/useLoadApp"; import { useLoadApp } from "@/hooks/useLoadApp";
import { useLoadAppFile } from "@/hooks/useLoadAppFile"; import { useLoadAppFile } from "@/hooks/useLoadAppFile";
@@ -29,6 +29,7 @@ import {
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import { useSettings } from "@/hooks/useSettings"; import { useSettings } from "@/hooks/useSettings";
import { useRunApp } from "@/hooks/useRunApp"; import { useRunApp } from "@/hooks/useRunApp";
import { useStreamChat } from "@/hooks/useStreamChat";
interface ErrorBannerProps { interface ErrorBannerProps {
error: string | undefined; error: string | undefined;
@@ -91,7 +92,8 @@ export const PreviewIframe = ({ loading }: { loading: boolean }) => {
// State to trigger iframe reload // State to trigger iframe reload
const [reloadKey, setReloadKey] = useState(0); const [reloadKey, setReloadKey] = useState(0);
const [errorMessage, setErrorMessage] = useAtom(previewErrorMessageAtom); const [errorMessage, setErrorMessage] = useAtom(previewErrorMessageAtom);
const setInputValue = useSetAtom(chatInputValueAtom); const [selectedChatId, setSelectedChatId] = useAtom(selectedChatIdAtom);
const { streamMessage } = useStreamChat();
const [availableRoutes, setAvailableRoutes] = useState< const [availableRoutes, setAvailableRoutes] = useState<
Array<{ path: string; label: string }> Array<{ path: string; label: string }>
>([]); >([]);
@@ -394,7 +396,12 @@ export const PreviewIframe = ({ loading }: { loading: boolean }) => {
error={errorMessage} error={errorMessage}
onDismiss={() => setErrorMessage(undefined)} onDismiss={() => setErrorMessage(undefined)}
onAIFix={() => { onAIFix={() => {
setInputValue(`Fix the error in ${errorMessage}`); if (selectedChatId) {
streamMessage({
prompt: `Fix error: ${errorMessage}`,
chatId: selectedChatId,
});
}
}} }}
/> />