A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: show toast when backup is ready instead of dialog
thecodrr5a0a729ca5fd
diff --git a/apps/web/src/common/reminders.js b/apps/web/src/common/reminders.jsindex 37b4f5038..5a94d3912 100644--- a/apps/web/src/common/reminders.js+++ b/apps/web/src/common/reminders.js@@ -102,7 +102,15 @@ export async function resetReminders() {saveFile(filePath, data);showToast("success", `Backup saved at ${filePath}.`);} else if (isUserPremium() && !isTesting()) {- await showBackupDialog();+ const toast = showToast(+ "success",+ "Your backup is ready for download.",+ [+ { text: "Later", onClick: () => toast?.hide(), type: "text" },+ { text: "Download", onClick: () => createBackup(), type: "primary" },+ ],+ 0+ );}}if (await shouldAddLoginReminder()) {diff --git a/apps/web/src/components/dialogs/backupdialog.tsx b/apps/web/src/components/dialogs/backupdialog.tsxdeleted file mode 100644index dcabccde3..000000000--- a/apps/web/src/components/dialogs/backupdialog.tsx+++ /dev/null@@ -1,39 +0,0 @@-import { Text } from "rebass";-import { createBackup } from "../../common";-import Dialog from "./dialog";--type BackupDialogProps = {- onClose: () => void;-};-function BackupDialog(props: BackupDialogProps) {- return (- <Dialog- isOpen={true}- alignment="center"- onClose={props.onClose}- title="Your backup is ready"- description="Download a backup of your notes to keep them safe."- positiveButton={{- text: "Save to disk",- onClick: async () => {- await createBackup(true);- props.onClose();- },- }}- negativeButton={{- text: "Remind me later",- onClick: async () => {- await createBackup(false);- props.onClose();- },- }}- >- <Text variant={"body"}>- In case forget your password or something unfortunate happens, you can- restore a backup to recover lost data.{" "}- </Text>- </Dialog>- );-}--export default BackupDialog;diff --git a/apps/web/src/components/dialogs/index.js b/apps/web/src/components/dialogs/index.jsindex fae02e01e..2ec07b91d 100644--- a/apps/web/src/components/dialogs/index.js+++ b/apps/web/src/components/dialogs/index.js@@ -17,7 +17,6 @@ import IssueDialog from "./issuedialog";import { MultifactorDialog, RecoveryCodesDialog } from "./multi-factor-dialog";import OnboardingDialog from "./onboarding-dialog";import AttachmentsDialog from "./attachmentsdialog";-import BackupDialog from "./backupdialog";const Dialogs = {AddNotebookDialog,@@ -40,6 +39,5 @@ const Dialogs = {RecoveryCodesDialog,OnboardingDialog,AttachmentsDialog,- BackupDialog,};export default Dialogs;diff --git a/apps/web/src/utils/toast.js b/apps/web/src/utils/toast.jsdeleted file mode 100644index 6800696aa..000000000--- a/apps/web/src/utils/toast.js+++ /dev/null@@ -1,70 +0,0 @@-import React from "react";-import CogoToast from "cogo-toast";-import { Button, Flex, Text } from "rebass";-import ThemeProvider from "../components/theme-provider";-import * as Icon from "../components/icons";-import { toTitleCase } from "./string";-import { store as appstore } from "../stores/app-store";-/**- *- * @returns {import("cogo-toast").CTReturn}- */-function showToast(type, message, actions) {- if (appstore.get().isFocusMode) return null;- const IconComponent = Icon[toTitleCase(type)];- const toast = CogoToast[type];- if (!toast) return;- return toast(- <ToastContainer type={type} message={message} actions={actions} />,- {- position: "top-right",- hideAfter: actions ? 5 : type === "error" ? 5 : 3,- bar: { size: "0px" },- renderIcon: () => {- return (- <ThemeProvider>- <IconComponent size={28} color={type} />- </ThemeProvider>- );- },- }- );-}--function ToastContainer(props) {- const { type, message, actions } = props;- return (- <ThemeProvider>- <Flex- data-test-id="toast"- justifyContent="center"- alignContent="center"- my={2}- >- <Text- data-test-id="toast-message"- variant="body"- fontSize="body"- color="text"- mr={2}- >- {message}- </Text>- {actions?.map((action) => (- <Button- flexShrink={0}- variant="anchor"- fontSize="body"- color={type}- key={action.text}- onClick={action.onClick}- >- {action.text}- </Button>- ))}- </Flex>- </ThemeProvider>- );-}--export { showToast };diff --git a/apps/web/src/utils/toast.tsx b/apps/web/src/utils/toast.tsxnew file mode 100644index 000000000..17eaa765c--- /dev/null+++ b/apps/web/src/utils/toast.tsx@@ -0,0 +1,96 @@+import CogoToast, { CTReturn } from "cogo-toast";+import { Button, Flex, Text } from "rebass";+import ThemeProvider from "../components/theme-provider";+import { Error, Warn, Success } from "../components/icons";+import { store as appstore } from "../stores/app-store";++type ToastType = "success" | "error" | "warn" | "info";+type ToastAction = {+ text: string;+ onClick: () => void;+ type: "primary" | "text";+};++function showToast(+ type: ToastType,+ message: string,+ actions?: ToastAction[],+ hideAfter?: number+): CTReturn | null | undefined {+ if (appstore.get().isFocusMode) return null;+ const IconComponent =+ type === "error" ? Error : type === "success" ? Success : Warn;+ const toast = CogoToast[type];+ if (!toast) return;+ const t = toast(<ToastContainer message={message} actions={actions} />, {+ position: "top-right",+ hideAfter:+ hideAfter === undefined+ ? actions+ ? 5+ : type === "error"+ ? 5+ : 3+ : hideAfter,+ bar: { size: "0px" },+ renderIcon: () => {+ return (+ <ThemeProvider>+ <IconComponent size={28} color={type} />+ </ThemeProvider>+ );+ },+ });+ return t;+}++type ToastContainerProps = {+ message: string;+ actions?: ToastAction[];+};++function ToastContainer(props: ToastContainerProps) {+ const { message, actions } = props;+ return (+ <ThemeProvider>+ <Flex+ data-test-id="toast"+ justifyContent="center"+ alignItems="center"+ my={2}+ sx={{ borderRadius: "default" }}+ >+ <Text+ data-test-id="toast-message"+ variant="body"+ fontSize="body"+ color="text"+ mr={2}+ >+ {message}+ </Text>+ {actions?.map((action) => (+ <Button+ flexShrink={0}+ variant="primary"+ color={action.type}+ fontWeight="bold"+ bg={"transparent"}+ fontSize="body"+ sx={{+ py: "7px",+ ":hover": { bg: "bgSecondary" },+ m: 0,+ }}+ key={action.text}+ onClick={action.onClick}+ >+ {action.text}+ </Button>+ ))}+ </Flex>+ </ThemeProvider>+ );+}++export { showToast };diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.jsindex 04c7f4ae2..ae88c373e 100644--- a/apps/web/src/views/settings.js+++ b/apps/web/src/views/settings.js@@ -316,7 +316,7 @@ function Settings(props) {? "Reconfigure fallback 2FA method": "Add fallback 2FA method"}- tip="You can use the fallback 2FA method if you cannot login via the primary method."+ tip="You can use the fallback 2FA method in case you are unable to login via the primary method."/></Button>