mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
fix(CodeEditor): save to db (#7504)
This commit is contained in:
parent
1f09c8a022
commit
5e0cae06db
@ -17,9 +17,9 @@ import { estimateHistoryTokens } from '@renderer/services/TokenService'
|
||||
import store, { useAppDispatch } from '@renderer/store'
|
||||
import { messageBlocksSelectors, updateOneBlock } from '@renderer/store/messageBlock'
|
||||
import { newMessagesActions } from '@renderer/store/newMessage'
|
||||
import { saveMessageAndBlocksToDB } from '@renderer/store/thunk/messageThunk'
|
||||
import { saveMessageAndBlocksToDB, updateMessageAndBlocksThunk } from '@renderer/store/thunk/messageThunk'
|
||||
import type { Assistant, Topic } from '@renderer/types'
|
||||
import { type Message, MessageBlockType } from '@renderer/types/newMessage'
|
||||
import { type Message, MessageBlock, MessageBlockType } from '@renderer/types/newMessage'
|
||||
import {
|
||||
captureScrollableDivAsBlob,
|
||||
captureScrollableDivAsDataURL,
|
||||
@ -211,7 +211,15 @@ const Messages: React.FC<MessagesProps> = ({ assistant, topic, setActiveTopic, o
|
||||
if (msgBlock && isTextLikeBlock(msgBlock) && msgBlock.type !== MessageBlockType.ERROR) {
|
||||
try {
|
||||
const updatedRaw = updateCodeBlock(msgBlock.content, codeBlockId, newContent)
|
||||
const updatedBlock: MessageBlock = {
|
||||
...msgBlock,
|
||||
content: updatedRaw,
|
||||
updatedAt: new Date().toISOString()
|
||||
}
|
||||
|
||||
dispatch(updateOneBlock({ id: msgBlockId, changes: { content: updatedRaw } }))
|
||||
await dispatch(updateMessageAndBlocksThunk(topic.id, null, [updatedBlock]))
|
||||
|
||||
window.message.success({ content: t('code_block.edit.save.success'), key: 'save-code' })
|
||||
} catch (error) {
|
||||
console.error(`Failed to save code block ${codeBlockId} content to message block ${msgBlockId}:`, error)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user