Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(resources): make the download dialog's sizes add up
Elian Dorancba1b2e24545
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 978f662346..fe0c0a394f 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -4610,7 +4610,7 @@"resource_download": {"title": "Download required","intro": "Trilium needs to download the following files before it can continue. They are saved on this device and are not synced, so each of your devices downloads them separately.",- "partially_downloaded": "{{size}} already downloaded",+ "partially_downloaded": "Already downloaded","sources": "From {{sources}}","total": "Download size","free_space": "Free space: {{size}}",diff --git a/apps/client/src/widgets/dialogs/resource_download.spec.tsx b/apps/client/src/widgets/dialogs/resource_download.spec.tsxindex a035e125ec..88a814310c 100644--- a/apps/client/src/widgets/dialogs/resource_download.spec.tsx+++ b/apps/client/src/widgets/dialogs/resource_download.spec.tsx@@ -69,8 +69,10 @@ describe("ResourceDownloadDialog", () => {expect(text(".resource-download-meta")).toContain("huggingface.co, github.com");expect(text(".resource-download-license")).toBe(`resource_download.license:{"license":"CC-BY-4.0"}`);- expect(text(".resource-download-meta")).toContain(`"size":"200 B"`);- expect(text(".resource-download-item .resource-download-size")).toBe("700 B");+ expect(row?.querySelector("[role=progressbar]")?.getAttribute("aria-valuenow")).toBe("200");+ expect(row?.querySelector(".resource-download-progress")?.textContent)+ .toContain(`"received":"200 B","total":"700 B"`);+ expect(text(".resource-download-item .resource-download-size")).toBe("500 B");expect(text(".resource-download-total .resource-download-size")).toBe("500 B");expect(text(".resource-download-total")).toContain(`free_space:{"size":"9.77 KiB"}`);expect(container.querySelector(".admonition")).toBeNull();diff --git a/apps/client/src/widgets/dialogs/resource_download.tsx b/apps/client/src/widgets/dialogs/resource_download.tsxindex a1b63f3f88..95a74cc9ef 100644--- a/apps/client/src/widgets/dialogs/resource_download.tsx+++ b/apps/client/src/widgets/dialogs/resource_download.tsx@@ -147,7 +147,6 @@ interface ResourceListProps {function ResourceList({ status, remaining, download }: ResourceListProps) {const missing = status.resources.filter(({ installed }) => !installed);- const unitOf = Math.max(remaining, ...missing.map(({ size }) => size));const activeId = download?.status === "downloading"? download.resources.find(({ done }) => !done)?.id: undefined;@@ -160,7 +159,7 @@ function ResourceList({ status, remaining, download }: ResourceListProps) {<ResourceItemkey={resource.id}resource={resource}- unitOf={unitOf}+ unitOf={remaining}state={download?.resources.find(({ id }) => id === resource.id)}file={resource.id === activeId ? download?.file ?? null : undefined}/>@@ -177,7 +176,7 @@ function ResourceList({ status, remaining, download }: ResourceListProps) {)}</div><span className="tn-card-option-value resource-download-size">- {formatSize(remaining, 2, unitOf)}+ {formatSize(remaining, 2, remaining)}</span></CardSection></Card>@@ -195,12 +194,15 @@ interface ResourceItemProps {}/**- * One resource as a settings row: its icon, what it is and where it comes from, and its size.- * Once a download starts, the icon shows whether the resource is done, downloading or waiting, as- * the setup's sync steps do, and the resource downloading carries its own progress bar.+ * One resource as a settings row: its icon, what it is and where it comes from, and what is left+ * to download of it, so that the rows add up to the download size. Once a download starts, the+ * icon shows whether the resource is done, downloading or waiting, as the setup's sync steps do.+ * The resource downloading carries a progress bar, and so does one an earlier download left+ * partly fetched, filled as far as it got.*/function ResourceItem({ resource, unitOf, state, file }: ResourceItemProps) {const isActive = file !== undefined;+ const isPartial = !state?.done && resource.downloadedSize > 0;return (<CardSection className="tn-card-option resource-download-item"><Icon icon={getRowIcon(resource, state, isActive)} className="resource-download-icon" />@@ -213,32 +215,46 @@ function ResourceItem({ resource, unitOf, state, file }: ResourceItemProps) {<span className="resource-download-license">{t("resource_download.license", { license: resource.license })}</span>- {resource.downloadedSize > 0 && <>- {" · "}- {t("resource_download.partially_downloaded", {- size: formatSize(resource.downloadedSize)- })}- </>}</small>- {isActive && state && <RowProgress state={state} file={file ?? null} />}+ {isActive && state && (+ <RowProgress+ received={state.receivedBytes}+ total={state.totalBytes}+ label={file && t("resource_download.current_file", { file })}+ />+ )}+ {!isActive && isPartial && (+ <RowProgress+ received={resource.downloadedSize}+ total={resource.size}+ label={t("resource_download.partially_downloaded")}+ />+ )}</div><span className="tn-card-option-value resource-download-size">- {formatSize(resource.size, 2, unitOf)}+ {formatSize(resource.size - resource.downloadedSize, 2, unitOf)}</span></CardSection>);}-function RowProgress({ state, file }: { state: ResourceDownloadState; file: string | null }) {+interface RowProgressProps {+ received: number;+ total: number;+ /** What the bar shows, on its leading edge below it. */+ label: string | null;+}++function RowProgress({ received, total, label }: RowProgressProps) {return (<div className="resource-download-progress">- <ProgressBar value={state.receivedBytes} max={state.totalBytes} />+ <ProgressBar value={received} max={total} /><small className="tn-card-option-description resource-download-progress-detail">- <span>{file && t("resource_download.current_file", { file })}</span>+ <span>{label}</span><span>{t("resource_download.progress", {- received: formatSize(state.receivedBytes, 2, state.totalBytes),- total: formatSize(state.totalBytes)+ received: formatSize(received, 2, total),+ total: formatSize(total)})}</span></small>