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: add toast notification system
thecodrr12f3a9ca88bf
diff --git a/apps/web/package.json b/apps/web/package.jsonindex 573fbbd25..19807ca85 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -6,6 +6,7 @@"@mdi/js": "^5.0.45","@mdi/react": "^1.4.0","@rebass/forms": "^4.0.6",+ "cogo-toast": "^4.2.3","emotion-theming": "^10.0.19","fast-sort": "^2.1.1","framer-motion": "^1.10.3",diff --git a/apps/web/src/components/icons/index.js b/apps/web/src/components/icons/index.jsindex 7599d2f16..555c773d4 100644--- a/apps/web/src/components/icons/index.js+++ b/apps/web/src/components/icons/index.js@@ -4,7 +4,7 @@ import * as Icons from "@mdi/js";import { useTheme } from "emotion-theming";import Animated from "../animated";-function Icon({ name, size = 24, color = "icon", stroke, rotate, hover }) {+function Icon({ name, size = 24, color = "icon", stroke, rotate }) {const theme = useTheme();return (<MDIIcon@@ -17,7 +17,7 @@ function Icon({ name, size = 24, color = "icon", stroke, rotate, hover }) {);}-function createIcon(name) {+function createIcon(name, rotate = false) {return function (props) {return (<Animated.Box@@ -28,7 +28,7 @@ function createIcon(name) {animate={props.animation}onClick={props.onClick}>- <Icon name={name} {...props} />+ <Icon name={name} rotate={rotate} {...props} /></Animated.Box>);};@@ -61,7 +61,7 @@ export const Settings = createIcon(Icons.mdiCogOutline);export const Home = createIcon(Icons.mdiHomeOutline);export const Restore = createIcon(Icons.mdiRecycle);export const Sync = createIcon(Icons.mdiSync);-export const Loading = createIcon(Icons.mdiLoading);+export const Loading = createIcon(Icons.mdiLoading, true);export const Export = createIcon(Icons.mdiExport);/** Properties Icons */@@ -85,3 +85,9 @@ export const Properties = createIcon(Icons.mdiDotsHorizontal);export const Markdown = createIcon(Icons.mdiLanguageMarkdownOutline);export const HTML = createIcon(Icons.mdiLanguageHtml5);export const Text = createIcon(Icons.mdiFormatTitle);++// TOAST+export const Success = createIcon(Icons.mdiCheckCircle);+export const Error = createIcon(Icons.mdiAlertCircle);+export const Warn = createIcon(Icons.mdiAlert);+export const Info = createIcon(Icons.mdiInformation);diff --git a/apps/web/src/theme/colorscheme/static.js b/apps/web/src/theme/colorscheme/static.jsindex f3ccc39d3..b68524496 100644--- a/apps/web/src/theme/colorscheme/static.js+++ b/apps/web/src/theme/colorscheme/static.js@@ -9,7 +9,8 @@ class StaticColorSchemeFactory {transparent: "transparent",static: "white",error: "#E53935",- favorite: "#ffd700"+ success: "#4F8A10",+ favorite: "#ffd700",};}}diff --git a/apps/web/src/utils/toast.js b/apps/web/src/utils/toast.jsnew file mode 100644index 000000000..936daba87--- /dev/null+++ b/apps/web/src/utils/toast.js@@ -0,0 +1,56 @@+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";++/**+ *+ * @returns {import("cogo-toast").CTReturn}+ */+function showToast(type, message, actions) {+ const IconComponent = Icon[toTitleCase(type)];++ return CogoToast[type](+ <ToastContainer type={type} message={message} actions={actions} />,+ {+ position: "top-right",+ hideAfter: actions ? 5 : 3,+ bar: { size: "0px" },+ renderIcon: () => {+ return (+ <ThemeProvider>+ <IconComponent color={type} />+ </ThemeProvider>+ );+ },+ }+ );+}++function ToastContainer(props) {+ const { type, message, actions } = props;+ return (+ <ThemeProvider>+ <Flex justifyContent="center" alignContent="center">+ <Text variant="body" fontSize="menu" mr={2}>+ {message}+ </Text>+ {actions?.map((action) => (+ <Button+ variant="anchor"+ fontSize="menu"+ color={type}+ key={action.text}+ onClick={action.onClick}+ >+ {action.text}+ </Button>+ ))}+ </Flex>+ </ThemeProvider>+ );+}++export { showToast };diff --git a/apps/web/yarn.lock b/apps/web/yarn.lockindex 82d81886e..171faf75f 100644--- a/apps/web/yarn.lock+++ b/apps/web/yarn.lock@@ -3070,6 +3070,11 @@ code-point-at@^1.0.0:resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=+cogo-toast@^4.2.3:+ version "4.2.3"+ resolved "https://registry.yarnpkg.com/cogo-toast/-/cogo-toast-4.2.3.tgz#5f91ce8e55c799f74d5e9ba1e39081b148b07f43"+ integrity sha512-Lp/lPk493MLtkgqHboVJXb5frvLJqUDpIqLh6uCMcNecw0/shikDG+DGsjvmPe5qmorRwxe+6JgfKobRrcvhZQ==+collection-visit@^1.0.0:version "1.0.0"resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"@@ -7350,7 +7355,7 @@ normalize-url@^3.0.0, normalize-url@^3.0.1:"notes-core@git+ssh://[email protected]:streetwriters/notesnook-core.git":version "1.5.0"- resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#85b016c0756aaeeab9487de9068027edd40a075d"+ resolved "git+ssh://[email protected]:streetwriters/notesnook-core.git#95ada5b4a905a6facc9168f8c6b5f517f227f55e"dependencies:crypto-random-string "^3.2.0"event-source-polyfill "^1.0.16"