mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-27 21:01:32 +08:00
fix: init message api err
This commit is contained in:
parent
f3bbd4ed44
commit
0ea4dd4e3a
@ -1,21 +0,0 @@
|
||||
import { App } from 'antd'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
import { initMessageApi } from './TopView/toast'
|
||||
|
||||
/**
|
||||
* MessageInitializer component
|
||||
* This component initializes the message API from App.useApp() hook
|
||||
* It should be rendered inside the AntdProvider (which wraps App component)
|
||||
* so that the message API can inherit the correct theme (dark/light mode)
|
||||
*/
|
||||
export const MessageInitializer = () => {
|
||||
const { message } = App.useApp()
|
||||
|
||||
useEffect(() => {
|
||||
// Initialize the message API for use in toast.ts
|
||||
initMessageApi(message)
|
||||
}, [message])
|
||||
|
||||
return null
|
||||
}
|
||||
@ -2,12 +2,12 @@
|
||||
import TopViewMinappContainer from '@renderer/components/MinApp/TopViewMinappContainer'
|
||||
import { useAppInit } from '@renderer/hooks/useAppInit'
|
||||
import { useShortcuts } from '@renderer/hooks/useShortcuts'
|
||||
import { Modal } from 'antd'
|
||||
import { message, Modal } from 'antd'
|
||||
import type { PropsWithChildren } from 'react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { Box } from '../Layout'
|
||||
import { getToastUtilities } from './toast'
|
||||
import { getToastUtilities, initMessageApi } from './toast'
|
||||
|
||||
let onPop = () => {}
|
||||
let onShow = ({ element, id }: { element: React.FC | React.ReactNode; id: string }) => {
|
||||
@ -36,6 +36,7 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
elementsRef.current = elements
|
||||
|
||||
const [modal, modalContextHolder] = Modal.useModal()
|
||||
const [messageApi, messageContextHolder] = message.useMessage()
|
||||
const { shortcuts } = useShortcuts()
|
||||
const enableQuitFullScreen = shortcuts.find((item) => item.key === 'exit_fullscreen')?.enabled
|
||||
|
||||
@ -43,8 +44,9 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
|
||||
useEffect(() => {
|
||||
window.modal = modal
|
||||
initMessageApi(messageApi)
|
||||
window.toast = getToastUtilities()
|
||||
}, [modal])
|
||||
}, [messageApi, modal])
|
||||
|
||||
onPop = () => {
|
||||
const views = [...elementsRef.current]
|
||||
@ -97,6 +99,7 @@ const TopViewContainer: React.FC<Props> = ({ children }) => {
|
||||
return (
|
||||
<>
|
||||
{children}
|
||||
{messageContextHolder}
|
||||
{modalContextHolder}
|
||||
<TopViewMinappContainer />
|
||||
{elements.map(({ element: Element, id }) => (
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { MessageInitializer } from '@renderer/components/MessageInitializer'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import type { LanguageVarious } from '@renderer/types'
|
||||
import { App, ConfigProvider, theme } from 'antd'
|
||||
import { ConfigProvider, theme } from 'antd'
|
||||
import deDE from 'antd/locale/de_DE'
|
||||
import elGR from 'antd/locale/el_GR'
|
||||
import enUS from 'antd/locale/en_US'
|
||||
@ -115,15 +114,7 @@ const AntdProvider: FC<PropsWithChildren> = ({ children }) => {
|
||||
motionDurationMid: '100ms'
|
||||
}
|
||||
}}>
|
||||
<App
|
||||
message={{
|
||||
top: 20,
|
||||
maxCount: 3,
|
||||
duration: 3
|
||||
}}>
|
||||
<MessageInitializer />
|
||||
{children}
|
||||
</App>
|
||||
{children}
|
||||
</ConfigProvider>
|
||||
)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user