Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions webview-ui/src/components/chat/CustomInstructionsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,28 @@ const CustomInstructionsMenu = ({
setFileInstructions,
} = useExtensionState();

const isAllInstructionsEnabled = () => {
if (fileInstructions && fileInstructions.length > 0 && customInstructions) {
return (
fileInstructions.every((i) => i.enabled === true) &&
isCustomInstructionsEnabled
);
} else if (fileInstructions && fileInstructions.length > 0 && !customInstructions) {
return fileInstructions.every((i) => i.enabled === true);
} else if ((!fileInstructions || fileInstructions.length <= 0) && customInstructions) {
return isCustomInstructionsEnabled;
} else {
return false;
}
};

const [allInstructionsEnabled, setAllInstructionsEnabled] = useState<boolean>(
(fileInstructions?.every((i) => i.enabled === true) ?? false) &&
customInstructions !== undefined &&
isCustomInstructionsEnabled
? true
: false
isAllInstructionsEnabled()
);

useEffect(() => {
setAllInstructionsEnabled(
(fileInstructions?.every((i) => i.enabled === true) ?? false) &&
customInstructions !== undefined &&
isCustomInstructionsEnabled
);
setAllInstructionsEnabled(isAllInstructionsEnabled());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fileInstructions, customInstructions, isCustomInstructionsEnabled]);

const toggleInstruction = (index: number) => {
Expand All @@ -53,11 +61,7 @@ const CustomInstructionsMenu = ({
type: "fileInstructions",
fileInstructions: updatedInstructions,
});
setAllInstructionsEnabled(
(updatedInstructions?.every((i) => i.enabled === true) ?? false) &&
customInstructions !== undefined &&
isCustomInstructionsEnabled
);
setAllInstructionsEnabled(isAllInstructionsEnabled());
};

const toggleTextInstruction = () => {
Expand All @@ -68,11 +72,7 @@ const CustomInstructionsMenu = ({
text: customInstructions,
bool: value,
});
setAllInstructionsEnabled(
(fileInstructions?.every((i) => i.enabled === true) ?? false) &&
customInstructions !== undefined &&
value
);
setAllInstructionsEnabled(isAllInstructionsEnabled());
};

const toggleAllInstructions = () => {
Expand All @@ -88,7 +88,7 @@ const CustomInstructionsMenu = ({
fileInstructions: updatedInstructions,
});
}
setAllInstructionsEnabled(newValue);
setAllInstructionsEnabled(isAllInstructionsEnabled());
setIsCustomInstructionsEnabled(newValue);
vscode.postMessage({
type: "customInstructions",
Expand Down