|
| 1 | +<template> |
| 2 | + <NcListItem |
| 3 | + :active="isActive" |
| 4 | + :name="video.title || 'Untitled'" |
| 5 | + @click.prevent="onPlay" |
| 6 | + :bold="false"> |
| 7 | + <template #icon> |
| 8 | + <img |
| 9 | + v-if="video.thumbnail" |
| 10 | + :src="video.thumbnail" |
| 11 | + alt="Thumbnail" |
| 12 | + class="thumbnail" |
| 13 | + width="44" |
| 14 | + height="44" /> |
| 15 | + <Filmstrip v-else :size="44" /> |
| 16 | + </template> |
| 17 | + |
| 18 | + <template #subname> |
| 19 | + <span v-if="video.year || video.genre"> |
| 20 | + <span v-if="video.year">{{ video.year }}</span> |
| 21 | + <span v-if="video.year && video.genre"> • </span> |
| 22 | + <span v-if="video.genre">{{ video.genre }}</span> |
| 23 | + </span> |
| 24 | + <span v-else-if="video.duration">{{ formatDuration(video.duration) }}</span> |
| 25 | + </template> |
| 26 | + |
| 27 | + <template #actions> |
| 28 | + <slot name="actions-start" /> |
| 29 | + |
| 30 | + <NcActionButton v-if="!disablePlay" @click.stop="onPlay"> |
| 31 | + <template #icon> |
| 32 | + <Play :size="20" /> |
| 33 | + </template> |
| 34 | + Play |
| 35 | + </NcActionButton> |
| 36 | + |
| 37 | + <NcActionButton v-if="!disablePlayNext" @click.stop="onPlayNext"> |
| 38 | + <template #icon> |
| 39 | + <SkipNext :size="20" /> |
| 40 | + </template> |
| 41 | + Play Next |
| 42 | + </NcActionButton> |
| 43 | + |
| 44 | + <NcActionButton v-if="!disableAddToQueue" @click.stop="onAddToQueue"> |
| 45 | + <template #icon> |
| 46 | + <PlaylistPlus :size="20" /> |
| 47 | + </template> |
| 48 | + Add to Queue |
| 49 | + </NcActionButton> |
| 50 | + |
| 51 | + <slot name="actions-end" /> |
| 52 | + </template> |
| 53 | + </NcListItem> |
| 54 | +</template> |
| 55 | + |
| 56 | +<script lang="ts"> |
| 57 | + import { defineComponent, computed, type PropType } from 'vue' |
| 58 | + import { type Video } from '@/models/media' |
| 59 | + import playback from '@/composables/usePlayback' |
| 60 | +
|
| 61 | + import NcListItem from '@nextcloud/vue/components/NcListItem' |
| 62 | + import NcActionButton from '@nextcloud/vue/components/NcActionButton' |
| 63 | +
|
| 64 | + import Filmstrip from '@icons/Filmstrip.vue' |
| 65 | + import Play from '@icons/Play.vue' |
| 66 | + import SkipNext from '@icons/SkipNext.vue' |
| 67 | + import PlaylistPlus from '@icons/PlaylistPlus.vue' |
| 68 | +
|
| 69 | + export default defineComponent({ |
| 70 | + name: 'VideoListItem', |
| 71 | + props: { |
| 72 | + video: { |
| 73 | + type: Object as PropType<Video>, |
| 74 | + required: true, |
| 75 | + }, |
| 76 | + disablePlay: { |
| 77 | + type: Boolean, |
| 78 | + default: false, |
| 79 | + }, |
| 80 | + disablePlayNext: { |
| 81 | + type: Boolean, |
| 82 | + default: false, |
| 83 | + }, |
| 84 | + disableAddToQueue: { |
| 85 | + type: Boolean, |
| 86 | + default: false, |
| 87 | + }, |
| 88 | + }, |
| 89 | + components: { |
| 90 | + NcActionButton, |
| 91 | + NcListItem, |
| 92 | + Filmstrip, |
| 93 | + Play, |
| 94 | + SkipNext, |
| 95 | + PlaylistPlus, |
| 96 | + }, |
| 97 | + emits: ['play'], |
| 98 | + setup(props, { emit }) { |
| 99 | + const { currentMedia, addToQueue, addAsNext } = playback |
| 100 | +
|
| 101 | + const isActive = computed(() => |
| 102 | + props.video.id === currentMedia.value?.id && currentMedia.value?.type === 'video' |
| 103 | + ) |
| 104 | +
|
| 105 | + const onPlay = () => emit('play', props.video) |
| 106 | + const onPlayNext = () => addAsNext({ type: 'video', ...props.video }) |
| 107 | + const onAddToQueue = () => addToQueue({ type: 'video', ...props.video }) |
| 108 | +
|
| 109 | + const formatDuration = (seconds: number): string => { |
| 110 | + const hours = Math.floor(seconds / 3600) |
| 111 | + const minutes = Math.floor((seconds % 3600) / 60) |
| 112 | + const secs = seconds % 60 |
| 113 | +
|
| 114 | + if (hours > 0) { |
| 115 | + return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}` |
| 116 | + } |
| 117 | + return `${minutes}:${secs.toString().padStart(2, '0')}` |
| 118 | + } |
| 119 | +
|
| 120 | + return { |
| 121 | + isActive, |
| 122 | + onPlay, |
| 123 | + onPlayNext, |
| 124 | + onAddToQueue, |
| 125 | + formatDuration, |
| 126 | + } |
| 127 | + }, |
| 128 | + }) |
| 129 | +</script> |
| 130 | + |
| 131 | +<style scoped lang="scss"> |
| 132 | + .thumbnail { |
| 133 | + border-radius: 4px; |
| 134 | + object-fit: cover; |
| 135 | +} |
| 136 | +</style> |
0 commit comments