Ver código fonte

Implementation of effect to monitor input value changes in useForm

Shun Miyazawa 10 meses atrás
pai
commit
84deb55e95

+ 16 - 1
apps/app/src/features/openai/client/services/editor-assistant.tsx

@@ -276,6 +276,17 @@ export const useEditorAssistant: UseEditorAssistant = () => {
     }
     }
   }, [detectedDiff]);
   }, [detectedDiff]);
 
 
+  // Disable UnifiedMergeView when starting to write text in Form while UnifiedMergeView is enabled
+  useEffect(() => {
+    const subscription = form.watch(
+      (formData) => {
+        if (formData.input != null && formData.input.length > 0 && isEnableUnifiedMergeView) {
+          mutateIsEnableUnifiedMergeView(false);
+        }
+      },
+    );
+    return () => subscription.unsubscribe();
+  }, [form, form.watch, isEnableUnifiedMergeView, mutateIsEnableUnifiedMergeView]);
 
 
   // Views
   // Views
   const headerIcon = useMemo(() => {
   const headerIcon = useMemo(() => {
@@ -319,6 +330,10 @@ export const useEditorAssistant: UseEditorAssistant = () => {
         return false;
         return false;
       }
       }
 
 
+      if (!isEnableUnifiedMergeView) {
+        return false;
+      }
+
       if (generatingAnswerMessage != null) {
       if (generatingAnswerMessage != null) {
         return false;
         return false;
       }
       }
@@ -358,7 +373,7 @@ export const useEditorAssistant: UseEditorAssistant = () => {
         {children}
         {children}
       </MessageCard>
       </MessageCard>
     );
     );
-  }, [aiAssistantSidebarData?.isEditorAssistant, codeMirrorEditor?.view, mutateIsEnableUnifiedMergeView]);
+  }, [aiAssistantSidebarData?.isEditorAssistant, codeMirrorEditor?.view, isEnableUnifiedMergeView, mutateIsEnableUnifiedMergeView]);
 
 
   return {
   return {
     createThread,
     createThread,