fix: apply code- discard button

This commit is contained in:
Akhileshrangani4
2024-12-01 22:15:03 -05:00
parent d840aad3e9
commit 74b0c6b9e4
5 changed files with 30 additions and 28 deletions

View File

@ -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(

View File

@ -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 = (
<div className="w-px bg-input"></div>
<Button
onClick={() => {
if (
setMergeDecorationsCollection &&
mergeDecorationsCollection &&
editorRef?.current
) {
editorRef.current.getModel()?.setValue(activeFileContent)
mergeDecorationsCollection.clear()
setMergeDecorationsCollection(undefined)
if (editorRef?.current && mergeDecorationsCollection) {
const model = editorRef.current.getModel()
if (model && (model as any).originalContent) {
editorRef.current?.setValue(
(model as any).originalContent
)
mergeDecorationsCollection.clear()
setMergeDecorationsCollection?.(undefined)
}
}
}}
size="sm"

View File

@ -57,7 +57,7 @@ export interface AIChatProps {
templateType: string
templateConfig?: TemplateConfig
projectName: string
handleApplyCode: (mergedCode: string) => void
handleApplyCode: (mergedCode: string, originalCode: string) => void
mergeDecorationsCollection?: monaco.editor.IEditorDecorationsCollection
setMergeDecorationsCollection?: (collection: undefined) => void
selectFile: (tab: TTab) => void
@ -110,7 +110,7 @@ export interface MessageProps {
) => void
setIsContextExpanded: (isExpanded: boolean) => void
socket: Socket | null
handleApplyCode: (mergedCode: string) => void
handleApplyCode: (mergedCode: string, originalCode: string) => void
activeFileName: string
activeFileContent: string
editorRef: any