2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
|
|
|
<article id="lyrics">
|
|
|
|
<div class="content">
|
|
|
|
<template v-if="song">
|
|
|
|
<div v-show="song.lyrics">
|
|
|
|
<div ref="lyricsContainer" v-html="song.lyrics"></div>
|
2022-04-15 17:00:08 +00:00
|
|
|
<TextZoomer :target="textZoomTarget"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
</div>
|
2022-04-21 09:38:24 +00:00
|
|
|
<p v-if="song.id && !song.lyrics" class="none text-secondary">
|
2022-04-15 14:24:30 +00:00
|
|
|
<template v-if="isAdmin">
|
|
|
|
No lyrics found.
|
2022-04-21 09:38:24 +00:00
|
|
|
<button class="text-orange" data-test="add-lyrics-btn" type="button" @click.prevent="showEditSongForm">
|
2022-04-15 14:24:30 +00:00
|
|
|
Click here
|
|
|
|
</button>
|
|
|
|
to add lyrics.
|
|
|
|
</template>
|
|
|
|
<span v-else>No lyrics available. Are you listening to Bach?</span>
|
|
|
|
</p>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</article>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { computed, defineAsyncComponent, onUpdated, reactive, ref, toRefs } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import { userStore } from '@/stores'
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const TextZoomer = defineAsyncComponent(() => import('@/components/ui/text-zoomer.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const props = defineProps<{ song: Song | null }>()
|
|
|
|
const { song } = toRefs(props)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const lyricsContainer = ref(null as unknown as HTMLElement)
|
|
|
|
const textZoomTarget = ref(null as unknown as HTMLElement)
|
|
|
|
const userState = reactive(userStore.state)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-21 09:38:24 +00:00
|
|
|
const showEditSongForm = () => eventBus.emit('MODAL_SHOW_EDIT_SONG_FORM', [song.value], 'lyrics')
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const isAdmin = computed(() => userState.current.is_admin)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
onUpdated(() => {
|
|
|
|
// Since Vue's $refs are not reactive, we work around by assigning to a data property
|
|
|
|
textZoomTarget.value = lyricsContainer.value
|
2022-04-15 14:24:30 +00:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.content {
|
|
|
|
line-height: 1.6;
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.text-zoomer {
|
|
|
|
opacity: 0;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
@media (hover: none) {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover .text-zoomer {
|
|
|
|
opacity: .5;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|