这些界面改动和专家服务草稿停在工作区,没有随上一笔主分支提交进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
2.2 KiB
TypeScript
51 lines
2.2 KiB
TypeScript
'use client'
|
|
|
|
import type { ReactNode } from 'react'
|
|
import { createToast, createToastManager } from '@langgenius/dify-ui/toast'
|
|
import { localizeSystemMessage } from '@/service/chinese-system-message'
|
|
|
|
export const manager = createToastManager()
|
|
const baseToast = createToast(manager)
|
|
|
|
function localizeTitle(title: ReactNode) {
|
|
return typeof title === 'string' ? localizeSystemMessage(title) : title
|
|
}
|
|
|
|
function localizePromiseOption(option: unknown): unknown {
|
|
if (typeof option === 'string')
|
|
return localizeSystemMessage(option)
|
|
if (typeof option === 'function') {
|
|
return (value: unknown) => {
|
|
const result = option(value)
|
|
if (typeof result === 'string')
|
|
return localizeSystemMessage(result)
|
|
if (result && typeof result === 'object' && 'title' in result && typeof result.title === 'string')
|
|
return { ...result, title: localizeSystemMessage(result.title) }
|
|
return result
|
|
}
|
|
}
|
|
if (option && typeof option === 'object' && 'title' in option && typeof option.title === 'string')
|
|
return { ...option, title: localizeSystemMessage(option.title) }
|
|
return option
|
|
}
|
|
|
|
type ToastApi = typeof baseToast
|
|
|
|
function localizedToast(title: ReactNode, options: Parameters<ToastApi>[1]) {
|
|
return baseToast(localizeTitle(title), options)
|
|
}
|
|
|
|
localizedToast.success = ((title, options) => baseToast.success(localizeTitle(title), options)) as ToastApi['success']
|
|
localizedToast.error = ((title, options) => baseToast.error(localizeTitle(title), options)) as ToastApi['error']
|
|
localizedToast.warning = ((title, options) => baseToast.warning(localizeTitle(title), options)) as ToastApi['warning']
|
|
localizedToast.info = ((title, options) => baseToast.info(localizeTitle(title), options)) as ToastApi['info']
|
|
localizedToast.dismiss = baseToast.dismiss.bind(baseToast)
|
|
localizedToast.promise = ((promiseValue, options) => baseToast.promise(promiseValue, {
|
|
loading: localizePromiseOption(options.loading) as typeof options.loading,
|
|
success: localizePromiseOption(options.success) as typeof options.success,
|
|
error: localizePromiseOption(options.error) as typeof options.error,
|
|
})) as ToastApi['promise']
|
|
localizedToast.update = baseToast.update.bind(baseToast)
|
|
|
|
export const toast = localizedToast as ToastApi
|