From 0d0eed34b25d1dd8094a0a911804c2ab75aceb38 Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Sun, 1 Dec 2024 22:15:03 -0500 Subject: [PATCH] fix: apply code- discard button --- frontend/app/api/merge/route.ts | 4 ++- .../components/editor/AIChat/ApplyButton.tsx | 4 +-- .../editor/AIChat/lib/markdownComponents.tsx | 21 ++++++++-------- .../components/editor/AIChat/types/index.ts | 4 +-- frontend/components/editor/index.tsx | 25 +++++++++---------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/frontend/app/api/merge/route.ts b/frontend/app/api/merge/route.ts index c17eab9..c2a7600 100644 --- a/frontend/app/api/merge/route.ts +++ b/frontend/app/api/merge/route.ts @@ -19,7 +19,9 @@ export async function POST(request: Request) { - Explanations or comments - Markdown formatting -The output should be the exact code that will replace the existing code, nothing more and nothing less.` +The output should be the exact code that will replace the existing code, nothing more and nothing less. + +Important: When merging, preserve the original code structure as much as possible. Only make necessary changes to integrate the new code while maintaining the original code's organization and style.` const mergedCode = `Original file (${fileName}):\n${originalCode}\n\nNew code to merge:\n${newCode}` diff --git a/frontend/components/editor/AIChat/ApplyButton.tsx b/frontend/components/editor/AIChat/ApplyButton.tsx index f122339..8fb94ff 100644 --- a/frontend/components/editor/AIChat/ApplyButton.tsx +++ b/frontend/components/editor/AIChat/ApplyButton.tsx @@ -8,7 +8,7 @@ interface ApplyButtonProps { activeFileName: string activeFileContent: string editorRef: { current: any } - onApply: (mergedCode: string) => void + onApply: (mergedCode: string, originalCode: string) => void } export default function ApplyButton({ @@ -48,7 +48,7 @@ export default function ApplyButton({ mergedCode += decoder.decode(value, { stream: true }) } } - onApply(mergedCode.trim()) + onApply(mergedCode.trim(), activeFileContent) } catch (error) { console.error("Error applying code:", error) toast.error( diff --git a/frontend/components/editor/AIChat/lib/markdownComponents.tsx b/frontend/components/editor/AIChat/lib/markdownComponents.tsx index 36130d5..770ee09 100644 --- a/frontend/components/editor/AIChat/lib/markdownComponents.tsx +++ b/frontend/components/editor/AIChat/lib/markdownComponents.tsx @@ -17,7 +17,7 @@ export const createMarkdownComponents = ( activeFileName: string, activeFileContent: string, editorRef: any, - handleApplyCode: (mergedCode: string) => void, + handleApplyCode: (mergedCode: string, originalCode: string) => void, selectFile: (tab: TTab) => void, mergeDecorationsCollection?: monaco.editor.IEditorDecorationsCollection, setMergeDecorationsCollection?: (collection: undefined) => void @@ -61,7 +61,7 @@ export const createMarkdownComponents = ( mergeDecorationsCollection && editorRef?.current ) { - mergeDecorationsCollection.clear() + mergeDecorationsCollection?.clear() setMergeDecorationsCollection(undefined) } }} @@ -75,14 +75,15 @@ export const createMarkdownComponents = (