Skip to content

Commit 7add7e8

Browse files
committed
Combine user files + regular uploaded files
1 parent 88f30ce commit 7add7e8

File tree

1 file changed

+93
-53
lines changed

1 file changed

+93
-53
lines changed

web/src/app/chat/input/ChatInputBar.tsx

Lines changed: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,45 @@ export function ChatInputBar({
444444
}
445445
};
446446

447+
// Combine selectedFiles and currentMessageFiles for unified rendering
448+
const allFiles = useMemo(() => {
449+
const combined: Array<{
450+
id: string;
451+
name: string;
452+
chatFileType: ChatFileType;
453+
isUploading?: boolean;
454+
source: "selected" | "current";
455+
originalFile: any;
456+
}> = [];
457+
458+
// Add selected files (excluding those already in currentMessageFiles)
459+
selectedFiles.forEach((file) => {
460+
if (!currentMessageFileIds.has(String(file.file_id || file.id))) {
461+
combined.push({
462+
id: String(file.file_id || file.id),
463+
name: file.name,
464+
chatFileType: file.chat_file_type,
465+
source: "selected",
466+
originalFile: file,
467+
});
468+
}
469+
});
470+
471+
// Add current message files
472+
currentMessageFiles.forEach((file, index) => {
473+
combined.push({
474+
id: file.id,
475+
name: file.name || `File${file.id}`,
476+
chatFileType: file.type,
477+
isUploading: file.isUploading,
478+
source: "current",
479+
originalFile: file,
480+
});
481+
});
482+
483+
return combined;
484+
}, [selectedFiles, currentMessageFiles, currentMessageFileIds]);
485+
447486
return (
448487
<div id="onyx-chat-input">
449488
<div className="flex justify-center mx-auto">
@@ -669,20 +708,60 @@ export function ChatInputBar({
669708
/>
670709
))}
671710

672-
{/* This is excluding image types because they get rendered differently via currentMessageFiles.map
673-
Seems quite hacky ... all rendering should probably be done in one place? */}
674-
{selectedFiles.map(
675-
(file) =>
676-
!currentMessageFileIds.has(
677-
String(file.file_id || file.id)
678-
) && (
679-
<SourceChip
680-
key={file.id}
681-
icon={<FileIcon size={16} />}
682-
title={file.name}
683-
onRemove={() => removeSelectedFile(file)}
684-
/>
685-
)
711+
{/* Unified file rendering section for both selected and current message files */}
712+
{allFiles.map((file, index) =>
713+
file.chatFileType === ChatFileType.IMAGE ? (
714+
<SourceChip
715+
key={`${file.source}-${file.id}-${index}`}
716+
icon={
717+
file.isUploading ? (
718+
<FiLoader className="animate-spin" />
719+
) : (
720+
<img
721+
className="h-full py-.5 object-cover rounded-lg bg-background cursor-pointer"
722+
src={buildImgUrl(file.id)}
723+
alt={file.name || "File image"}
724+
/>
725+
)
726+
}
727+
title={file.name}
728+
onRemove={() => {
729+
if (file.source === "selected") {
730+
removeSelectedFile(file.originalFile);
731+
} else {
732+
setCurrentMessageFiles(
733+
currentMessageFiles.filter(
734+
(fileInFilter) => fileInFilter.id !== file.id
735+
)
736+
);
737+
}
738+
}}
739+
/>
740+
) : (
741+
<SourceChip
742+
key={`${file.source}-${file.id}-${index}`}
743+
icon={
744+
<FileIcon
745+
className={
746+
file.source === "current" ? "text-red-500" : ""
747+
}
748+
size={16}
749+
/>
750+
}
751+
title={file.name}
752+
onRemove={() => {
753+
if (file.source === "selected") {
754+
removeSelectedFile(file.originalFile);
755+
} else {
756+
setCurrentMessageFiles(
757+
currentMessageFiles.filter(
758+
(fileInFilter) => fileInFilter.id !== file.id
759+
)
760+
);
761+
}
762+
}}
763+
/>
764+
)
686765
)}
687766
{selectedFolders.map((folder) => (
688767
<SourceChip
@@ -752,45 +831,6 @@ export function ChatInputBar({
752831
onRemove={removeDocs}
753832
/>
754833
)}
755-
{currentMessageFiles.map((file, index) =>
756-
file.type === ChatFileType.IMAGE ? (
757-
<SourceChip
758-
key={`file-${index}`}
759-
icon={
760-
file.isUploading ? (
761-
<FiLoader className="animate-spin" />
762-
) : (
763-
<img
764-
className="h-full py-.5 object-cover rounded-lg bg-background cursor-pointer"
765-
src={buildImgUrl(file.id)}
766-
alt={file.name || "Uploaded image"}
767-
/>
768-
)
769-
}
770-
title={file.name || "File" + file.id}
771-
onRemove={() => {
772-
setCurrentMessageFiles(
773-
currentMessageFiles.filter(
774-
(fileInFilter) => fileInFilter.id !== file.id
775-
)
776-
);
777-
}}
778-
/>
779-
) : (
780-
<SourceChip
781-
key={`file-${index}`}
782-
icon={<FileIcon className="text-red-500" size={16} />}
783-
title={file.name || "File"}
784-
onRemove={() => {
785-
setCurrentMessageFiles(
786-
currentMessageFiles.filter(
787-
(fileInFilter) => fileInFilter.id !== file.id
788-
)
789-
);
790-
}}
791-
/>
792-
)
793-
)}
794834
</div>
795835
</div>
796836
)}

0 commit comments

Comments
 (0)