diff --git a/frontend/src/components/SourcesPopup.tsx b/frontend/src/components/SourcesPopup.tsx index 6846cf84..83966730 100644 --- a/frontend/src/components/SourcesPopup.tsx +++ b/frontend/src/components/SourcesPopup.tsx @@ -81,12 +81,6 @@ export default function SourcesPopup({ return () => window.removeEventListener('resize', updatePosition); }, [isOpen, anchorRef]); - const handleEmptyDocumentSelect = () => { - dispatch(setSelectedDocs(null)); - handlePostDocumentSelect(null); - onClose(); - }; - const handleClickOutside = (event: MouseEvent) => { if ( popupRef.current && @@ -153,14 +147,24 @@ export default function SourcesPopup({ <> {filteredOptions?.map((option: any, index: number) => { if (option.model === embeddingsName) { + const isSelected = + selectedDocs && + (option.id + ? selectedDocs.id === option.id + : selectedDocs.date === option.date); + return (
{ - dispatch(setSelectedDocs(option)); - handlePostDocumentSelect(option); - onClose(); + if (isSelected) { + dispatch(setSelectedDocs(null)); + handlePostDocumentSelect(null); + } else { + dispatch(setSelectedDocs(option)); + handlePostDocumentSelect(option); + } }} > - {selectedDocs && - (option.id - ? selectedDocs.id === option.id // For documents with MongoDB IDs - : selectedDocs.date === option.date) && ( // For preloaded sources - Selected - )} + {isSelected && ( + Selected + )}
); } return null; })} -
- Source - - {t('none')} - -
- {selectedDocs === null && ( - Selected - )} -
-
) : (