|
| 1 | +<script lang="ts" setup> |
| 2 | +import { NFlex, NSkeleton, NTag } from 'naive-ui'; |
| 3 | +import { computed, type PropType, toRefs } from 'vue'; |
| 4 | +
|
| 5 | +import type { TraktEpisodeExtended } from '~/models/trakt/trakt-episode.model'; |
| 6 | +import type { TraktSeasonExtended } from '~/models/trakt/trakt-season.model'; |
| 7 | +import type { TraktShowExtended } from '~/models/trakt/trakt-show.model'; |
| 8 | +
|
| 9 | +import { capitalizeEachWord } from '~/utils/string.utils'; |
| 10 | +
|
| 11 | +const props = defineProps({ |
| 12 | + episode: { |
| 13 | + type: Object as PropType<TraktEpisodeExtended>, |
| 14 | + required: false, |
| 15 | + }, |
| 16 | + season: { |
| 17 | + type: Object as PropType<TraktSeasonExtended>, |
| 18 | + required: false, |
| 19 | + }, |
| 20 | + show: { |
| 21 | + type: Object as PropType<TraktShowExtended>, |
| 22 | + required: false, |
| 23 | + }, |
| 24 | + mode: { |
| 25 | + type: String as PropType<'show' | 'season' | 'episode'>, |
| 26 | + required: false, |
| 27 | + default: 'episode', |
| 28 | + }, |
| 29 | +}); |
| 30 | +
|
| 31 | +const { mode, episode, season, show } = toRefs(props); |
| 32 | +
|
| 33 | +const aired = computed(() => { |
| 34 | + if (mode.value === 'episode') { |
| 35 | + if (!episode?.value) return; |
| 36 | + if (!episode.value?.first_aired) return '-'; |
| 37 | + return new Date(episode.value?.first_aired).toLocaleDateString(); |
| 38 | + } |
| 39 | + if (mode.value === 'season') { |
| 40 | + if (!season?.value) return; |
| 41 | + if (!season.value?.first_aired) return '-'; |
| 42 | + return new Date(season.value?.first_aired).toLocaleDateString(); |
| 43 | + } |
| 44 | + if (!show?.value) return; |
| 45 | + if (!show.value?.first_aired) return '-'; |
| 46 | + return new Date(show.value?.first_aired).toLocaleDateString(); |
| 47 | +}); |
| 48 | +
|
| 49 | +const runtime = computed(() => { |
| 50 | + if (mode.value === 'episode') { |
| 51 | + if (!episode?.value) return; |
| 52 | + if (!episode.value?.runtime) return '-'; |
| 53 | + return `${episode.value.runtime} min`; |
| 54 | + } |
| 55 | + if (!show?.value) return; |
| 56 | + if (!show.value?.runtime) return '-'; |
| 57 | + return `${show.value.runtime} min`; |
| 58 | +}); |
| 59 | +
|
| 60 | +const genres = computed(() => { |
| 61 | + if (!show?.value) return; |
| 62 | + return show.value?.genres?.map(capitalizeEachWord) ?? []; |
| 63 | +}); |
| 64 | +
|
| 65 | +const year = computed(() => { |
| 66 | + if (!show?.value) return; |
| 67 | + return show.value?.year ?? '-'; |
| 68 | +}); |
| 69 | +
|
| 70 | +const status = computed(() => { |
| 71 | + if (!show?.value) return; |
| 72 | + return capitalizeEachWord(show.value?.status) ?? '-'; |
| 73 | +}); |
| 74 | +
|
| 75 | +const airedEpisodes = computed(() => { |
| 76 | + if (!season?.value) return; |
| 77 | + return `${season.value?.aired_episodes ?? '-'} / ${season.value?.episode_count ?? '-'}`; |
| 78 | +}); |
| 79 | +
|
| 80 | +const episodeType = computed(() => { |
| 81 | + if (!episode?.value) return; |
| 82 | + return episode.value?.episode_type ?? '-'; |
| 83 | +}); |
| 84 | +
|
| 85 | +const network = computed(() => { |
| 86 | + if (!show?.value && !season?.value) return; |
| 87 | + return show?.value?.network ?? season?.value?.network ?? '-'; |
| 88 | +}); |
| 89 | +
|
| 90 | +const country = computed(() => { |
| 91 | + if (!show?.value) return; |
| 92 | + return show.value?.country ?? '-'; |
| 93 | +}); |
| 94 | +</script> |
| 95 | + |
| 96 | +<template> |
| 97 | + <NFlex size="large" class="container" vertical> |
| 98 | + <NFlex class="row" size="large"> |
| 99 | + <!-- Show Year --> |
| 100 | + <NFlex class="detail" align="center"> |
| 101 | + <span class="prefix">Year</span> |
| 102 | + <span v-if="year">{{ year }}</span> |
| 103 | + <NSkeleton v-else style="width: 2.25rem" round /> |
| 104 | + </NFlex> |
| 105 | + |
| 106 | + <!-- Show Country --> |
| 107 | + <NFlex class="detail" align="center"> |
| 108 | + <span class="prefix">Country</span> |
| 109 | + <span v-if="country">{{ country }}</span> |
| 110 | + <NSkeleton v-else style="width: 2ch" round /> |
| 111 | + </NFlex> |
| 112 | + |
| 113 | + <!-- Show Network --> |
| 114 | + <NFlex class="detail" align="center"> |
| 115 | + <span class="prefix">Network</span> |
| 116 | + <span v-if="network">{{ network }}</span> |
| 117 | + <NSkeleton v-else style="width: 5.5rem" round /> |
| 118 | + </NFlex> |
| 119 | + </NFlex> |
| 120 | + |
| 121 | + <NFlex class="row" size="large"> |
| 122 | + <!-- Air date --> |
| 123 | + <NFlex class="detail" align="center"> |
| 124 | + <span class="prefix">Aired</span> |
| 125 | + <span v-if="aired">{{ aired }}</span> |
| 126 | + <NSkeleton v-else style="width: 5.125rem" round /> |
| 127 | + </NFlex> |
| 128 | + |
| 129 | + <!-- Show Status --> |
| 130 | + <NFlex class="detail" align="center"> |
| 131 | + <span class="prefix">Status</span> |
| 132 | + <span v-if="status">{{ status }}</span> |
| 133 | + <NSkeleton v-else style="width: 7.5rem" round /> |
| 134 | + </NFlex> |
| 135 | + |
| 136 | + <!-- Runtime --> |
| 137 | + <NFlex class="detail" align="center"> |
| 138 | + <span class="prefix">Runtime</span> |
| 139 | + <span v-if="runtime">{{ runtime }}</span> |
| 140 | + <NSkeleton v-else style="width: 3.75rem" round /> |
| 141 | + </NFlex> |
| 142 | + </NFlex> |
| 143 | + |
| 144 | + <NFlex class="row" size="large"> |
| 145 | + <!-- Season aired episodes --> |
| 146 | + <NFlex v-if="mode !== 'show'" class="detail" align="center"> |
| 147 | + <span class="prefix">Aired episodes</span> |
| 148 | + <span v-if="airedEpisodes">{{ airedEpisodes }}</span> |
| 149 | + <NSkeleton v-else style="width: 3rem" round /> |
| 150 | + </NFlex> |
| 151 | + |
| 152 | + <!-- Type --> |
| 153 | + <NFlex v-if="mode === 'episode'" class="detail" align="center"> |
| 154 | + <span class="prefix">Type</span> |
| 155 | + <span v-if="episodeType">{{ episodeType }}</span> |
| 156 | + <NSkeleton v-else style="width: 6.25rem" round /> |
| 157 | + </NFlex> |
| 158 | + </NFlex> |
| 159 | + |
| 160 | + <!-- Genres --> |
| 161 | + <NFlex class="detail genres" align="center" justify="flex-start"> |
| 162 | + <span class="prefix">Genres</span> |
| 163 | + <template v-if="genres"> |
| 164 | + <NTag v-for="(genre, i) of genres" :key="i" size="small" round>{{ genre }}</NTag> |
| 165 | + </template> |
| 166 | + <template v-else> |
| 167 | + <NSkeleton style="width: 3rem" round /> |
| 168 | + <NSkeleton style="width: 3rem" round /> |
| 169 | + <NSkeleton style="width: 3rem" round /> |
| 170 | + </template> |
| 171 | + </NFlex> |
| 172 | + </NFlex> |
| 173 | +</template> |
| 174 | + |
| 175 | +<style lang="scss" scoped> |
| 176 | +.container, |
| 177 | +.row { |
| 178 | + flex: 1 1 auto; |
| 179 | + width: 100%; |
| 180 | +} |
| 181 | +
|
| 182 | +.prefix { |
| 183 | + color: var(--white-50); |
| 184 | + font-weight: 600; |
| 185 | + transition: color 0.3s var(--n-bezier); |
| 186 | +} |
| 187 | +
|
| 188 | +.detail { |
| 189 | + flex: 1 1 30%; |
| 190 | +
|
| 191 | + &:hover .prefix { |
| 192 | + color: var(--white-70); |
| 193 | + } |
| 194 | +
|
| 195 | + &.genres { |
| 196 | + flex: 1 1 auto; |
| 197 | + width: 100%; |
| 198 | + margin: 0.5rem 0; |
| 199 | + } |
| 200 | +} |
| 201 | +</style> |
0 commit comments