Showing
2 changed files
with
50 additions
and
21 deletions
components/details/ScoreAndVote.vue
0 → 100644
1 | +<script lang="ts" setup> | ||
2 | +//#region --Props--. | ||
3 | +const props = defineProps({ | ||
4 | + score: { | ||
5 | + type: Number, | ||
6 | + required: true, | ||
7 | + nullable: false, | ||
8 | + }, | ||
9 | + nbVote: { | ||
10 | + type: Number, | ||
11 | + required: true, | ||
12 | + nullable: false, | ||
13 | + }, | ||
14 | +}); | ||
15 | +//#endregion | ||
16 | + | ||
17 | +//#region --Function--. | ||
18 | +/** | ||
19 | + * Format vote count if > 1000. | ||
20 | + * @param count | ||
21 | + */ | ||
22 | +const formatVoteCount = (count: number) => { | ||
23 | + if (count >= 1000) { | ||
24 | + return `${(count / 1000).toFixed(1)}k votes`; | ||
25 | + } | ||
26 | + return `${count} votes`; | ||
27 | +}; | ||
28 | +//#endregion | ||
29 | +</script> | ||
30 | + | ||
31 | +<template> | ||
32 | + <section class="flex items-center mb-6"> | ||
33 | + <section class="bg-primary text-white rounded-full w-12 h-12 flex items-center justify-center font-bold mr-3"> | ||
34 | + {{ score.toFixed(1) }} | ||
35 | + </section> | ||
36 | + <section> | ||
37 | + <p class="font-semibold">Note TMDB</p> | ||
38 | + <div class="text-sm text-gray-400">{{ formatVoteCount(nbVote) }}</div> | ||
39 | + </section> | ||
40 | + </section> | ||
41 | +</template> | ||
42 | + | ||
43 | +<style scoped></style> |
@@ -91,17 +91,6 @@ const formatRuntime = (minutes: number) => { | @@ -91,17 +91,6 @@ const formatRuntime = (minutes: number) => { | ||
91 | return `${hours}h ${mins}min`; | 91 | return `${hours}h ${mins}min`; |
92 | }; | 92 | }; |
93 | 93 | ||
94 | -/** | ||
95 | - * Format vote count if > 1000. | ||
96 | - * @param count | ||
97 | - */ | ||
98 | -const formatVoteCount = (count: number) => { | ||
99 | - if (count >= 1000) { | ||
100 | - return `${(count / 1000).toFixed(1)}k votes`; | ||
101 | - } | ||
102 | - return `${count} votes`; | ||
103 | -}; | ||
104 | - | ||
105 | async function fetchCredits(id: number | string) { | 94 | async function fetchCredits(id: number | string) { |
106 | try { | 95 | try { |
107 | const data = (await fetchMovieCredits(id)) as CreditsResponse; | 96 | const data = (await fetchMovieCredits(id)) as CreditsResponse; |
@@ -180,15 +169,7 @@ onMounted(() => { | @@ -180,15 +169,7 @@ onMounted(() => { | ||
180 | </p> | 169 | </p> |
181 | 170 | ||
182 | <!-- Note et votes --> | 171 | <!-- Note et votes --> |
183 | - <div class="flex items-center mb-6"> | 172 | + <details-score-and-vote :nb-vote="movie.vote_count" :score="movie.vote_average" /> |
184 | - <div class="bg-primary text-white rounded-full w-12 h-12 flex items-center justify-center font-bold mr-3"> | ||
185 | - {{ movie.vote_average.toFixed(1) }} | ||
186 | - </div> | ||
187 | - <div> | ||
188 | - <div class="font-semibold">Note TMDB</div> | ||
189 | - <div class="text-sm text-gray-400">{{ formatVoteCount(movie.vote_count) }}</div> | ||
190 | - </div> | ||
191 | - </div> | ||
192 | 173 | ||
193 | <!-- Genres --> | 174 | <!-- Genres --> |
194 | <div class="mb-6"> | 175 | <div class="mb-6"> |
@@ -213,7 +194,12 @@ onMounted(() => { | @@ -213,7 +194,12 @@ onMounted(() => { | ||
213 | </div> | 194 | </div> |
214 | <div v-if="movie.credit.cast.length > 0"> | 195 | <div v-if="movie.credit.cast.length > 0"> |
215 | <span class="font-semibold">Têtes d'affiche:</span> | 196 | <span class="font-semibold">Têtes d'affiche:</span> |
216 | - {{ movie.credit.cast.slice(0, 5).map(person => person.name).join(', ') }} | 197 | + {{ |
198 | + movie.credit.cast | ||
199 | + .slice(0, 5) | ||
200 | + .map((person) => person.name) | ||
201 | + .join(", ") | ||
202 | + }} | ||
217 | </div> | 203 | </div> |
218 | </div> | 204 | </div> |
219 | </div> | 205 | </div> |
-
Please register or login to post a comment