/
StoryEvents.vue
48 lines (42 loc) · 1.1 KB
/
StoryEvents.vue
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
<script lang="ts" setup>
import { ref, computed, watch, onMounted, nextTick } from 'vue'
import { Icon } from '@iconify/vue'
import BaseEmpty from '../base/BaseEmpty.vue'
import { useEventsStore } from '../../stores/events'
import StoryEvent from './StoryEvent.vue'
const eventsStore = useEventsStore()
const hasEvents = computed(() => eventsStore.events.length)
onMounted(resetUnseen)
watch(() => eventsStore.unseen, resetUnseen)
async function resetUnseen () {
if (eventsStore.unseen > 0) {
eventsStore.unseen = 0
}
await nextTick()
eventsElement.value.scrollTo({ top: eventsElement.value.scrollHeight })
}
const eventsElement = ref<HTMLDivElement>()
</script>
<template>
<div
ref="eventsElement"
class="histoire-story-events"
>
<BaseEmpty
v-if="!hasEvents"
>
<Icon
icon="carbon:event-schedule"
class="htw-w-8 htw-h-8 htw-opacity-50 htw-mb-6"
/>
No event fired
</BaseEmpty>
<div v-else>
<StoryEvent
v-for="(event, key) of eventsStore.events"
:key="key"
:event="event"
/>
</div>
</div>
</template>