main
vue 93 lines 2.06 KB
Raw
1 <template>
2 <div class="relative flex flex-col overflow-hidden">
3 <div
4 v-if="!!editMessageBody"
5 class="bg-secondary hover:text-primary mb-2 flex cursor-pointer items-center gap-2 rounded-lg px-2 py-2 text-sm transition-colors duration-200"
6 @click="handleCancelEdit()"
7 >
8 <Icon name="carbon:close" :size="20" />
9 <div>Edit message</div>
10 </div>
11 <n-input
12 v-model:value.trim="input"
13 class="max-h-full min-h-20 pt-1 pb-9"
14 type="textarea"
15 placeholder="Ask Talon..."
16 :autosize="{
17 minRows: 3,
18 maxRows: 18
19 }"
20 />
21 <div class="absolute right-0 bottom-0 left-0 flex items-center justify-between p-2 pr-3">
22 <div class="flex items-center gap-2.5">
23 <n-button size="tiny" secondary @click="clearChat()">
24 <template #icon>
25 <Icon name="mdi:broom" />
26 </template>
27 Clear chat
28 </n-button>
29 </div>
30 <n-button
31 circle
32 size="small"
33 secondary
34 :type="isFormValid ? 'primary' : undefined"
35 :disabled="!isFormValid && !loading"
36 @click="loading ? stop() : send()"
37 >
38 <Icon :name="loading ? 'carbon:stop-filled-alt' : 'carbon:arrow-up'" />
39 </n-button>
40 </div>
41 </div>
42 </template>
43
44 <script setup lang="ts">
45 import _trim from "lodash/trim"
46 import { NButton, NInput } from "naive-ui"
47 import { computed, toRefs } from "vue"
48 import Icon from "@/components/common/Icon.vue"
49
50 export interface Message {
51 input: string
52 }
53
54 const props = defineProps<{ loading?: boolean; editMessageBody?: string | null }>()
55
56 const emit = defineEmits<{
57 (e: "message", value: Message): void
58 (e: "stop"): void
59 (e: "cancel-edit"): void
60 (e: "clear-chat"): void
61 }>()
62
63 const { loading, editMessageBody } = toRefs(props)
64 const input = defineModel<string | null>("input", { default: null })
65 const isFormValid = computed(() => !!_trim(input.value || ""))
66
67 function reset() {
68 input.value = null
69 }
70
71 function send() {
72 if (input.value) {
73 emit("message", {
74 input: input.value
75 })
76
77 reset()
78 }
79 }
80
81 function stop() {
82 emit("stop")
83 }
84
85 function handleCancelEdit() {
86 emit("cancel-edit")
87 reset()
88 }
89
90 function clearChat() {
91 emit("clear-chat")
92 }
93 </script>