From e384607d24aa3170518d1dca32fbac640ef07b81 Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Sat, 30 Nov 2024 02:26:34 -0500 Subject: [PATCH] chore: context tab updates - Context tab updates with the latest file changes and will not be removed from context when a message is sent --- frontend/components/editor/AIChat/index.tsx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/frontend/components/editor/AIChat/index.tsx b/frontend/components/editor/AIChat/index.tsx index 4e7888d..d05813e 100644 --- a/frontend/components/editor/AIChat/index.tsx +++ b/frontend/components/editor/AIChat/index.tsx @@ -150,8 +150,6 @@ export default function AIChat({ false, templateType ) - // Clear context tabs after sending - setContextTabs([]) } // Set context for the chat @@ -169,6 +167,22 @@ export default function AIChat({ addContextTab("code", name, context, range) } + // update context tabs when file contents change + useEffect(() => { + setContextTabs((prevTabs) => + prevTabs.map((tab) => { + if (tab.type === "file" && tab.name === activeFileName) { + const fileExt = tab.name.split(".").pop() || "txt" + return { + ...tab, + content: `\`\`\`${fileExt}\n${activeFileContent}\n\`\`\`` + } + } + return tab + }) + ) + }, [activeFileContent, activeFileName]) + return (