mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 11:20:07 +08:00
* feat: implement message editing and resend functionality with block management * fix: move start_time_millsec initialization to onChunk for accurate timing * feat: refactor message update thunks to separate block addition and updates * feat: enhance MessageBlockEditor with toolbar buttons and attachment functionality * refactor: implement message editing context and integrate with message operations * style: adjust padding in MessageBlockEditor and related components * refactor: remove MessageEditingContext and integrate editing logic directly in Message component * refactor: streamline message rendering logic by using conditional rendering for MessageEditor and MessageContent * refactor: remove redundant ipcRenderer variable in useMCPServers hook * fix: Add mock for electron's ipcRenderer to support testing * test: Update mocks for ipcRenderer and remove redundant window.electron mock * fix: enhance file handling in MessageEditor with new Electron API - Added support for file dragging with visual feedback. - Improved file type validation during drag-and-drop and clipboard pasting. - Displayed user notifications for unsupported file types. - Refactored file handling logic for better clarity and maintainability.
34 lines
955 B
TypeScript
34 lines
955 B
TypeScript
import { createContext, ReactNode, use, useState } from 'react'
|
|
|
|
interface MessageEditingContextType {
|
|
editingMessageId: string | null
|
|
startEditing: (messageId: string) => void
|
|
stopEditing: () => void
|
|
}
|
|
|
|
const MessageEditingContext = createContext<MessageEditingContextType | null>(null)
|
|
|
|
export function MessageEditingProvider({ children }: { children: ReactNode }) {
|
|
const [editingMessageId, setEditingMessageId] = useState<string | null>(null)
|
|
|
|
const startEditing = (messageId: string) => {
|
|
setEditingMessageId(messageId)
|
|
}
|
|
|
|
const stopEditing = () => {
|
|
setEditingMessageId(null)
|
|
}
|
|
|
|
return (
|
|
<MessageEditingContext value={{ editingMessageId, startEditing, stopEditing }}>{children}</MessageEditingContext>
|
|
)
|
|
}
|
|
|
|
export function useMessageEditing() {
|
|
const context = use(MessageEditingContext)
|
|
if (!context) {
|
|
throw new Error('useMessageEditing must be used within a MessageEditingProvider')
|
|
}
|
|
return context
|
|
}
|