web: fix sync progress in account recovery

This commit is contained in:
Abdullah Atta
2023-11-02 10:35:06 +05:00
parent dbfb1168fb
commit 76237ad7dd

View File

@@ -329,23 +329,14 @@ function RecoveryMethods(props: BaseRecoveryComponentProps<"methods">) {
function RecoveryKeyMethod(props: BaseRecoveryComponentProps<"method:key">) {
const { navigate } = props;
const [progress, setProgress] = useState("0");
const [progress, setProgress] = useState(0);
useEffect(() => {
db.eventManager.subscribe(
EVENTS.syncProgress,
({
type,
total,
current
}: {
type: string;
total: number;
current: number;
}) => {
if (total === current) return;
({ type, current }: { type: string; current: number }) => {
if (type === "download") {
setProgress(((current / total) * 100).toFixed());
setProgress(current);
}
}
);
@@ -358,11 +349,11 @@ function RecoveryKeyMethod(props: BaseRecoveryComponentProps<"method:key">) {
title="Recover your account"
subtitle={"Use a data recovery key to reset your account password."}
loading={{
title: `Downloading your data (${progress}%)`,
title: `Downloading your data (${progress})`,
subtitle: "Please wait while your data is downloaded & decrypted."
}}
onSubmit={async (form) => {
setProgress("0");
setProgress(0);
const user = await db.user?.getUser();
if (!user) throw new Error("User not authenticated");
@@ -479,14 +470,13 @@ function BackupData(props: BaseRecoveryComponentProps<"backup">) {
function NewPassword(props: BaseRecoveryComponentProps<"new">) {
const { navigate, formData } = props;
const [progress, setProgress] = useState("0");
const [progress, setProgress] = useState(0);
useEffect(() => {
db.eventManager.subscribe(
EVENTS.syncProgress,
({ total, current }: { total: number; current: number }) => {
if (total === current) return;
setProgress(((current / total) * 100).toFixed());
({ current }: { current: number }) => {
setProgress(current);
}
);
}, []);
@@ -500,11 +490,11 @@ function NewPassword(props: BaseRecoveryComponentProps<"new">) {
"Notesnook is E2E encrypted — your password never leaves this device."
}
loading={{
title: `Resetting account password (${progress}%)`,
title: `Resetting account password (${progress})`,
subtitle: "Please wait while we reset your account password."
}}
onSubmit={async (form) => {
setProgress("0");
setProgress(0);
if (form.password !== form.confirmPassword)
throw new Error("Passwords do not match.");