diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx index e6e1b54..88ea041 100644 --- a/src/components/chat/ChatInput.tsx +++ b/src/components/chat/ChatInput.tsx @@ -50,6 +50,8 @@ export function ChatInput({ chatId }: { chatId?: number }) { const [messages, setMessages] = useAtom(chatMessagesAtom); const setIsPreviewOpen = useSetAtom(isPreviewOpenAtom); + const { refreshAppIframe } = useRunApp(); + // Use the hook to fetch the proposal const { proposalResult, @@ -140,6 +142,9 @@ export function ChatInput({ chatId }: { chatId?: number }) { } finally { setIsApproving(false); setIsPreviewOpen(true); + refreshAppIframe(); + + // Keep same as handleReject refreshProposal(); fetchChatMessages(); } @@ -169,6 +174,8 @@ export function ChatInput({ chatId }: { chatId?: number }) { setError((err as Error)?.message || "An error occurred while rejecting"); } finally { setIsRejecting(false); + + // Keep same as handleApprove refreshProposal(); fetchChatMessages(); } diff --git a/src/components/preview_panel/PreviewIframe.tsx b/src/components/preview_panel/PreviewIframe.tsx index 1c0e703..8135ea5 100644 --- a/src/components/preview_panel/PreviewIframe.tsx +++ b/src/components/preview_panel/PreviewIframe.tsx @@ -55,8 +55,8 @@ const ErrorBanner = ({ error, onDismiss, onAIFix }: ErrorBannerProps) => { - Tip: Check if refreshing the - page or restarting the app fixes the error. + Tip: Check if restarting the + app fixes the error. diff --git a/src/hooks/useRunApp.ts b/src/hooks/useRunApp.ts index f854c4f..a653eed 100644 --- a/src/hooks/useRunApp.ts +++ b/src/hooks/useRunApp.ts @@ -106,5 +106,10 @@ export function useRunApp() { } }, []); - return { loading, error, runApp, stopApp, restartApp, app }; + const refreshAppIframe = useCallback(async () => { + setPreviewPanelKey((prevKey) => prevKey + 1); + setError(null); + }, [setPreviewPanelKey, setError]); + + return { loading, error, runApp, stopApp, restartApp, app, refreshAppIframe }; } diff --git a/src/hooks/useStreamChat.ts b/src/hooks/useStreamChat.ts index c73b04e..7067734 100644 --- a/src/hooks/useStreamChat.ts +++ b/src/hooks/useStreamChat.ts @@ -17,6 +17,7 @@ import { useLoadVersions } from "./useLoadVersions"; import { showError } from "@/lib/toast"; import { useProposal } from "./useProposal"; import { useSearch } from "@tanstack/react-router"; +import { useRunApp } from "./useRunApp"; export function getRandomString() { return Math.random().toString(36).substring(2, 15); @@ -34,6 +35,7 @@ export function useStreamChat({ const { refreshApp } = useLoadApp(selectedAppId); const setStreamCount = useSetAtom(chatStreamCountAtom); const { refreshVersions } = useLoadVersions(selectedAppId); + const { refreshAppIframe } = useRunApp(); let chatId: number | undefined; if (hasChatId) { @@ -100,6 +102,7 @@ export function useStreamChat({ onEnd: (response: ChatResponseEnd) => { if (response.updatedFiles) { setIsPreviewOpen(true); + refreshAppIframe(); } refreshProposal(chatId);