From 2d274a291c9b5dcdf3b3db7c69686d2db36ef17a Mon Sep 17 00:00:00 2001 From: DIYgod Date: Thu, 14 Dec 2023 17:46:15 +0800 Subject: [PATCH] feat: action success toast --- assets/locales/en/messages.json | 3 +++ assets/locales/zh/messages.json | 3 +++ package.json | 1 + pnpm-lock.yaml | 25 +++++++++++++++++++++++++ src/lib/config.ts | 5 ++++- src/options/index.tsx | 2 ++ src/options/routes/General.tsx | 6 +++++- 7 files changed, 43 insertions(+), 2 deletions(-) diff --git a/assets/locales/en/messages.json b/assets/locales/en/messages.json index 52f60ad..8d9a20c 100644 --- a/assets/locales/en/messages.json +++ b/assets/locales/en/messages.json @@ -121,5 +121,8 @@ }, "totalNumberOfRules": { "message": "Total number of rules" + }, + "updateSuccessful": { + "message": "Update successful" } } \ No newline at end of file diff --git a/assets/locales/zh/messages.json b/assets/locales/zh/messages.json index b964b47..0c0879d 100644 --- a/assets/locales/zh/messages.json +++ b/assets/locales/zh/messages.json @@ -121,5 +121,8 @@ }, "totalNumberOfRules": { "message": "规则总数" + }, + "updateSuccessful": { + "message": "更新成功" } } \ No newline at end of file diff --git a/package.json b/package.json index 02013dc..75d17e7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "psl": "^1.9.0", "react": "18.2.0", "react-dom": "18.2.0", + "react-hot-toast": "^2.4.1", "react-router-dom": "^6.20.1", "route-recognizer": "^0.3.4", "rss-parser": "^3.13.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a7a7875..b221bb3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -56,6 +56,9 @@ dependencies: react-dom: specifier: 18.2.0 version: 18.2.0(react@18.2.0) + react-hot-toast: + specifier: ^2.4.1 + version: 2.4.1(csstype@3.1.3)(react-dom@18.2.0)(react@18.2.0) react-router-dom: specifier: ^6.20.1 version: 6.20.1(react-dom@18.2.0)(react@18.2.0) @@ -4301,6 +4304,14 @@ packages: slash: 3.0.0 dev: false + /goober@2.1.13(csstype@3.1.3): + resolution: {integrity: sha512-jFj3BQeleOoy7t93E9rZ2de+ScC4lQICLwiAQmKMg9F6roKGaLSHoCDYKkWlSafg138jejvq/mTdvmnwDQgqoQ==} + peerDependencies: + csstype: ^3.0.10 + dependencies: + csstype: 3.1.3 + dev: false + /gopd@1.0.1: resolution: {integrity: sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==} dependencies: @@ -5843,6 +5854,20 @@ packages: resolution: {integrity: sha512-nQTTcUu+ATDbrSD1BZHr5kgSD4oF8OFjxun8uAaL8RwPBacGBNPf/yAuVVdx17N8XNzRDMrZ9XcKZHCjPW+9ew==} dev: false + /react-hot-toast@2.4.1(csstype@3.1.3)(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ==} + engines: {node: '>=10'} + peerDependencies: + react: '>=16' + react-dom: '>=16' + dependencies: + goober: 2.1.13(csstype@3.1.3) + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + transitivePeerDependencies: + - csstype + dev: false + /react-refresh@0.14.0: resolution: {integrity: sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==} engines: {node: '>=0.10.0'} diff --git a/src/lib/config.ts b/src/lib/config.ts index a817d5f..78da0ea 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1,5 +1,6 @@ import { Storage } from "@plasmohq/storage" import _ from 'lodash'; +import toast from "react-hot-toast" const storage = new Storage() @@ -57,5 +58,7 @@ export async function setConfig(config: Partial) { if (config.rsshubDomain === defaultConfig.rsshubDomain) { config.rsshubAccessControl.enabled = defaultConfig.rsshubAccessControl.enabled; } - return storage.set("config", config) + await storage.set("config", config) + toast.success("Saved") + return config; } diff --git a/src/options/index.tsx b/src/options/index.tsx index 4d5ee53..ee0795a 100644 --- a/src/options/index.tsx +++ b/src/options/index.tsx @@ -2,10 +2,12 @@ import { MemoryRouter } from "react-router-dom" import { Routing } from "~/options/routes" import "~/lib/style.css" import Siderbar from "./Siderbar" +import { Toaster } from "react-hot-toast" function Options() { return (
+
diff --git a/src/options/routes/General.tsx b/src/options/routes/General.tsx index 60292c0..8323dfe 100644 --- a/src/options/routes/General.tsx +++ b/src/options/routes/General.tsx @@ -17,6 +17,7 @@ import { parseRules, getRulesCount } from "~/lib/rules" import type { Rules as IRules } from "~/lib/types" import { sendToBackground } from "@plasmohq/messaging" import { Loader2 } from "lucide-react" +import toast from "react-hot-toast" function General() { const [config] = useStorage("config", (v) => _.merge({}, defaultConfig, v)) @@ -102,7 +103,10 @@ function General() { setRulesUpdating(true) sendToBackground({ name: "refreshRules" - }).then((res) => setRulesUpdating(false)) + }).then((res) => { + setRulesUpdating(false) + toast.success(chrome.i18n.getMessage("updateSuccessful")) + }) }} > {rulesUpdating && }