Extracted properties to methods

This commit is contained in:
Kalle Fagerberg 2022-09-18 18:40:43 +02:00 committed by thrillfall
parent a5d5278956
commit 2d96b26a82

View File

@ -1,22 +1,22 @@
<template> <template>
<ListItem :title="podcastData?.title ?? sub.url" <ListItem :title="getTitle()"
:details="formatSubscriptionDetails(sub)"> :details="getDetails()">
<template #icon> <template #icon>
<Avatar :size="44" <Avatar :size="44"
:url="podcastData?.imageBlob ?? podcastData?.imageUrl" :url="getImageSrc()"
:display-name="podcastData?.author" /> :display-name="getAvatarName()" />
</template> </template>
<template #subtitle> <template #subtitle>
<span v-if="isLoading"><em>(Loading RSS data...)</em></span> <span v-if="isLoading"><em>(Loading RSS data...)</em></span>
<span v-else>{{ podcastData?.description }}</span> <span v-else>{{ getSubtitle() }}</span>
</template> </template>
<template #actions> <template #actions>
<ActionLink :href="podcastData?.link" <ActionLink :href="getHomepageLink()"
target="_blank" target="_blank"
icon="icon-external"> icon="icon-external">
Podcast's homepage Podcast's homepage
</ActionLink> </ActionLink>
<ActionLink :href="sub.url" <ActionLink :href="getRssLink()"
target="_blank"> target="_blank">
<template #icon> <template #icon>
<Rss /> <Rss />
@ -70,18 +70,37 @@ export default {
} }
}, },
methods: { methods: {
formatSubscriptionDetails(sub) { getTitle() {
if (sub.listenedSeconds <= 0) { return this.podcastData?.title ?? this.sub.url ?? ''
},
getDetails() {
if (this.sub.listenedSeconds <= 0) {
return '(no time listened)' return '(no time listened)'
} }
const hours = Math.floor(sub.listenedSeconds / 3600) const seconds = this.sub.listenedSeconds
const modMinutes = Math.floor(sub.listenedSeconds / 60) % 60 const hours = Math.floor(seconds / 3600)
const modMinutes = Math.floor(seconds / 60) % 60
if (hours === 0) { if (hours === 0) {
const modSeconds = sub.listenedSeconds % 60 const modSeconds = seconds % 60
return `(${modMinutes}min ${modSeconds}s listened)` return `(${modMinutes}min ${modSeconds}s listened)`
} }
return `(${hours}h ${modMinutes}min listened)` return `(${hours}h ${modMinutes}min listened)`
}, },
getImageSrc() {
return this.podcastData?.imageBlob ?? this.podcastData?.imageUrl ?? ''
},
getAvatarName() {
return this.podcastData?.author ?? ''
},
getSubtitle() {
return this.podcastData?.description ?? ''
},
getHomepageLink() {
return this.podcastData?.link ?? ''
},
getRssLink() {
return this.sub.url ?? ''
},
}, },
} }
</script> </script>