added support for multi select sources

This commit is contained in:
Ankit Matth
2025-08-16 15:19:19 +05:30
parent 6a02bcf15b
commit 6f47aa802b
7 changed files with 115 additions and 69 deletions

View File

@@ -149,9 +149,10 @@ export default function SourcesPopup({
if (option.model === embeddingsName) {
const isSelected =
selectedDocs &&
(option.id
? selectedDocs.id === option.id
: selectedDocs.date === option.date);
Array.isArray(selectedDocs) && selectedDocs.length > 0 &&
selectedDocs.some(doc =>
option.id ? doc.id === option.id : doc.date === option.date
);
return (
<div
@@ -159,11 +160,19 @@ export default function SourcesPopup({
className="border-opacity-80 dark:border-dim-gray flex cursor-pointer items-center border-b border-[#D9D9D9] p-3 transition-colors hover:bg-gray-100 dark:text-[14px] dark:hover:bg-[#2C2E3C]"
onClick={() => {
if (isSelected) {
dispatch(setSelectedDocs(null));
handlePostDocumentSelect(null);
const updatedDocs = (selectedDocs && Array.isArray(selectedDocs))
? selectedDocs.filter(doc =>
option.id ? doc.id !== option.id : doc.date !== option.date
)
: [];
dispatch(setSelectedDocs(updatedDocs.length > 0 ? updatedDocs : null));
handlePostDocumentSelect(updatedDocs.length > 0 ? updatedDocs : null);
} else {
dispatch(setSelectedDocs(option));
handlePostDocumentSelect(option);
const updatedDocs = (selectedDocs && Array.isArray(selectedDocs))
? [...selectedDocs, option]
: [option];
dispatch(setSelectedDocs(updatedDocs));
handlePostDocumentSelect(updatedDocs);
}
}}
>