Showing
1 changed file
with
29 additions
and
7 deletions
| @@ -2,11 +2,11 @@ | @@ -2,11 +2,11 @@ | ||
| 2 | //#region --import--. | 2 | //#region --import--. |
| 3 | import { ArrowLeftIcon, FilmIcon } from "lucide-vue-next"; | 3 | import { ArrowLeftIcon, FilmIcon } from "lucide-vue-next"; |
| 4 | import { useTMDB } from "~/composables/tMDB"; | 4 | import { useTMDB } from "~/composables/tMDB"; |
| 5 | -import { onMounted, ref } from "vue"; | 5 | +import { computed, onMounted, ref } from "vue"; |
| 6 | import { Movie } from "~/models/movie"; | 6 | import { Movie } from "~/models/movie"; |
| 7 | import type { MovieInterface } from "~/interfaces/movie"; | 7 | import type { MovieInterface } from "~/interfaces/movie"; |
| 8 | import { Credit } from "~/models/credit"; | 8 | import { Credit } from "~/models/credit"; |
| 9 | -import type { CreditInterface, CreditsResponse } from "~/interfaces/credit"; | 9 | +import type { CreditsResponse } from "~/interfaces/credit"; |
| 10 | //#endregion | 10 | //#endregion |
| 11 | 11 | ||
| 12 | //#region --Declaration--. | 12 | //#region --Declaration--. |
| @@ -46,6 +46,17 @@ const movie = computed(() => { | @@ -46,6 +46,17 @@ const movie = computed(() => { | ||
| 46 | return null; | 46 | return null; |
| 47 | } | 47 | } |
| 48 | }); | 48 | }); |
| 49 | + | ||
| 50 | +/** | ||
| 51 | + * Computed property for director | ||
| 52 | + */ | ||
| 53 | +const director = computed(() => { | ||
| 54 | + if (unref(movie)?.credit?.crew) { | ||
| 55 | + return movie.value?.credit.crew.find((person) => person.job === "Director"); | ||
| 56 | + } else { | ||
| 57 | + return null; | ||
| 58 | + } | ||
| 59 | +}); | ||
| 49 | //#endregion | 60 | //#endregion |
| 50 | 61 | ||
| 51 | //#region --Function--. | 62 | //#region --Function--. |
| @@ -91,18 +102,17 @@ const formatVoteCount = (count: number) => { | @@ -91,18 +102,17 @@ const formatVoteCount = (count: number) => { | ||
| 91 | return `${count} votes`; | 102 | return `${count} votes`; |
| 92 | }; | 103 | }; |
| 93 | 104 | ||
| 94 | -async function fetchCredits(id: number|string) { | 105 | +async function fetchCredits(id: number | string) { |
| 95 | try { | 106 | try { |
| 96 | - const data = await fetchMovieCredits(id) as CreditsResponse; | 107 | + const data = (await fetchMovieCredits(id)) as CreditsResponse; |
| 97 | data.movie_id = id; | 108 | data.movie_id = id; |
| 98 | // Add to store collection. | 109 | // Add to store collection. |
| 99 | - console.log('credit response', data) | ||
| 100 | - | ||
| 101 | useRepo(Credit).save(data); | 110 | useRepo(Credit).save(data); |
| 102 | } catch (error) { | 111 | } catch (error) { |
| 103 | console.error("Error fetching movie credits:", error); | 112 | console.error("Error fetching movie credits:", error); |
| 104 | } | 113 | } |
| 105 | } | 114 | } |
| 115 | + | ||
| 106 | //#endregion | 116 | //#endregion |
| 107 | 117 | ||
| 108 | //#region --Global event--. | 118 | //#region --Global event--. |
| @@ -111,7 +121,7 @@ onMounted(() => { | @@ -111,7 +121,7 @@ onMounted(() => { | ||
| 111 | if (unref(movieId)) { | 121 | if (unref(movieId)) { |
| 112 | const id = unref(movieId) as string | number; | 122 | const id = unref(movieId) as string | number; |
| 113 | fetchDetails(id); | 123 | fetchDetails(id); |
| 114 | - fetchCredits(id) | 124 | + fetchCredits(id); |
| 115 | } | 125 | } |
| 116 | // loadComments() | 126 | // loadComments() |
| 117 | }); | 127 | }); |
| @@ -194,6 +204,18 @@ onMounted(() => { | @@ -194,6 +204,18 @@ onMounted(() => { | ||
| 194 | <h2 class="text-xl font-bold mb-2">Synopsis</h2> | 204 | <h2 class="text-xl font-bold mb-2">Synopsis</h2> |
| 195 | <p class="text-gray-300">{{ movie.overview || "Aucun synopsis disponible." }}</p> | 205 | <p class="text-gray-300">{{ movie.overview || "Aucun synopsis disponible." }}</p> |
| 196 | </div> | 206 | </div> |
| 207 | + | ||
| 208 | + <!-- Réalisateur et têtes d'affiche --> | ||
| 209 | + <div v-if="movie.credit" class="mb-6"> | ||
| 210 | + <h2 class="text-xl font-bold mb-2">Équipe</h2> | ||
| 211 | + <div v-if="director" class="mb-2"> | ||
| 212 | + <span class="font-semibold">Réalisateur:</span> {{ director.name }} | ||
| 213 | + </div> | ||
| 214 | + <div v-if="movie.credit.cast.length > 0"> | ||
| 215 | + <span class="font-semibold">Têtes d'affiche:</span> | ||
| 216 | + {{ movie.credit.cast.slice(0, 5).map(person => person.name).join(', ') }} | ||
| 217 | + </div> | ||
| 218 | + </div> | ||
| 197 | </div> | 219 | </div> |
| 198 | </div> | 220 | </div> |
| 199 | </div> | 221 | </div> |
-
Please register or login to post a comment