From 0e399fa4434eadf6a879d8b55863165fe59fe37f Mon Sep 17 00:00:00 2001 From: icarus Date: Sat, 13 Dec 2025 00:55:31 +0800 Subject: [PATCH] refactor(toast): update toast utilities and imports - Move ToastUtilities type to local component file - Add closeToast functionality to toast utilities - Update error block to use success toast method --- src/renderer/src/components/TopView/toast.tsx | 19 +++++++++++++++++++ src/renderer/src/env.d.ts | 3 ++- .../pages/home/Messages/Blocks/ErrorBlock.tsx | 2 +- src/renderer/src/utils/dataLimit.ts | 2 +- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/components/TopView/toast.tsx b/src/renderer/src/components/TopView/toast.tsx index 0731a1b4bb..c9b1d56fca 100644 --- a/src/renderer/src/components/TopView/toast.tsx +++ b/src/renderer/src/components/TopView/toast.tsx @@ -178,9 +178,28 @@ export const loading = (args: RequireSome): strin */ export const addToast = (config: ToastConfig) => info(config) +/** + * Close a specific toast notification by its key + * @param key - Toast key (string) + */ +export const closeToast = (key: string) => { + getMessageApi().destroy(key) +} + +export type ToastUtilities = { + addToast: typeof addToast + close: typeof closeToast + error: typeof error + success: typeof success + warning: typeof warning + info: typeof info + loading: typeof loading +} + export const getToastUtilities = () => ({ addToast, + close: closeToast, error, success, warning, diff --git a/src/renderer/src/env.d.ts b/src/renderer/src/env.d.ts index f4452a5c31..55ec1d82c9 100644 --- a/src/renderer/src/env.d.ts +++ b/src/renderer/src/env.d.ts @@ -1,10 +1,11 @@ /// import type { PermissionUpdate } from '@anthropic-ai/claude-agent-sdk' -import type { ToastUtilities } from '@cherrystudio/ui' import type { HookAPI } from 'antd/es/modal/useModal' import type { NavigateFunction } from 'react-router-dom' +import type { ToastUtilities } from './components/TopView/toast' + interface ImportMetaEnv { VITE_RENDERER_INTEGRATED_MODEL: string } diff --git a/src/renderer/src/pages/home/Messages/Blocks/ErrorBlock.tsx b/src/renderer/src/pages/home/Messages/Blocks/ErrorBlock.tsx index 1cb445f12d..53fe890ed3 100644 --- a/src/renderer/src/pages/home/Messages/Blocks/ErrorBlock.tsx +++ b/src/renderer/src/pages/home/Messages/Blocks/ErrorBlock.tsx @@ -176,7 +176,7 @@ const ErrorDetailModal: React.FC = ({ open, onClose, erro } navigator.clipboard.writeText(errorText) - window.toast.addToast({ title: t('message.copied') }) + window.toast.success({ title: t('message.copied') }) } const renderErrorDetails = (error?: SerializedError) => { diff --git a/src/renderer/src/utils/dataLimit.ts b/src/renderer/src/utils/dataLimit.ts index 6e79732ab7..15fb794afb 100644 --- a/src/renderer/src/utils/dataLimit.ts +++ b/src/renderer/src/utils/dataLimit.ts @@ -84,7 +84,7 @@ export async function checkDataLimit() { currentInterval = setInterval(check, CHECK_INTERVAL_WARNING) } else if (!shouldShowWarning && currentToastId) { // TODO: new toast component cannot be closed programmatically. add a dismiss button in the toast. - // window.toast.closeToast(currentToastId) + window.toast.close(currentToastId) currentToastId = null // Switch back to normal mode