Merge branch 'fix/already-downloaded' into 'main'
fix(export): optimizar lógica de descarga y manejo de estado en componentes de exportación See merge request fjmimbre/orcid_system!6
This commit is contained in:
@@ -26,9 +26,6 @@ export function ExportDropdown({
|
||||
const isBusy = Boolean(exportingFormat);
|
||||
const hasSelection = selectedCount > 0;
|
||||
|
||||
const nothingToDownload =
|
||||
isAuthenticated && !hasSelection && newPublicationsCount === 0;
|
||||
|
||||
function handleDownload() {
|
||||
const { format, profile } = resolveExportFromDestination(exportDestination);
|
||||
onExport(format, profile);
|
||||
@@ -62,7 +59,7 @@ export function ExportDropdown({
|
||||
<button
|
||||
type="button"
|
||||
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"
|
||||
>
|
||||
{isBusy ? (
|
||||
|
||||
@@ -245,15 +245,9 @@ export function DashboardPage() {
|
||||
// Manual selection takes priority
|
||||
ids = Array.from(selectedIds);
|
||||
} else if (isAuthenticated) {
|
||||
// Authenticated → only download publications not yet downloaded by me
|
||||
ids = newPublicationIds;
|
||||
if (ids.length === 0) {
|
||||
toast.info("No hay publicaciones nuevas", {
|
||||
id: EXPORT_TOAST_ID,
|
||||
description: "Ya has descargado todas las publicaciones de este investigador.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Prefer undownloaded; if none left, allow re-downloading the full profile
|
||||
ids =
|
||||
newPublicationIds.length > 0 ? newPublicationIds : undefined;
|
||||
} else {
|
||||
// Anonymous → download everything
|
||||
ids = undefined;
|
||||
@@ -282,12 +276,19 @@ export function DashboardPage() {
|
||||
if (selectedIds.size > 0) {
|
||||
scope = `${selectedIds.size} publicación${selectedIds.size === 1 ? "" : "es"} seleccionada${selectedIds.size === 1 ? "" : "s"}`;
|
||||
} 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 {
|
||||
scope = "todo el investigador";
|
||||
}
|
||||
if (isAuthenticated && ids?.length) {
|
||||
setPublications((prev) => markPublicationsAsDownloaded(prev, ids));
|
||||
if (isAuthenticated) {
|
||||
const downloadedIds =
|
||||
ids?.length > 0 ? ids : publications.map((p) => p.id);
|
||||
setPublications((prev) =>
|
||||
markPublicationsAsDownloaded(prev, downloadedIds),
|
||||
);
|
||||
}
|
||||
|
||||
toast.success(`Exportación ${format.toUpperCase()} completada`, {
|
||||
|
||||
@@ -182,18 +182,14 @@ export function GroupResultsPage() {
|
||||
return;
|
||||
}
|
||||
|
||||
const ids = isAuthenticated ? allNewIds : allIds;
|
||||
const ids =
|
||||
isAuthenticated && allNewIds.length > 0 ? allNewIds : allIds;
|
||||
if (ids.length === 0) {
|
||||
toast.info(
|
||||
isAuthenticated
|
||||
? "No hay publicaciones nuevas"
|
||||
: "No hay publicaciones para exportar",
|
||||
{
|
||||
toast.info("No hay publicaciones para exportar", {
|
||||
id: GLOBAL_EXPORT_TOAST_ID,
|
||||
description:
|
||||
"No se encontraron publicaciones en los investigadores cargados.",
|
||||
},
|
||||
);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,7 +249,8 @@ export function GroupResultsPage() {
|
||||
const until = cardExportCooldownUntilRef.current[orcidId] ?? 0;
|
||||
if (now < until) return;
|
||||
|
||||
const ids = isAuthenticated ? newIds : totalIds;
|
||||
const ids =
|
||||
isAuthenticated && newIds.length > 0 ? newIds : totalIds;
|
||||
if (ids.length === 0) {
|
||||
toast.info("No hay publicaciones para exportar", {
|
||||
id: `group-export-card-${orcidId}`,
|
||||
@@ -552,10 +549,7 @@ function CardExportButton({
|
||||
exportCooldownActive,
|
||||
}) {
|
||||
const isBusy = Boolean(exporting);
|
||||
const disabled =
|
||||
isBusy ||
|
||||
exportCooldownActive ||
|
||||
(isAuthenticated && !hasNew && totalCount > 0 && newCount === 0);
|
||||
const disabled = isBusy || exportCooldownActive;
|
||||
|
||||
let label;
|
||||
if (isBusy) {
|
||||
|
||||
Reference in New Issue
Block a user