From 614ef3ffaf5d3e4356406d2a3d0bad0cc1417129 Mon Sep 17 00:00:00 2001 From: Guillermo Arrieta Medina Date: Tue, 10 Mar 2026 14:37:07 -0600 Subject: [PATCH] =?UTF-8?q?El=20textarea=20de=20los=20autores=20ya=20te=20?= =?UTF-8?q?permite=20a=C3=B1adir=20m=C3=A1s=20autores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nueva/NuevaBibliografiaModalContainer.tsx | 50 ++++++++++++++----- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx b/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx index 4e8703c..a079fc3 100644 --- a/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx +++ b/src/features/bibliografia/nueva/NuevaBibliografiaModalContainer.tsx @@ -1408,6 +1408,34 @@ function FormatoYCitasStep({ onChangeTipo: (id: string, tipo: BibliografiaTipo) => void }) { const isGeneratingAny = generatingIds.size > 0 + const [authorsDraftById, setAuthorsDraftById] = useState< + Record + >({}) + + useEffect(() => { + const ids = new Set(refs.map((r) => r.id)) + setAuthorsDraftById((prev) => { + let next = prev + + // Remove drafts for refs that no longer exist + for (const id of Object.keys(prev)) { + if (!ids.has(id)) { + if (next === prev) next = { ...prev } + delete next[id] + } + } + + // Initialize drafts for new refs (do not override existing edits) + for (const r of refs) { + if (typeof next[r.id] !== 'string') { + if (next === prev) next = { ...prev } + next[r.id] = r.authors.join('\n') + } + } + + return next + }) + }, [refs]) return (
@@ -1461,17 +1489,9 @@ function FormatoYCitasStep({
{refs.map((r) => { - const infoText = [ - r.authors.join(', '), - r.publisher, - r.year ? String(r.year) : undefined, - ] - .filter(Boolean) - .join(' • ') - const isGenerating = generatingIds.has(r.id) - const authorsText = r.authors.join('\n') + const authorsText = authorsDraftById[r.id] ?? r.authors.join('\n') const yearText = typeof r.year === 'number' ? String(r.year) : '' const isbnText = r.isbn ?? '' const publisherText = r.publisher ?? '' @@ -1520,14 +1540,20 @@ function FormatoYCitasStep({ value={authorsText} disabled={isGeneratingAny || isGenerating} className="min-h-22.5" - onChange={(e) => + onChange={(e) => { + const nextText = e.currentTarget.value + setAuthorsDraftById((prev) => ({ + ...prev, + [r.id]: nextText, + })) + onChangeRef(r.id, { - authors: e.currentTarget.value + authors: nextText .split(/\r?\n/) .map((x) => x.trim()) .filter(Boolean), }) - } + }} />