Merge pull request #1240 from Bnyro/chaptersfix

fix the highlighting of the last chapter
This commit is contained in:
Kavin 2022-07-25 17:55:44 +05:30 committed by GitHub
commit 4853582484
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,11 +9,7 @@
v-for="(chapter, index) in chapters" v-for="(chapter, index) in chapters"
@click="$emit('seek', chapter.start)" @click="$emit('seek', chapter.start)"
class="chapter-vertical" class="chapter-vertical"
:class=" :class="{ 'bg-red-500/50': isCurrentChapter(index) }"
playerPosition >= chapter.start && playerPosition < chapters[index + 1].start
? 'chapter-vertical bg-red-500/50'
: 'chapter-vertical'
"
> >
<div class="flex"> <div class="flex">
<span class="mt-5 mr-2 text-current" v-text="index + 1" /> <span class="mt-5 mr-2 text-current" v-text="index + 1" />
@ -31,11 +27,8 @@
:key="chapter.start" :key="chapter.start"
v-for="(chapter, index) in chapters" v-for="(chapter, index) in chapters"
@click="$emit('seek', chapter.start)" @click="$emit('seek', chapter.start)"
:class=" class="chapter"
playerPosition >= chapter.start && playerPosition < chapters[index + 1].start :class="{ 'bg-red-500/50': isCurrentChapter(index) }"
? 'chapter bg-red-500/50'
: 'chapter'
"
> >
<img :src="chapter.image" :alt="chapter.title" /> <img :src="chapter.image" :alt="chapter.title" />
<div class="m-1 flex"> <div class="m-1 flex">
@ -73,7 +66,7 @@
<script setup> <script setup>
import { defineProps, defineEmits } from "vue"; import { defineProps, defineEmits } from "vue";
defineProps({ const props = defineProps({
chapters: Object, chapters: Object,
mobileLayout: { mobileLayout: {
type: Boolean, type: Boolean,
@ -85,5 +78,12 @@ defineProps({
}, },
}); });
const isCurrentChapter = index => {
return (
props.playerPosition >= props.chapters[index].start &&
props.playerPosition < (props.chapters[index + 1]?.start ?? Infinity)
);
};
defineEmits(["seek"]); defineEmits(["seek"]);
</script> </script>