Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor(gallery):rename-pct-to-precentage

Aswin Asokd51a03f50a7f
diff --git a/web/apps/photos/tests/download-progress.test.ts b/web/apps/photos/tests/download-progress.test.ts
index 21ee216355..96e1325d8c 100644
--- a/web/apps/photos/tests/download-progress.test.ts
+++ b/web/apps/photos/tests/download-progress.test.ts
@@ -12,18 +12,18 @@ describe("downloadProgressState", () => {
);
expect(downloaded).toEqual({
phase: "decrypting",
- pct: 100,
+ precentage: 100,
loaded: 100,
total: 100,
});
const tail = downloadProgressState(loading, undefined, downloaded);
- expect(tail).toEqual({ phase: "decrypting", pct: 100 });
+ expect(tail).toEqual({ phase: "decrypting", precentage: 100 });
expect(downloadProgressState(loading, undefined, tail)).toEqual(tail);
});
test("prepares HLS auto video without a download entry, then hides", () => {
const preparing = downloadProgressState(loading, undefined, undefined);
- expect(preparing).toEqual({ phase: "preparing", pct: 0 });
+ expect(preparing).toEqual({ phase: "preparing", precentage: 0 });
expect(downloadProgressState({}, undefined, preparing)).toBeUndefined();
});
@@ -32,11 +32,14 @@ describe("downloadProgressState", () => {
downloadProgressState(
{},
{ loaded: 30, total: 100 },
- { phase: "downloading", pct: 30 },
+ { phase: "downloading", precentage: 30 },
),
).toBeUndefined();
expect(
- downloadProgressState({}, undefined, { phase: "failed", pct: 70 }),
+ downloadProgressState({}, undefined, {
+ phase: "failed",
+ precentage: 70,
+ }),
).toBeUndefined();
});
@@ -47,7 +50,12 @@ describe("downloadProgressState", () => {
{ loaded: 117, total: 100 },
undefined,
),
- ).toEqual({ phase: "decrypting", pct: 100, loaded: 117, total: 100 });
+ ).toEqual({
+ phase: "decrypting",
+ precentage: 100,
+ loaded: 117,
+ total: 100,
+ });
});
test("shows unknown totals as indeterminate and retains the download tail", () => {
@@ -58,12 +66,12 @@ describe("downloadProgressState", () => {
);
expect(state).toEqual({
phase: "downloading",
- pct: undefined,
+ precentage: undefined,
loaded: 30,
});
expect(downloadProgressState(loading, undefined, state)).toEqual({
phase: "decrypting",
- pct: 100,
+ precentage: 100,
});
});
@@ -71,25 +79,25 @@ describe("downloadProgressState", () => {
expect(
downloadProgressState({ fetchFailed: true }, undefined, {
phase: "downloading",
- pct: 42,
+ precentage: 42,
}),
- ).toEqual({ phase: "failed", pct: 42 });
+ ).toEqual({ phase: "failed", precentage: 42 });
expect(
downloadProgressState(
{ ...loading, fetchFailed: true },
{ loaded: 100, total: 100 },
undefined,
),
- ).toEqual({ phase: "failed", pct: 0 });
+ ).toEqual({ phase: "failed", precentage: 0 });
});
test("retry ignores the previous failed percentage", () => {
expect(
downloadProgressState(loading, undefined, {
phase: "failed",
- pct: 42,
+ precentage: 42,
}),
- ).toEqual({ phase: "preparing", pct: 0 });
+ ).toEqual({ phase: "preparing", precentage: 0 });
});
test("opens on an in-flight download without previous state", () => {
@@ -99,7 +107,12 @@ describe("downloadProgressState", () => {
{ loaded: 30, total: 100 },
undefined,
),
- ).toEqual({ phase: "downloading", pct: 30, loaded: 30, total: 100 });
+ ).toEqual({
+ phase: "downloading",
+ precentage: 30,
+ loaded: 30,
+ total: 100,
+ });
});
test("prepares a known total with no bytes and floors partial percentages", () => {
@@ -109,13 +122,13 @@ describe("downloadProgressState", () => {
{ loaded: 0, total: 100 },
undefined,
),
- ).toEqual({ phase: "preparing", pct: 0 });
+ ).toEqual({ phase: "preparing", precentage: 0 });
expect(
downloadProgressState(
loading,
{ loaded: 9999, total: 10000 },
undefined,
- )?.pct,
+ )?.precentage,
).toBe(99);
});
});
diff --git a/web/packages/gallery/components/viewer/download-progress.ts b/web/packages/gallery/components/viewer/download-progress.ts
index 0e75355016..ea34f4b3a5 100644
--- a/web/packages/gallery/components/viewer/download-progress.ts
+++ b/web/packages/gallery/components/viewer/download-progress.ts
@@ -9,7 +9,7 @@ export type DownloadProgressPhase =
export interface DownloadProgressState {
phase: DownloadProgressPhase;
- pct: number | undefined;
+ precentage: number | undefined;
loaded?: number;
total?: number;
}
@@ -20,30 +20,33 @@ export const downloadProgressState = (
previous: DownloadProgressState | undefined,
): DownloadProgressState | undefined => {
if (itemData.fetchFailed)
- return { phase: "failed", pct: previous?.pct ?? 0 };
+ return { phase: "failed", precentage: previous?.precentage ?? 0 };
if (!itemData.isContentLoading) return undefined;
if (entry) {
const { loaded, total } = entry;
if (total !== undefined && total > 0) {
if (loaded >= total)
- return { phase: "decrypting", pct: 100, loaded, total };
+ return { phase: "decrypting", precentage: 100, loaded, total };
if (loaded > 0)
return {
phase: "downloading",
- pct: Math.min(99, Math.floor((loaded * 100) / total)),
+ precentage: Math.min(
+ 99,
+ Math.floor((loaded * 100) / total),
+ ),
loaded,
total,
};
- return { phase: "preparing", pct: 0 };
+ return { phase: "preparing", precentage: 0 };
}
if (total === undefined && loaded > 0)
- return { phase: "downloading", pct: undefined, loaded };
+ return { phase: "downloading", precentage: undefined, loaded };
} else if (
previous?.phase == "downloading" ||
previous?.phase == "decrypting"
) {
- return { phase: "decrypting", pct: 100 };
+ return { phase: "decrypting", precentage: 100 };
}
- return { phase: "preparing", pct: 0 };
+ return { phase: "preparing", precentage: 0 };
};
diff --git a/web/packages/gallery/components/viewer/photoswipe-core.ts b/web/packages/gallery/components/viewer/photoswipe-core.ts
index 7a919872c7..be963b1c7e 100644
--- a/web/packages/gallery/components/viewer/photoswipe-core.ts
+++ b/web/packages/gallery/components/viewer/photoswipe-core.ts
@@ -855,7 +855,7 @@ export class FileViewerPhotoSwipe<
let progressRing: SVGCircleElement;
let progressBar: HTMLElement;
let fill: HTMLElement;
- let pct: HTMLElement;
+ let precentage: HTMLElement;
let status: HTMLElement;
let separator: HTMLElement;
let size: HTMLElement;
@@ -892,7 +892,10 @@ export class FileViewerPhotoSwipe<
const state = rememberDownloadProgress();
const failed = state?.phase == "failed";
- const pctText = state?.pct === undefined ? "" : `${state.pct}%`;
+ const precentageText =
+ state?.precentage === undefined
+ ? ""
+ : `${state.precentage}%`;
const statusText = state
? t(
{
@@ -913,15 +916,15 @@ export class FileViewerPhotoSwipe<
})
: `${formattedByteSize(state.loaded, 1)} / ${formattedByteSize(state.total, 1)}`
: "";
- setText(pct, pctText);
+ setText(precentage, precentageText);
setText(status, statusText);
setText(size, sizeText);
setText(retry, t("retry"));
size.hidden = !sizeText;
separator.hidden = !(sizeText || failed);
retry.hidden = !failed;
- fill.style.width = `${Math.max(state?.pct ?? 0, 1)}%`;
- progressRing.style.strokeDashoffset = `${100 - (state?.pct ?? 0)}`;
+ fill.style.width = `${Math.max(state?.precentage ?? 0, 1)}%`;
+ progressRing.style.strokeDashoffset = `${100 - (state?.precentage ?? 0)}`;
for (const [element, prefix] of [
[progressText, "pswp__ente-progress-text"],
[progressValue, "pswp__ente-progress-overlay"],
@@ -931,7 +934,7 @@ export class FileViewerPhotoSwipe<
element.classList.toggle(`${prefix}--failed`, failed);
element.classList.toggle(
`${prefix}--indeterminate`,
- !!state && state.pct === undefined,
+ !!state && state.precentage === undefined,
);
}
setAttribute(
@@ -947,13 +950,13 @@ export class FileViewerPhotoSwipe<
setAttribute(
progressValue,
"aria-valuenow",
- state?.pct?.toString(),
+ state?.precentage?.toString(),
);
setAttribute(
progressValue,
"aria-valuetext",
[
- pctText,
+ precentageText,
!(compactProgress.matches && sizeText) && statusText,
!compactProgress.matches && (sizeText || failed) && "Β·",
sizeText,
@@ -1005,7 +1008,7 @@ export class FileViewerPhotoSwipe<
onInit: (element) => {
progressValue = element;
progressRing = element.querySelector("circle")!;
- pct = element.querySelector<HTMLElement>(
+ precentage = element.querySelector<HTMLElement>(
".pswp__ente-progress-pct",
)!;
element.setAttribute("role", "progressbar");