2022-03-26 23:41:26 +01:00
|
|
|
<template>
|
|
|
|
<div class="w-full px-2 py-3 overflow-hidden relative border-b border-white border-opacity-10" @mouseover="mouseover" @mouseleave="mouseleave">
|
2022-08-14 19:34:21 +02:00
|
|
|
<div v-if="episode" class="flex items-center cursor-pointer" :class="{ 'opacity-70': isSelected || selectionMode }" @click="clickedEpisode">
|
2022-03-26 23:41:26 +01:00
|
|
|
<div class="flex-grow px-2">
|
|
|
|
<p class="text-sm font-semibold">
|
|
|
|
{{ title }}
|
|
|
|
</p>
|
2022-05-28 18:38:51 +02:00
|
|
|
|
|
|
|
<p class="text-sm text-gray-200 episode-subtitle mt-1.5 mb-0.5">{{ subtitle }}</p>
|
|
|
|
|
2022-08-14 19:34:21 +02:00
|
|
|
<div class="flex justify-between pt-2 max-w-xl">
|
|
|
|
<p v-if="episode.season" class="text-sm text-gray-300">Season #{{ episode.season }}</p>
|
|
|
|
<p v-if="episode.episode" class="text-sm text-gray-300">Episode #{{ episode.episode }}</p>
|
|
|
|
<p v-if="publishedAt" class="text-sm text-gray-300">Published {{ $formatDate(publishedAt, 'MMM do, yyyy') }}</p>
|
|
|
|
</div>
|
|
|
|
|
2022-03-26 23:41:26 +01:00
|
|
|
<div class="flex items-center pt-2">
|
2022-05-28 18:38:51 +02:00
|
|
|
<button class="h-8 px-4 border border-white border-opacity-20 hover:bg-white hover:bg-opacity-10 rounded-full flex items-center justify-center cursor-pointer focus:outline-none" :class="userIsFinished ? 'text-white text-opacity-40' : ''" @click.stop="playClick">
|
2022-03-27 00:23:33 +01:00
|
|
|
<span class="material-icons" :class="streamIsPlaying ? '' : 'text-success'">{{ streamIsPlaying ? 'pause' : 'play_arrow' }}</span>
|
|
|
|
<p class="pl-2 pr-1 text-sm font-semibold">{{ timeRemaining }}</p>
|
2022-05-28 18:38:51 +02:00
|
|
|
</button>
|
2022-03-26 23:41:26 +01:00
|
|
|
|
|
|
|
<ui-tooltip :text="userIsFinished ? 'Mark as Not Finished' : 'Mark as Finished'" direction="top">
|
|
|
|
<ui-read-icon-btn :disabled="isProcessingReadUpdate" :is-read="userIsFinished" borderless class="mx-1 mt-0.5" @click="toggleFinished" />
|
|
|
|
</ui-tooltip>
|
2022-08-14 19:34:21 +02:00
|
|
|
|
|
|
|
<ui-icon-btn v-if="userCanUpdate" icon="edit" borderless @click="clickEdit" />
|
|
|
|
<ui-icon-btn v-if="userCanDelete" icon="close" borderless @click="removeClick" />
|
2022-03-26 23:41:26 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-14 19:34:21 +02:00
|
|
|
<div v-if="isHovering || isSelected || selectionMode" class="hidden md:block w-12 min-w-12" />
|
2022-03-26 23:41:26 +01:00
|
|
|
</div>
|
2022-08-14 19:34:21 +02:00
|
|
|
<div v-if="isSelected || selectionMode" class="absolute top-0 left-0 w-full h-full bg-black bg-opacity-10 z-10 cursor-pointer" @click.stop="clickedSelectionBg" />
|
|
|
|
<div class="hidden md:block md:w-12 md:min-w-12 md:-right-0 md:absolute md:top-0 h-full transform transition-transform z-20" :class="!isHovering && !isSelected && !selectionMode ? 'translate-x-24' : 'translate-x-0'">
|
2022-03-26 23:41:26 +01:00
|
|
|
<div class="flex h-full items-center">
|
|
|
|
<div class="mx-1">
|
2022-08-14 19:34:21 +02:00
|
|
|
<ui-checkbox v-model="isSelected" @input="selectedUpdated" checkbox-bg="bg" />
|
2022-03-26 23:41:26 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-03-27 00:23:33 +01:00
|
|
|
<div v-if="!userIsFinished" class="absolute bottom-0 left-0 h-0.5 bg-warning" :style="{ width: itemProgressPercent * 100 + '%' }" />
|
2022-03-26 23:41:26 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
libraryItemId: String,
|
|
|
|
episode: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
2022-08-14 19:34:21 +02:00
|
|
|
},
|
|
|
|
selectionMode: Boolean
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isProcessingReadUpdate: false,
|
|
|
|
processingRemove: false,
|
2022-08-14 19:34:21 +02:00
|
|
|
isHovering: false,
|
|
|
|
isSelected: false
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2022-04-12 02:42:09 +02:00
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
|
|
|
},
|
|
|
|
userCanDelete() {
|
|
|
|
return this.$store.getters['user/getUserCanDelete']
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
audioFile() {
|
|
|
|
return this.episode.audioFile
|
|
|
|
},
|
|
|
|
title() {
|
|
|
|
return this.episode.title || ''
|
|
|
|
},
|
2022-05-28 18:38:51 +02:00
|
|
|
subtitle() {
|
|
|
|
return this.episode.subtitle || ''
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
description() {
|
2022-05-28 18:38:51 +02:00
|
|
|
return this.episode.description || ''
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
|
|
|
duration() {
|
|
|
|
return this.$secondsToTimestamp(this.episode.duration)
|
|
|
|
},
|
|
|
|
isStreaming() {
|
2022-07-30 19:25:15 +02:00
|
|
|
return this.$store.getters['getIsMediaStreaming'](this.libraryItemId, this.episode.id)
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
|
|
|
streamIsPlaying() {
|
|
|
|
return this.$store.state.streamIsPlaying && this.isStreaming
|
|
|
|
},
|
|
|
|
itemProgress() {
|
|
|
|
return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId, this.episode.id)
|
|
|
|
},
|
|
|
|
itemProgressPercent() {
|
|
|
|
return this.itemProgress ? this.itemProgress.progress : 0
|
|
|
|
},
|
|
|
|
userIsFinished() {
|
|
|
|
return this.itemProgress ? !!this.itemProgress.isFinished : false
|
|
|
|
},
|
|
|
|
timeRemaining() {
|
|
|
|
if (this.streamIsPlaying) return 'Playing'
|
|
|
|
if (!this.itemProgress) return this.$elapsedPretty(this.episode.duration)
|
|
|
|
if (this.userIsFinished) return 'Finished'
|
|
|
|
var remaining = Math.floor(this.itemProgress.duration - this.itemProgress.currentTime)
|
|
|
|
return `${this.$elapsedPretty(remaining)} left`
|
2022-04-10 18:01:50 +02:00
|
|
|
},
|
|
|
|
publishedAt() {
|
|
|
|
return this.episode.publishedAt
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-08-14 19:34:21 +02:00
|
|
|
clickedEpisode() {
|
|
|
|
this.$emit('view', this.episode)
|
|
|
|
},
|
|
|
|
clickedSelectionBg() {
|
|
|
|
this.isSelected = !this.isSelected
|
|
|
|
this.selectedUpdated(this.isSelected)
|
|
|
|
},
|
|
|
|
selectedUpdated(value) {
|
|
|
|
this.$emit('selected', { isSelected: value, episode: this.episode })
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
mouseover() {
|
|
|
|
this.isHovering = true
|
|
|
|
},
|
|
|
|
mouseleave() {
|
|
|
|
this.isHovering = false
|
|
|
|
},
|
2022-03-27 22:37:04 +02:00
|
|
|
clickEdit() {
|
|
|
|
this.$emit('edit', this.episode)
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
playClick() {
|
|
|
|
if (this.streamIsPlaying) {
|
|
|
|
this.$eventBus.$emit('pause-item')
|
|
|
|
} else {
|
2022-08-28 20:12:38 +02:00
|
|
|
this.$emit('play', this.episode)
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
2022-07-30 19:40:43 +02:00
|
|
|
toggleFinished(confirmed = false) {
|
|
|
|
if (!this.userIsFinished && this.itemProgressPercent > 0 && !confirmed) {
|
|
|
|
const payload = {
|
|
|
|
message: `Are you sure you want to mark "${this.title}" as finished?`,
|
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.toggleFinished(true)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-26 23:41:26 +01:00
|
|
|
var updatePayload = {
|
|
|
|
isFinished: !this.userIsFinished
|
|
|
|
}
|
|
|
|
this.isProcessingReadUpdate = true
|
|
|
|
this.$axios
|
|
|
|
.$patch(`/api/me/progress/${this.libraryItemId}/${this.episode.id}`, updatePayload)
|
|
|
|
.then(() => {
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
this.$toast.success(`Item marked as ${updatePayload.isFinished ? 'Finished' : 'Not Finished'}`)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
this.isProcessingReadUpdate = false
|
|
|
|
this.$toast.error(`Failed to mark as ${updatePayload.isFinished ? 'Finished' : 'Not Finished'}`)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
removeClick() {
|
2022-05-25 01:38:25 +02:00
|
|
|
this.$emit('remove', this.episode)
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
2022-04-16 03:49:13 +02:00
|
|
|
}
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
</script>
|