Studio: don't duplicate composer chip when re-uploading an indexed doc

The backend dedups re-uploads and the sidepanel shows the doc once, but
the composer's pending-doc chips are created per addDoc call, so each
re-upload of an already-indexed file appended another 'Ready' chip for
the same document. In the already_indexed branch, if a chip with the
returned documentId already exists, drop the chip we just added instead
of marking it ready — so the composer shows each document only once.
This commit is contained in:
Roland Tannous 2026-05-28 15:33:17 +04:00
commit f30c0a48dd
2 changed files with 26 additions and 9 deletions

View file

@ -128,14 +128,23 @@ export function useThreadDocUploads(): UseThreadDocUploadsResult {
file,
);
if (alreadyIndexed) {
// Identical file already in this scope — no re-index.
setPendingDocs((prev) =>
prev.map((d) =>
// Identical file already in this scope — no re-index. If a
// chip for this document already exists, drop the one we just
// added so the composer doesn't show the same doc twice;
// otherwise mark this chip ready.
setPendingDocs((prev) => {
const dupExists = prev.some(
(d) => d.id !== localChipId && d.documentId === documentId,
);
if (dupExists) {
return prev.filter((d) => d.id !== localChipId);
}
return prev.map((d) =>
d.id === localChipId
? { ...d, status: "ready", documentId }
: d,
),
);
);
});
toast.info(`${file.name} is already indexed`);
if (
scope?.kind === "thread" &&

View file

@ -617,13 +617,21 @@ export function SharedComposer({
file,
);
if (alreadyIndexed) {
setPendingDocs((prev) =>
prev.map((d) =>
// Drop the just-added chip if this doc is already represented
// so the composer never shows the same document twice.
setPendingDocs((prev) => {
const dupExists = prev.some(
(d) => d.id !== localChipId && d.documentId === documentId,
);
if (dupExists) {
return prev.filter((d) => d.id !== localChipId);
}
return prev.map((d) =>
d.id === localChipId
? { ...d, status: "ready", documentId }
: d,
),
);
);
});
toast.info(`${file.name} is already indexed`);
if (
scope?.kind === "thread" &&