mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-09-01 19:49:54 +02:00
mobile: fix logout button not working in user sheet
This commit is contained in:
committed by
Abdullah Atta
parent
8a06d258a0
commit
f59b7330a1
@@ -39,6 +39,7 @@ import Paragraph from "../../ui/typography/paragraph";
|
||||
import Sync from "../../../services/sync";
|
||||
|
||||
import Clipboard from "@react-native-clipboard/clipboard";
|
||||
import { logoutUser } from "../../../screens/settings/logout";
|
||||
export const UserSheet = () => {
|
||||
const ref = useSheetRef();
|
||||
const { colors } = useThemeColors();
|
||||
@@ -313,6 +314,8 @@ export const UserSheet = () => {
|
||||
icon: "logout",
|
||||
title: strings.logout(),
|
||||
onPress: () => {
|
||||
console.log("logout");
|
||||
logoutUser();
|
||||
ref.current?.hide();
|
||||
},
|
||||
hidden: !user
|
||||
|
||||
92
apps/mobile/app/screens/settings/logout.ts
Normal file
92
apps/mobile/app/screens/settings/logout.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { strings } from "@notesnook/intl";
|
||||
import { presentDialog } from "../../components/dialog/functions";
|
||||
import { DatabaseLogger, db } from "../../common/database";
|
||||
import { eSendEvent, ToastManager } from "../../services/event-manager";
|
||||
import { eCloseSimpleDialog } from "../../utils/events";
|
||||
import {
|
||||
endProgress,
|
||||
startProgress,
|
||||
updateProgress
|
||||
} from "../../components/dialogs/progress";
|
||||
import Navigation from "../../services/navigation";
|
||||
import BackupService from "../../services/backup";
|
||||
|
||||
export async function logoutUser() {
|
||||
const hasUnsyncedChanges = await db.hasUnsyncedChanges();
|
||||
presentDialog({
|
||||
title: strings.logout(),
|
||||
paragraph: strings.logoutConfirmation(),
|
||||
positiveText: strings.logout(),
|
||||
check: {
|
||||
info: strings.backupDataBeforeLogout(),
|
||||
defaultValue: true
|
||||
},
|
||||
notice: hasUnsyncedChanges
|
||||
? {
|
||||
text: strings.unsyncedChangesWarning(),
|
||||
type: "alert"
|
||||
}
|
||||
: undefined,
|
||||
positivePress: async (_, takeBackup) => {
|
||||
eSendEvent(eCloseSimpleDialog);
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
startProgress({
|
||||
fillBackground: true,
|
||||
title: strings.loggingOut(),
|
||||
canHideProgress: true,
|
||||
paragraph: strings.loggingOutDesc()
|
||||
});
|
||||
|
||||
Navigation.navigate("Notes");
|
||||
|
||||
if (takeBackup) {
|
||||
updateProgress({
|
||||
progress: strings.backingUpData()
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await BackupService.run(false, "local", "partial");
|
||||
if (result?.error) throw result.error as Error;
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
const error = e;
|
||||
const canLogout = await new Promise((resolve) => {
|
||||
presentDialog({
|
||||
context: "local",
|
||||
title: strings.failedToTakeBackup(),
|
||||
paragraph: `${
|
||||
(error as Error).message
|
||||
}. ${strings.failedToTakeBackupMessage()}?`,
|
||||
positiveText: strings.yes(),
|
||||
negativeText: strings.no(),
|
||||
positivePress: () => {
|
||||
resolve(true);
|
||||
},
|
||||
onClose: () => {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!canLogout) {
|
||||
endProgress();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateProgress({
|
||||
progress: strings.loggingOut()
|
||||
});
|
||||
|
||||
await db.user?.logout();
|
||||
endProgress();
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
ToastManager.error(e as Error, strings.logoutError());
|
||||
endProgress();
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -76,6 +76,7 @@ import { useDragState } from "./editor/state";
|
||||
import { verifyUser, verifyUserWithApplock } from "./functions";
|
||||
import { SettingSection } from "./types";
|
||||
import { getTimeLeft } from "./user-section";
|
||||
import { logoutUser } from "./logout";
|
||||
|
||||
export const settingsGroups: SettingSection[] = [
|
||||
{
|
||||
@@ -412,89 +413,7 @@ export const settingsGroups: SettingSection[] = [
|
||||
name: strings.logout(),
|
||||
description: strings.logoutWarnin(),
|
||||
icon: "logout",
|
||||
modifer: async () => {
|
||||
const hasUnsyncedChanges = await db.hasUnsyncedChanges();
|
||||
presentDialog({
|
||||
title: strings.logout(),
|
||||
paragraph: strings.logoutConfirmation(),
|
||||
positiveText: strings.logout(),
|
||||
check: {
|
||||
info: strings.backupDataBeforeLogout(),
|
||||
defaultValue: true
|
||||
},
|
||||
notice: hasUnsyncedChanges
|
||||
? {
|
||||
text: strings.unsyncedChangesWarning(),
|
||||
type: "alert"
|
||||
}
|
||||
: undefined,
|
||||
positivePress: async (_, takeBackup) => {
|
||||
eSendEvent(eCloseSimpleDialog);
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
startProgress({
|
||||
fillBackground: true,
|
||||
title: strings.loggingOut(),
|
||||
canHideProgress: true,
|
||||
paragraph: strings.loggingOutDesc()
|
||||
});
|
||||
|
||||
Navigation.navigate("Notes");
|
||||
|
||||
if (takeBackup) {
|
||||
updateProgress({
|
||||
progress: strings.backingUpData()
|
||||
});
|
||||
|
||||
try {
|
||||
const result = await BackupService.run(
|
||||
false,
|
||||
"local",
|
||||
"partial"
|
||||
);
|
||||
if (result?.error) throw result.error as Error;
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
const error = e;
|
||||
const canLogout = await new Promise((resolve) => {
|
||||
presentDialog({
|
||||
context: "local",
|
||||
title: strings.failedToTakeBackup(),
|
||||
paragraph: `${
|
||||
(error as Error).message
|
||||
}. ${strings.failedToTakeBackupMessage()}?`,
|
||||
positiveText: strings.yes(),
|
||||
negativeText: strings.no(),
|
||||
positivePress: () => {
|
||||
resolve(true);
|
||||
},
|
||||
onClose: () => {
|
||||
resolve(false);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!canLogout) {
|
||||
endProgress();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateProgress({
|
||||
progress: strings.loggingOut()
|
||||
});
|
||||
|
||||
await db.user?.logout();
|
||||
endProgress();
|
||||
} catch (e) {
|
||||
DatabaseLogger.error(e);
|
||||
ToastManager.error(e as Error, strings.logoutError());
|
||||
endProgress();
|
||||
}
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
}
|
||||
modifer: logoutUser
|
||||
},
|
||||
{
|
||||
id: "delete-account",
|
||||
|
||||
Reference in New Issue
Block a user