diff --git a/src/views/ChatPanel.tsx b/src/views/ChatPanel.tsx index 37fb295..681a88a 100644 --- a/src/views/ChatPanel.tsx +++ b/src/views/ChatPanel.tsx @@ -69,7 +69,7 @@ const StopButton = () => { } }} onClick={() => { - dispatch(stopGenerating({ hasDone: false })); + dispatch(stopGenerating({ hasDone: false, message: null })); messageUtil.sendMessage({ command: 'stopDevChat' }); @@ -124,8 +124,8 @@ const chatPanel = () => { dispatch(startResponsing(message.text)); timer.start(); }); - messageUtil.registerHandler('receiveMessage', (message: { text: string; isError: boolean }) => { - dispatch(stopGenerating({ hasDone: true })); + messageUtil.registerHandler('receiveMessage', (message: { text: string; isError: boolean, hash }) => { + dispatch(stopGenerating({ hasDone: true, message: message })); if (message.isError) { dispatch(happendError(message.text)); } diff --git a/src/views/MessageHeader.tsx b/src/views/MessageHeader.tsx index bd507ad..d75ae1e 100644 --- a/src/views/MessageHeader.tsx +++ b/src/views/MessageHeader.tsx @@ -15,7 +15,8 @@ import { } from './inputSlice'; import { - deleteMessage + deleteMessage, + popMessage } from './chatSlice'; const MessageHeader = (props: any) => { @@ -71,10 +72,15 @@ const MessageHeader = (props: any) => { } - {showDelete && hash && + {showDelete && hash !== 'message' && { - dispatch(deleteMessage(item)); + if (item.hash) { + dispatch(deleteMessage(item)); + } else { + dispatch(popMessage()); + dispatch(popMessage()); + } }}> diff --git a/src/views/chatSlice.ts b/src/views/chatSlice.ts index 994cd8e..9b064da 100644 --- a/src/views/chatSlice.ts +++ b/src/views/chatSlice.ts @@ -85,6 +85,17 @@ export const chatSlice = createSlice({ state.generating = false; state.responsed = false; state.hasDone = action.payload.hasDone; + if (action.payload.hasDone) { + const { hash } = action.payload.message; + const messagesLength = state.messages.length; + + if (messagesLength > 1) { + state.messages[messagesLength - 2].hash = hash; + state.messages[messagesLength - 1].hash = hash; + } else if (messagesLength > 0) { + state.messages[messagesLength - 1].hash = hash; + } + } }, startResponsing: (state, action) => { state.responsed = true; @@ -151,6 +162,7 @@ export const chatSlice = createSlice({ .addCase(deleteMessage.fulfilled, (state, action) => { const { hash } = action.payload; const index = state.messages.findIndex((item: any) => item.hash === hash); + debugger if (index > -1) { state.messages.splice(index); }