Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: migrate to react-hot-toast

thecodrrf231f6b26339
diff --git a/apps/web/package.json b/apps/web/package.json
index 81b6ed25e..1fbb631d2 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -20,7 +20,6 @@
"async-mutex": "^0.3.2",
"axios": "^0.21.4",
"clipboard-polyfill": "^3.0.3",
- "cogo-toast": "^4.2.3",
"compressorjs": "^1.0.7",
"dayjs": "^1.10.4",
"emotion-theming": "^10.0.19",
@@ -49,6 +48,7 @@
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-dropzone": "^11.4.2",
+ "react-hot-toast": "^2.2.0",
"react-modal": "^3.12.1",
"react-qrcode-logo": "^2.2.1",
"react-scripts": "^4.0.3",
diff --git a/apps/web/src/app.js b/apps/web/src/app.js
index 1d27cf405..18e316296 100644
--- a/apps/web/src/app.js
+++ b/apps/web/src/app.js
@@ -13,6 +13,7 @@ import Config from "./utils/config";
import EditorLoading from "./components/editor/loading";
import NavigationMenuPlaceholder from "./components/navigationmenu/index.lite";
import { useStore } from "./stores/app-store";
+import { Toaster } from "react-hot-toast";
const GlobalMenuWrapper = React.lazy(() =>
import("./components/global-menu-wrapper")
@@ -63,6 +64,7 @@ function App() {
show={show}
/>
)}
+ <Toaster />
</Flex>
</ThemeProvider>
</LazyMotion>
diff --git a/apps/web/src/utils/toast.tsx b/apps/web/src/utils/toast.tsx
index 923755f52..93cbce964 100644
--- a/apps/web/src/utils/toast.tsx
+++ b/apps/web/src/utils/toast.tsx
@@ -1,8 +1,8 @@
-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";
+import toast from "react-hot-toast";
type ToastType = "success" | "error" | "warn" | "info";
type ToastAction = {
@@ -16,32 +16,24 @@ function showToast(
message: string,
actions?: ToastAction[],
hideAfter?: number
-): CTReturn | null | undefined {
- if (appstore.get().isFocusMode) return null;
+): { hide: () => void } {
+ if (appstore.get().isFocusMode) return { hide: () => {} }; // TODO
+
const IconComponent =
type === "error" ? Error : type === "success" ? Success : Warn;
- const toast = CogoToast[type];
- if (!toast) return;
- const t = toast(<ToastContainer message={message} actions={actions} />, {
+
+ const RenderedIcon = () => <IconComponent size={28} color={type} />;
+
+ const id = toast(<ToastContainer message={message} actions={actions} />, {
+ duration: hideAfter || Infinity,
+ icon: <RenderedIcon />,
+ id: message,
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>
- );
+ style: {
+ maxWidth: "auto",
},
});
- return t;
+ return { hide: () => toast.dismiss(id) };
}
type ToastContainerProps = {
@@ -57,7 +49,6 @@ function ToastContainer(props: ToastContainerProps) {
data-test-id="toast"
justifyContent="center"
alignItems="center"
- my={2}
sx={{ borderRadius: "default" }}
>
<Text