fix(export): optimizar lógica de descarga y manejo de estado en componentes de exportación

Se eliminan condiciones innecesarias en el componente ExportDropdown y se mejora la lógica de selección de publicaciones en DashboardPage y GroupResultsPage. Se asegura que la desactivación de botones se base únicamente en el estado de carga y cooldown, mejorando la experiencia del usuario al evitar mensajes de notificación redundantes.
This commit is contained in:
Alexis
2026-06-03 12:44:34 +02:00
parent 15eeee52d1
commit e08fa17b7b
3 changed files with 24 additions and 32 deletions
@@ -26,9 +26,6 @@ export function ExportDropdown({
const isBusy = Boolean(exportingFormat); const isBusy = Boolean(exportingFormat);
const hasSelection = selectedCount > 0; const hasSelection = selectedCount > 0;
const nothingToDownload =
isAuthenticated && !hasSelection && newPublicationsCount === 0;
function handleDownload() { function handleDownload() {
const { format, profile } = resolveExportFromDestination(exportDestination); const { format, profile } = resolveExportFromDestination(exportDestination);
onExport(format, profile); onExport(format, profile);
@@ -62,7 +59,7 @@ export function ExportDropdown({
<button <button
type="button" type="button"
onClick={handleDownload} onClick={handleDownload}
disabled={disabled || isBusy || nothingToDownload} disabled={disabled || isBusy}
className="inline-flex w-full items-center justify-center gap-2 rounded-lg border border-surface-border-strong bg-surface-primary px-[18px] py-2.5 text-sm font-medium text-ink-primary transition-colors enabled:hover:bg-surface-secondary disabled:cursor-not-allowed disabled:opacity-70 sm:w-auto" className="inline-flex w-full items-center justify-center gap-2 rounded-lg border border-surface-border-strong bg-surface-primary px-[18px] py-2.5 text-sm font-medium text-ink-primary transition-colors enabled:hover:bg-surface-secondary disabled:cursor-not-allowed disabled:opacity-70 sm:w-auto"
> >
{isBusy ? ( {isBusy ? (
+13 -12
View File
@@ -245,15 +245,9 @@ export function DashboardPage() {
// Manual selection takes priority // Manual selection takes priority
ids = Array.from(selectedIds); ids = Array.from(selectedIds);
} else if (isAuthenticated) { } else if (isAuthenticated) {
// Authenticated → only download publications not yet downloaded by me // Prefer undownloaded; if none left, allow re-downloading the full profile
ids = newPublicationIds; ids =
if (ids.length === 0) { newPublicationIds.length > 0 ? newPublicationIds : undefined;
toast.info("No hay publicaciones nuevas", {
id: EXPORT_TOAST_ID,
description: "Ya has descargado todas las publicaciones de este investigador.",
});
return;
}
} else { } else {
// Anonymous → download everything // Anonymous → download everything
ids = undefined; ids = undefined;
@@ -282,12 +276,19 @@ export function DashboardPage() {
if (selectedIds.size > 0) { if (selectedIds.size > 0) {
scope = `${selectedIds.size} publicación${selectedIds.size === 1 ? "" : "es"} seleccionada${selectedIds.size === 1 ? "" : "s"}`; scope = `${selectedIds.size} publicación${selectedIds.size === 1 ? "" : "es"} seleccionada${selectedIds.size === 1 ? "" : "s"}`;
} else if (isAuthenticated) { } else if (isAuthenticated) {
scope = `${newPublicationIds.length} publicación${newPublicationIds.length === 1 ? "" : "es"} nueva${newPublicationIds.length === 1 ? "" : "s"}`; scope =
newPublicationIds.length > 0
? `${newPublicationIds.length} publicación${newPublicationIds.length === 1 ? "" : "es"} nueva${newPublicationIds.length === 1 ? "" : "s"}`
: "todo el investigador";
} else { } else {
scope = "todo el investigador"; scope = "todo el investigador";
} }
if (isAuthenticated && ids?.length) { if (isAuthenticated) {
setPublications((prev) => markPublicationsAsDownloaded(prev, ids)); const downloadedIds =
ids?.length > 0 ? ids : publications.map((p) => p.id);
setPublications((prev) =>
markPublicationsAsDownloaded(prev, downloadedIds),
);
} }
toast.success(`Exportación ${format.toUpperCase()} completada`, { toast.success(`Exportación ${format.toUpperCase()} completada`, {
+7 -13
View File
@@ -182,18 +182,14 @@ export function GroupResultsPage() {
return; return;
} }
const ids = isAuthenticated ? allNewIds : allIds; const ids =
isAuthenticated && allNewIds.length > 0 ? allNewIds : allIds;
if (ids.length === 0) { if (ids.length === 0) {
toast.info( toast.info("No hay publicaciones para exportar", {
isAuthenticated
? "No hay publicaciones nuevas"
: "No hay publicaciones para exportar",
{
id: GLOBAL_EXPORT_TOAST_ID, id: GLOBAL_EXPORT_TOAST_ID,
description: description:
"No se encontraron publicaciones en los investigadores cargados.", "No se encontraron publicaciones en los investigadores cargados.",
}, });
);
return; return;
} }
@@ -253,7 +249,8 @@ export function GroupResultsPage() {
const until = cardExportCooldownUntilRef.current[orcidId] ?? 0; const until = cardExportCooldownUntilRef.current[orcidId] ?? 0;
if (now < until) return; if (now < until) return;
const ids = isAuthenticated ? newIds : totalIds; const ids =
isAuthenticated && newIds.length > 0 ? newIds : totalIds;
if (ids.length === 0) { if (ids.length === 0) {
toast.info("No hay publicaciones para exportar", { toast.info("No hay publicaciones para exportar", {
id: `group-export-card-${orcidId}`, id: `group-export-card-${orcidId}`,
@@ -552,10 +549,7 @@ function CardExportButton({
exportCooldownActive, exportCooldownActive,
}) { }) {
const isBusy = Boolean(exporting); const isBusy = Boolean(exporting);
const disabled = const disabled = isBusy || exportCooldownActive;
isBusy ||
exportCooldownActive ||
(isAuthenticated && !hasNew && totalCount > 0 && newCount === 0);
let label; let label;
if (isBusy) { if (isBusy) {