2021-09-08 16:15:54 +02:00
|
|
|
<template>
|
2021-10-23 03:08:02 +02:00
|
|
|
<modals-modal v-model="show" name="chapters" :width="500" :height="'unset'">
|
2021-09-24 23:14:33 +02:00
|
|
|
<div ref="container" class="w-full rounded-lg bg-primary box-shadow-md overflow-y-auto overflow-x-hidden" style="max-height: 80vh">
|
2021-09-08 16:15:54 +02:00
|
|
|
<template v-for="chap in chapters">
|
2021-09-24 23:14:33 +02:00
|
|
|
<div :key="chap.id" :id="`chapter-row-${chap.id}`" class="flex items-center px-6 py-3 justify-start cursor-pointer hover:bg-bg relative" :class="chap.id === currentChapterId ? 'bg-bg bg-opacity-80' : 'bg-opacity-20'" @click="clickChapter(chap)">
|
2021-09-08 16:15:54 +02:00
|
|
|
{{ chap.title }}
|
|
|
|
<span class="flex-grow" />
|
|
|
|
<span class="font-mono text-sm text-gray-300">{{ $secondsToTimestamp(chap.start) }}</span>
|
2021-09-24 23:14:33 +02:00
|
|
|
|
|
|
|
<div v-show="chap.id === currentChapterId" class="w-0.5 h-full absolute top-0 left-0 bg-yellow-400" />
|
2021-09-08 16:15:54 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</modals-modal>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
value: Boolean,
|
|
|
|
chapters: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
2021-09-21 23:42:01 +02:00
|
|
|
},
|
|
|
|
currentChapter: {
|
|
|
|
type: Object,
|
|
|
|
default: () => null
|
2021-09-08 16:15:54 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {}
|
|
|
|
},
|
2021-09-24 23:14:33 +02:00
|
|
|
watch: {
|
|
|
|
value(newVal) {
|
|
|
|
this.$nextTick(this.scrollToChapter)
|
|
|
|
}
|
|
|
|
},
|
2021-09-08 16:15:54 +02:00
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get() {
|
|
|
|
return this.value
|
|
|
|
},
|
|
|
|
set(val) {
|
|
|
|
this.$emit('input', val)
|
|
|
|
}
|
2021-09-21 23:42:01 +02:00
|
|
|
},
|
|
|
|
currentChapterId() {
|
|
|
|
return this.currentChapter ? this.currentChapter.id : null
|
2021-09-08 16:15:54 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clickChapter(chap) {
|
|
|
|
this.$emit('select', chap)
|
2021-09-24 23:14:33 +02:00
|
|
|
},
|
|
|
|
scrollToChapter() {
|
|
|
|
if (!this.currentChapterId) return
|
|
|
|
|
|
|
|
var container = this.$refs.container
|
|
|
|
if (container) {
|
|
|
|
var currChapterEl = document.getElementById(`chapter-row-${this.currentChapterId}`)
|
|
|
|
if (currChapterEl) {
|
|
|
|
var offsetTop = currChapterEl.offsetTop
|
|
|
|
var containerHeight = container.clientHeight
|
|
|
|
container.scrollTo({ top: offsetTop - containerHeight / 2 })
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 16:15:54 +02:00
|
|
|
}
|
2021-09-24 23:14:33 +02:00
|
|
|
}
|
2021-09-08 16:15:54 +02:00
|
|
|
}
|
|
|
|
</script>
|