Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
deb627a9ab | ||
|
|
70efc09dae |
@@ -64,18 +64,16 @@ onUpdated(() => {
|
|||||||
rounded="lg"
|
rounded="lg"
|
||||||
elevation="2"
|
elevation="2"
|
||||||
>
|
>
|
||||||
<v-card-text>
|
<div
|
||||||
<div
|
ref="contentElm"
|
||||||
ref="contentElm"
|
v-html="contentHtml"
|
||||||
v-html="contentHtml"
|
class="chat-msg-content pa-3"
|
||||||
class="chat-msg-content"
|
></div>
|
||||||
></div>
|
|
||||||
</v-card-text>
|
|
||||||
</v-card>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.chat-msg-content ol {
|
.chat-msg-content ol, .chat-msg-content ul {
|
||||||
padding-left: 2em;
|
padding-left: 2em;
|
||||||
}
|
}
|
||||||
.hljs-code-container {
|
.hljs-code-container {
|
||||||
|
|||||||
@@ -1,3 +1,73 @@
|
|||||||
|
<script setup>
|
||||||
|
import { isMobile } from 'is-mobile'
|
||||||
|
const { $i18n } = useNuxtApp()
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
sendMessage: {
|
||||||
|
type: Function,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
|
loading: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const message = ref('')
|
||||||
|
const rows = ref(1)
|
||||||
|
const autoGrow = ref(true)
|
||||||
|
|
||||||
|
const hint = computed(() => {
|
||||||
|
return isMobile() ? '' : $i18n.t('pressEnterToSendYourMessageOrShiftEnterToAddANewLine')
|
||||||
|
})
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
const lines = message.value.split(/\r\n|\r|\n/).length
|
||||||
|
if (lines > 8) {
|
||||||
|
rows.value = 8
|
||||||
|
autoGrow.value = false
|
||||||
|
} else {
|
||||||
|
rows.value = 1
|
||||||
|
autoGrow.value = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const send = () => {
|
||||||
|
let msg = message.value
|
||||||
|
// remove the last "\n"
|
||||||
|
if (msg[msg.length - 1] === "\n") {
|
||||||
|
msg = msg.slice(0, -1)
|
||||||
|
}
|
||||||
|
if (msg.length > 0) {
|
||||||
|
props.sendMessage(msg)
|
||||||
|
}
|
||||||
|
message.value = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
const usePrompt = (prompt) => {
|
||||||
|
message.value = prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
const clickSendBtn = () => {
|
||||||
|
send()
|
||||||
|
}
|
||||||
|
|
||||||
|
const enterOnly = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!isMobile()) {
|
||||||
|
send()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
usePrompt
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="flex-grow-1 d-flex align-center justify-space-between"
|
class="flex-grow-1 d-flex align-center justify-space-between"
|
||||||
@@ -24,68 +94,4 @@
|
|||||||
@click="clickSendBtn"
|
@click="clickSendBtn"
|
||||||
></v-btn>
|
></v-btn>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
|
||||||
import { isMobile } from 'is-mobile'
|
|
||||||
export default {
|
|
||||||
name: "MsgEditor",
|
|
||||||
props: {
|
|
||||||
sendMessage: Function,
|
|
||||||
disabled: Boolean,
|
|
||||||
loading: Boolean,
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
message: "",
|
|
||||||
rows: 1,
|
|
||||||
autoGrow: true,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
hint() {
|
|
||||||
return isMobile() ? "" : "Press Enter to send your message or Shift+Enter to add a new line";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
message(val) {
|
|
||||||
const lines = val.split(/\r\n|\r|\n/).length;
|
|
||||||
if (lines > 8) {
|
|
||||||
this.rows = 8;
|
|
||||||
this.autoGrow = false;
|
|
||||||
} else {
|
|
||||||
this.rows = 1;
|
|
||||||
this.autoGrow = true;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
send() {
|
|
||||||
let msg = this.message
|
|
||||||
// remove the last "\n"
|
|
||||||
if (msg[msg.length - 1] === "\n") {
|
|
||||||
msg = msg.slice(0, -1)
|
|
||||||
}
|
|
||||||
if (msg.length > 0) {
|
|
||||||
this.sendMessage(msg)
|
|
||||||
}
|
|
||||||
this.message = ""
|
|
||||||
},
|
|
||||||
usePrompt(prompt) {
|
|
||||||
this.message = prompt
|
|
||||||
},
|
|
||||||
clickSendBtn () {
|
|
||||||
this.send()
|
|
||||||
},
|
|
||||||
enterOnly (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
if (!isMobile()) {
|
|
||||||
this.send()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
</style>
|
|
||||||
@@ -12,7 +12,6 @@ const loadConversation = async () => {
|
|||||||
const { data, error } = await useAuthFetch('/api/chat/conversations/' + route.params.id)
|
const { data, error } = await useAuthFetch('/api/chat/conversations/' + route.params.id)
|
||||||
if (!error.value) {
|
if (!error.value) {
|
||||||
conversation.value = Object.assign(conversation.value, data.value)
|
conversation.value = Object.assign(conversation.value, data.value)
|
||||||
console.log(conversation.value)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +23,6 @@ const loadMessage = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onActivated(async () => {
|
onActivated(async () => {
|
||||||
console.log('activated')
|
|
||||||
if (route.params.id) {
|
if (route.params.id) {
|
||||||
conversation.value.loadingMessages = true
|
conversation.value.loadingMessages = true
|
||||||
await loadConversation()
|
await loadConversation()
|
||||||
@@ -36,9 +34,6 @@ onActivated(async () => {
|
|||||||
currentConversation.value = Object.assign({}, conversation.value)
|
currentConversation.value = Object.assign({}, conversation.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
watchEffect(() => {
|
|
||||||
console.log('conversation.value', conversation.value)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
Reference in New Issue
Block a user