Skip to content

Commit

Permalink
Fix the bug of being unable to delete messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
WongSaang committed Mar 22, 2023
1 parent afa3e49 commit 1ff1c46
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion components/MessageActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const deleteMessage = async () => {
method: 'DELETE'
})
if (!error.value) {
this.$emit('deleteMessage', props.messageIndex)
props.deleteMessage(props.messageIndex)
showSnackbar('Deleted!')
}
showSnackbar('Delete failed')
Expand Down
27 changes: 20 additions & 7 deletions components/MsgContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ const md = new MarkdownIt({
},
})
const props = defineProps(['content'])
const props = defineProps({
message: {
type: Object,
required: true
}
})
const contentHtml = ref('')
const contentElm = ref(null)
watchEffect(() => {
contentHtml.value = props.content ? md.render(props.content) : ''
contentHtml.value = props.message.message ? md.render(props.message.message) : ''
})
const bindCopyCodeToButtons = () => {
Expand Down Expand Up @@ -54,11 +59,19 @@ onUpdated(() => {
</script>
<template>
<div
ref="contentElm"
v-html="contentHtml"
class="chat-msg-content"
></div>
<v-card
:color="message.is_bot ? '' : 'primary'"
rounded="lg"
elevation="2"
>
<v-card-text>
<div
ref="contentElm"
v-html="contentHtml"
class="chat-msg-content"
></div>
</v-card-text>
</v-card>
</template>
<style>
Expand Down
19 changes: 9 additions & 10 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const fetchReply = async (message, parentMessageId) => {
const data = Object.assign({}, currentModel.value, {
openaiApiKey: openaiApiKey.value,
message: message,
parentMessageId: parentMessageId,
// parentMessageId: parentMessageId,
conversationId: currentConversation.value.id
})
Expand Down Expand Up @@ -93,6 +93,13 @@ const fetchReply = async (message, parentMessageId) => {
throw new Error(data.error);
}
if (event === 'userMessageId') {
console.log(currentConversation.value.messages[currentConversation.value.messages.length - 1])
currentConversation.value.messages[currentConversation.value.messages.length - 1].id = data.userMessageId
console.log(currentConversation.value.messages[currentConversation.value.messages.length - 1])
return;
}
if (event === 'done') {
if (currentConversation.value.id === null) {
currentConversation.value.id = data.conversationId
Expand Down Expand Up @@ -184,15 +191,7 @@ const deleteMessage = (index) => {
:use-prompt="usePrompt"
:delete-message="deleteMessage"
/>
<v-card
:color="message.is_bot ? '' : 'primary'"
rounded="lg"
elevation="2"
>
<v-card-text>
<MsgContent :content="message.message" />
</v-card-text>
</v-card>
<MsgContent :message="message" />
<MessageActions
v-if="message.is_bot"
:message="message"
Expand Down

0 comments on commit 1ff1c46

Please sign in to comment.