forked from michael-dm/eva
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.vue
More file actions
63 lines (52 loc) · 1.38 KB
/
index.vue
File metadata and controls
63 lines (52 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<script setup lang="ts">
import type { Message } from '~/electron/trpc/routers'
const { $trpc } = useNuxtApp()
const msgView = ref<HTMLElement>()
const { y } = useScroll(msgView, { behavior: 'smooth' })
const messages = reactive(new Map<string, Message>())
messages.set('first', {
messageId: 'first',
type: 'bot',
text: "Je t'écoute.",
})
const loading = ref(false)
const error = ref<Error>()
const scrollDown = () => {
y.value = msgView.value!.scrollHeight
}
const message$ = $trpc.message.subscribe(undefined, {
onData(data) {
loading.value = false
messages.set(data.messageId, data)
scrollDown()
},
})
$trpc.isLoading.subscribe(undefined, {
onData() {
loading.value = true
scrollDown()
},
})
onUnmounted(() => {
message$.unsubscribe()
})
</script>
<template>
<div ref="msgView" class="font-mono space-y-2 py-3 px-5 text-sm w-full max-h-screen overflow-x-hidden overflow-y-auto">
<div v-for="[_, message] of messages" :key="message.messageId" :class="message.type == 'user' ? 'text-gray-400' : 'text-gray-600'">
{{ message.text }}
</div>
<div v-if="loading" class="animate-pulse bg-gray-300 h-4 rounded mt-1" />
<div v-if="error" class="text-red-500">
{{ error.message }}
</div>
</div>
</template>
<style>
body, html {
width: 100%;
height: 100%;
overflow: hidden;
background-color: rgba(255, 255, 255, 0.5);
}
</style>