mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-26 11:44:28 +08:00
fix: history page message search
This commit is contained in:
parent
7b4f79aab5
commit
2af0b87ce5
@ -3,6 +3,7 @@ import { HStack } from '@renderer/components/Layout'
|
||||
import SearchPopup from '@renderer/components/Popups/SearchPopup'
|
||||
import useScrollPosition from '@renderer/hooks/useScrollPosition'
|
||||
import { useSettings } from '@renderer/hooks/useSettings'
|
||||
import { ChatProvider } from '@renderer/pages/home/Messages/ChatContext'
|
||||
import { getAssistantById } from '@renderer/services/AssistantService'
|
||||
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
|
||||
import { isGenerating, locateToMessage } from '@renderer/services/MessagesService'
|
||||
@ -46,31 +47,33 @@ const TopicMessages: FC<Props> = ({ topic, ...props }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<MessagesContainer {...props} ref={containerRef} onScroll={handleScroll} className={messageStyle}>
|
||||
<ContainerWrapper style={{ paddingTop: 30, paddingBottom: 30 }}>
|
||||
{topic?.messages.map((message) => (
|
||||
<div key={message.id} style={{ position: 'relative' }}>
|
||||
<MessageItem message={message} topic={topic} />
|
||||
<Button
|
||||
type="text"
|
||||
size="middle"
|
||||
style={{ color: 'var(--color-text-3)', position: 'absolute', right: 0, top: 5 }}
|
||||
onClick={() => locateToMessage(navigate, message)}
|
||||
icon={<ArrowRightOutlined />}
|
||||
/>
|
||||
<Divider style={{ margin: '8px auto 15px' }} variant="dashed" />
|
||||
</div>
|
||||
))}
|
||||
{isEmpty && <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
|
||||
{!isEmpty && (
|
||||
<HStack justifyContent="center">
|
||||
<Button onClick={() => onContinueChat(topic)} icon={<MessageOutlined />}>
|
||||
{t('history.continue_chat')}
|
||||
</Button>
|
||||
</HStack>
|
||||
)}
|
||||
</ContainerWrapper>
|
||||
</MessagesContainer>
|
||||
<ChatProvider activeTopic={topic} isHistoryView={true}>
|
||||
<MessagesContainer {...props} ref={containerRef} onScroll={handleScroll} className={messageStyle}>
|
||||
<ContainerWrapper style={{ paddingTop: 30, paddingBottom: 30 }}>
|
||||
{topic?.messages.map((message) => (
|
||||
<div key={message.id} style={{ position: 'relative' }}>
|
||||
<MessageItem message={message} topic={topic} />
|
||||
<Button
|
||||
type="text"
|
||||
size="middle"
|
||||
style={{ color: 'var(--color-text-3)', position: 'absolute', right: 0, top: 5 }}
|
||||
onClick={() => locateToMessage(navigate, message)}
|
||||
icon={<ArrowRightOutlined />}
|
||||
/>
|
||||
<Divider style={{ margin: '8px auto 15px' }} variant="dashed" />
|
||||
</div>
|
||||
))}
|
||||
{isEmpty && <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />}
|
||||
{!isEmpty && (
|
||||
<HStack justifyContent="center">
|
||||
<Button onClick={() => onContinueChat(topic)} icon={<MessageOutlined />}>
|
||||
{t('history.continue_chat')}
|
||||
</Button>
|
||||
</HStack>
|
||||
)}
|
||||
</ContainerWrapper>
|
||||
</MessagesContainer>
|
||||
</ChatProvider>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -12,10 +12,16 @@ interface ChatContextProps {
|
||||
toggleMultiSelectMode: (value: boolean) => void
|
||||
handleMultiSelectAction: (actionType: string, messageIds: string[]) => void
|
||||
activeTopic: Topic
|
||||
locateMessage: (messageId: string) => void
|
||||
messageRefs: Map<string, HTMLElement>
|
||||
registerMessageElement: (id: string, element: HTMLElement | null) => void
|
||||
}
|
||||
|
||||
interface ChatProviderProps {
|
||||
children: ReactNode
|
||||
activeTopic: Topic
|
||||
}
|
||||
|
||||
const ChatContext = createContext<ChatContextProps | undefined>(undefined)
|
||||
|
||||
export const useChatContext = () => {
|
||||
@ -26,11 +32,6 @@ export const useChatContext = () => {
|
||||
return context
|
||||
}
|
||||
|
||||
interface ChatProviderProps {
|
||||
children: ReactNode
|
||||
activeTopic: Topic
|
||||
}
|
||||
|
||||
export const ChatProvider: FC<ChatProviderProps> = ({ children, activeTopic }) => {
|
||||
const { t } = useTranslation()
|
||||
const dispatch = useDispatch()
|
||||
@ -58,6 +59,27 @@ export const ChatProvider: FC<ChatProviderProps> = ({ children, activeTopic }) =
|
||||
})
|
||||
}, [])
|
||||
|
||||
const locateMessage = (messageId: string) => {
|
||||
const messageElement = messageRefs.get(messageId)
|
||||
if (messageElement) {
|
||||
// 检查消息是否可见
|
||||
const display = window.getComputedStyle(messageElement).display
|
||||
|
||||
if (display === 'none') {
|
||||
// 如果消息隐藏,需要处理显示逻辑
|
||||
// 查找消息并设置为选中状态
|
||||
const message = messages.find((m) => m.id === messageId)
|
||||
if (message) {
|
||||
// 这里需要实现设置消息为选中状态的逻辑
|
||||
// 可能需要调用其他函数或修改状态
|
||||
}
|
||||
}
|
||||
|
||||
// 滚动到消息位置
|
||||
messageElement.scrollIntoView({ behavior: 'smooth', block: 'start' })
|
||||
}
|
||||
}
|
||||
|
||||
const handleMultiSelectAction = (actionType: string, messageIds: string[]) => {
|
||||
if (messageIds.length === 0) {
|
||||
window.message.warning(t('chat.multiple.select.empty'))
|
||||
@ -150,6 +172,7 @@ export const ChatProvider: FC<ChatProviderProps> = ({ children, activeTopic }) =
|
||||
toggleMultiSelectMode,
|
||||
handleMultiSelectAction,
|
||||
activeTopic,
|
||||
locateMessage,
|
||||
messageRefs,
|
||||
registerMessageElement
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user