Files
notesnook/apps/mobile/app/services/message.js

159 lines
3.8 KiB
JavaScript
Raw Permalink Normal View History

/*
This file is part of the Notesnook project (https://notesnook.com/)
2023-01-16 13:44:52 +05:00
Copyright (C) 2023 Streetwriters (Private) Limited
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2023-08-29 20:42:45 +05:00
2024-02-02 18:46:23 +05:00
import React from "react";
2023-02-13 16:49:25 +05:00
import { Platform } from "react-native";
import { verifyUser } from "../screens/settings/functions";
import { useMessageStore } from "../stores/use-message-store";
import {
eOpenLoginDialog,
eOpenRateDialog,
eOpenRecoveryKeyDialog
} from "../utils/events";
2023-07-06 09:29:35 +05:00
import { eSendEvent, presentSheet } from "./event-manager";
import PremiumService from "./premium";
import SettingsService from "./settings";
2023-07-06 09:29:35 +05:00
import { Update } from "../components/sheets/update";
const rateAppMessage = {
visible: true,
message: "We would love to know what you think",
actionText:
"Rate Notesnook on " +
`${Platform.OS === "ios" ? "App store" : "Play store"}`,
onPress: () => {
eSendEvent(eOpenRateDialog);
},
data: {},
icon: "star",
type: "normal"
};
export function setRateAppMessage() {
useMessageStore.getState().setMessage(rateAppMessage);
}
2022-01-02 02:02:18 +05:00
const recoveryKeyMessage = {
visible: true,
2023-09-15 14:59:52 +05:00
message: "Keep your data safe",
actionText: "Save your account recovery key",
2022-01-02 02:02:18 +05:00
onPress: () => {
verifyUser(
null,
() => {
eSendEvent(eOpenRecoveryKeyDialog);
},
2024-05-16 15:09:22 +05:00
false,
2022-01-02 02:02:18 +05:00
async () => {
2022-03-03 15:09:30 +05:00
SettingsService.set({
recoveryKeySaved: true
});
2022-01-02 02:02:18 +05:00
clearMessage();
},
2024-05-16 15:09:22 +05:00
"Cancel"
2022-01-02 02:02:18 +05:00
);
},
data: {},
icon: "key",
type: "normal"
2022-01-02 02:02:18 +05:00
};
export function setRecoveryKeyMessage() {
useMessageStore.getState().setMessage(recoveryKeyMessage);
}
2020-10-26 11:35:42 +05:00
2021-06-05 21:10:20 +05:00
const loginMessage = {
2021-06-07 09:51:00 +05:00
visible: true,
message: "You are not logged in",
actionText: "Login to encrypt and sync notes",
2021-06-07 09:51:00 +05:00
onPress: () => {
eSendEvent(eOpenLoginDialog);
},
data: {},
icon: "account-outline",
type: "normal"
2021-06-07 09:51:00 +05:00
};
2020-12-16 14:57:58 +05:00
2021-06-05 21:10:20 +05:00
export function setLoginMessage() {
2021-06-07 09:51:00 +05:00
useMessageStore.getState().setMessage(loginMessage);
2020-12-10 13:06:59 +05:00
}
2021-06-05 21:10:20 +05:00
const emailMessage = {
2021-06-07 09:51:00 +05:00
visible: true,
message: "Email not confirmed",
actionText: "Please confirm your email to sync notes.",
2021-06-07 09:51:00 +05:00
onPress: () => {
PremiumService.showVerifyEmailDialog();
2021-06-05 21:10:20 +05:00
},
2021-06-07 09:51:00 +05:00
data: {},
icon: "email",
type: "error"
2021-06-07 09:51:00 +05:00
};
2021-06-05 21:10:20 +05:00
export function setEmailVerifyMessage() {
2021-06-07 09:51:00 +05:00
useMessageStore.getState().setMessage(emailMessage);
2021-06-05 21:10:20 +05:00
}
const noMessage = {
2021-06-07 09:51:00 +05:00
visible: false,
message: "",
actionText: "",
2021-06-07 09:51:00 +05:00
onPress: null,
data: {},
icon: "account-outline"
2021-06-07 09:51:00 +05:00
};
2021-06-05 21:10:20 +05:00
export function clearMessage() {
2021-06-07 09:51:00 +05:00
useMessageStore.getState().setMessage(noMessage);
2020-12-16 14:57:58 +05:00
}
2022-10-26 12:19:28 +05:00
const autoBackupsOff = {
visible: true,
message: "Automatic backups turned off",
actionText: "Get Notesnook Pro to enable automatic backups",
onPress: () => {
clearMessage();
},
data: {},
icon: "backup-restore",
type: "error"
};
export function setAutobackOffMessage() {
useMessageStore.getState().setMessage(autoBackupsOff);
}
2023-07-06 09:29:35 +05:00
const updateAvailableMessage = (version) => ({
visible: true,
message: "New update available",
actionText: "Tap here to update to the latest version",
onPress: () => {
presentSheet({
component: (ref) => <Update version={version} fwdRef={ref} />
});
},
data: {},
icon: "update",
type: "normal"
});
export function setUpdateAvailableMessage(version) {
useMessageStore.getState().setMessage(updateAvailableMessage(version));
}