mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-01 09:49:03 +08:00
feat(翻译): 添加翻译成功提醒并跟踪当前路由
在翻译完成后添加成功提示,但仅在非翻译页面显示 添加activeRoute状态以跟踪当前路由路径
This commit is contained in:
parent
6d929c322b
commit
8f6bea490f
@ -10,6 +10,8 @@ import useNavBackgroundColor from '@renderer/hooks/useNavBackgroundColor'
|
||||
import { modelGenerating, useRuntime } from '@renderer/hooks/useRuntime'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import i18n from '@renderer/i18n'
|
||||
import { useAppDispatch } from '@renderer/store'
|
||||
import { setActiveRoute } from '@renderer/store/runtime'
|
||||
import { ThemeMode } from '@renderer/types'
|
||||
import { isEmoji } from '@renderer/utils'
|
||||
import type { MenuProps } from 'antd'
|
||||
@ -144,6 +146,7 @@ const MainMenus: FC = () => {
|
||||
const { minappShow } = useRuntime()
|
||||
const navigate = useNavigate()
|
||||
const { theme } = useTheme()
|
||||
const dispatch = useAppDispatch()
|
||||
|
||||
const isRoute = (path: string): string => (pathname === path && !minappShow ? 'active' : '')
|
||||
const isRoutes = (path: string): string => (pathname.startsWith(path) && !minappShow ? 'active' : '')
|
||||
@ -179,6 +182,7 @@ const MainMenus: FC = () => {
|
||||
hideMinappPopup()
|
||||
await modelGenerating()
|
||||
navigate(path)
|
||||
dispatch(setActiveRoute(path))
|
||||
}}>
|
||||
<Icon theme={theme} className={isActive}>
|
||||
{iconMap[icon]}
|
||||
|
||||
@ -7,6 +7,7 @@ import {
|
||||
} from '@renderer/store/translate'
|
||||
import { Assistant, TranslateHistory } from '@renderer/types'
|
||||
import { uuid } from '@renderer/utils'
|
||||
import { t } from 'i18next'
|
||||
|
||||
export default function useTranslate() {
|
||||
const translatedContent = useAppSelector((state) => state.translate.translatedContent)
|
||||
@ -40,6 +41,13 @@ export default function useTranslate() {
|
||||
await saveTranslateHistory(text, translatedContent, actualSourceLanguage, actualTargetLanguage)
|
||||
|
||||
setTranslating(false)
|
||||
|
||||
const pathname = store.getState().runtime.activeRoute
|
||||
console.log('get pathname', pathname)
|
||||
if (pathname !== '/translate') {
|
||||
// ALTERNATIVE: 也许可以改成通知的形式
|
||||
window.message.success(t('translate.success'))
|
||||
}
|
||||
}
|
||||
|
||||
const saveTranslateHistory = async (
|
||||
|
||||
@ -2018,6 +2018,7 @@
|
||||
},
|
||||
"error.failed": "Translation failed",
|
||||
"error.not_configured": "Translation model is not configured",
|
||||
"success": "Translation completed",
|
||||
"history": {
|
||||
"clear": "Clear History",
|
||||
"clear_description": "Clear history will delete all translation history, continue?",
|
||||
|
||||
@ -2017,6 +2017,7 @@
|
||||
},
|
||||
"error.failed": "翻訳に失敗しました",
|
||||
"error.not_configured": "翻訳モデルが設定されていません",
|
||||
"success": "翻訳が完了しました。",
|
||||
"history": {
|
||||
"clear": "履歴をクリア",
|
||||
"clear_description": "履歴をクリアすると、すべての翻訳履歴が削除されます。続行しますか?",
|
||||
|
||||
@ -2017,6 +2017,7 @@
|
||||
},
|
||||
"error.failed": "Перевод не удалось",
|
||||
"error.not_configured": "Модель перевода не настроена",
|
||||
"success": "Перевод завершен",
|
||||
"history": {
|
||||
"clear": "Очистить историю",
|
||||
"clear_description": "Очистка истории удалит все записи переводов. Продолжить?",
|
||||
|
||||
@ -2015,6 +2015,7 @@
|
||||
"content": "翻译后将覆盖原文,是否继续?",
|
||||
"title": "翻译确认"
|
||||
},
|
||||
"success": "翻译完成",
|
||||
"error.failed": "翻译失败",
|
||||
"error.not_configured": "翻译模型未配置",
|
||||
"history": {
|
||||
|
||||
@ -2017,6 +2017,7 @@
|
||||
},
|
||||
"error.failed": "翻譯失敗",
|
||||
"error.not_configured": "翻譯模型未設定",
|
||||
"success": "翻譯完成",
|
||||
"history": {
|
||||
"clear": "清空歷史",
|
||||
"clear_description": "清空歷史將刪除所有翻譯歷史記錄,是否繼續?",
|
||||
|
||||
@ -40,6 +40,7 @@ export interface RuntimeState {
|
||||
searching: boolean
|
||||
filesPath: string
|
||||
resourcesPath: string
|
||||
activeRoute: string
|
||||
update: UpdateState
|
||||
export: ExportState
|
||||
chat: ChatState
|
||||
@ -60,6 +61,7 @@ const initialState: RuntimeState = {
|
||||
searching: false,
|
||||
filesPath: '',
|
||||
resourcesPath: '',
|
||||
activeRoute: '/',
|
||||
update: {
|
||||
info: null,
|
||||
checking: false,
|
||||
@ -114,6 +116,9 @@ const runtimeSlice = createSlice({
|
||||
setResourcesPath: (state, action: PayloadAction<string>) => {
|
||||
state.resourcesPath = action.payload
|
||||
},
|
||||
setActiveRoute: (state, action: PayloadAction<string>) => {
|
||||
state.activeRoute = action.payload
|
||||
},
|
||||
setUpdateState: (state, action: PayloadAction<Partial<UpdateState>>) => {
|
||||
state.update = { ...state.update, ...action.payload }
|
||||
},
|
||||
@ -163,6 +168,7 @@ export const {
|
||||
setSearching,
|
||||
setFilesPath,
|
||||
setResourcesPath,
|
||||
setActiveRoute,
|
||||
setUpdateState,
|
||||
setExportState,
|
||||
// Chat related actions
|
||||
|
||||
Loading…
Reference in New Issue
Block a user