Ajout composant MovieCommentList.
Ajout createdAt dans interface MovieCommentInterface. Implémentation du composant MovieCommentList dans la page des détails.
Showing
4 changed files
with
63 additions
and
0 deletions
@@ -8,3 +8,5 @@ | @@ -8,3 +8,5 @@ | ||
8 | - Ajout composant BackdropImage. | 8 | - Ajout composant BackdropImage. |
9 | - Ajout composant MovieCommentForm. | 9 | - Ajout composant MovieCommentForm. |
10 | - Ajout model + interface MovieComment. | 10 | - Ajout model + interface MovieComment. |
11 | +- Ajout composant MovieCommentForm. | ||
12 | +- Ajout composant MovieCommentList. |
components/MovieCommentList.vue
0 → 100644
1 | +<script setup lang="ts"> | ||
2 | +//#region --Import--. | ||
3 | +import type { MovieCommentInterface } from "~/interfaces/movieComment"; | ||
4 | +//#endregion | ||
5 | + | ||
6 | +//#region --Props--. | ||
7 | +defineProps({ | ||
8 | + comments: { | ||
9 | + type: Array<MovieCommentInterface>, | ||
10 | + required: true, | ||
11 | + nullable: false | ||
12 | + }, | ||
13 | +}); | ||
14 | +//#endregion | ||
15 | +</script> | ||
16 | + | ||
17 | +<template> | ||
18 | + <!-- Liste des commentaires --> | ||
19 | + <section v-if="comments.length > 0" class="mt-10"> | ||
20 | + <h2>Commentaires publiés</h2> | ||
21 | + <div | ||
22 | + v-for="(comment, index) in comments" | ||
23 | + :key="index" | ||
24 | + class="bg-gray-800 rounded-lg p-6 mb-4" | ||
25 | + > | ||
26 | + <div class="flex justify-between items-start mb-2"> | ||
27 | + <div> | ||
28 | + <h4 class="font-bold text-lg">Par {{ comment.username }}</h4> | ||
29 | + <p class="text-sm text-gray-400">Le {{ useDateFormat(comment.createdAt, "DD-MM-YYYY") }}</p> | ||
30 | + </div> | ||
31 | + <div class="bg-primary text-white rounded-full w-10 h-10 flex items-center justify-center font-bold"> | ||
32 | + {{ comment.rating }} | ||
33 | + </div> | ||
34 | + </div> | ||
35 | + <p class="text-gray-300">{{ comment.message }}</p> | ||
36 | + </div> | ||
37 | + </section> | ||
38 | +</template> | ||
39 | + | ||
40 | +<style scoped> | ||
41 | + | ||
42 | +</style> |
1 | import type { MovieInterface } from "~/interfaces/movie"; | 1 | import type { MovieInterface } from "~/interfaces/movie"; |
2 | 2 | ||
3 | export interface MovieCommentInterface { | 3 | export interface MovieCommentInterface { |
4 | + createdAt: string; | ||
4 | username: string; | 5 | username: string; |
5 | message: string; | 6 | message: string; |
6 | rating: number; | 7 | rating: number; |
@@ -9,10 +9,14 @@ import { Credit } from "~/models/credit"; | @@ -9,10 +9,14 @@ import { Credit } from "~/models/credit"; | ||
9 | import type { CreditsResponse } from "~/interfaces/credit"; | 9 | import type { CreditsResponse } from "~/interfaces/credit"; |
10 | import type { MovieCommentInterface } from "~/interfaces/movieComment"; | 10 | import type { MovieCommentInterface } from "~/interfaces/movieComment"; |
11 | import { MovieComment } from "~/models/movieComment"; | 11 | import { MovieComment } from "~/models/movieComment"; |
12 | +// Infos sur le composable date de Vuetify : https://vuetifyjs.com/en/features/dates/ | ||
13 | +// Et l'api date : https://vuetifyjs.com/en/api/use-date/#exposed | ||
14 | +import { useDate } from "vuetify"; | ||
12 | //#endregion | 15 | //#endregion |
13 | 16 | ||
14 | //#region --Declaration--. | 17 | //#region --Declaration--. |
15 | const { fetchMovieDetails, fetchMovieCredits } = useTMDB(); | 18 | const { fetchMovieDetails, fetchMovieCredits } = useTMDB(); |
19 | +const { date, parseISO, toISO, toJsDate, format, locale } = useDate(); | ||
16 | //#endregion | 20 | //#endregion |
17 | 21 | ||
18 | //#region --Declaration--. | 22 | //#region --Declaration--. |
@@ -60,6 +64,16 @@ const director = computed(() => { | @@ -60,6 +64,16 @@ const director = computed(() => { | ||
60 | return null; | 64 | return null; |
61 | } | 65 | } |
62 | }); | 66 | }); |
67 | + | ||
68 | +/** | ||
69 | + * Retourne les commentaires liés au film, du plus récent au plus ancien. | ||
70 | + */ | ||
71 | +const comments = computed(() => { | ||
72 | + return useRepo(MovieComment).query().where(comment => { | ||
73 | + const searched = comment as unknown as MovieCommentInterface; | ||
74 | + return searched.movie_id === unref(movieId) | ||
75 | + }).orderBy('createdAt', 'desc').get(); | ||
76 | +}); | ||
63 | //#endregion | 77 | //#endregion |
64 | 78 | ||
65 | //#region --Function--. | 79 | //#region --Function--. |
@@ -109,6 +123,7 @@ async function fetchCredits(id: number | string) { | @@ -109,6 +123,7 @@ async function fetchCredits(id: number | string) { | ||
109 | function handleSubmitEvent(event: MovieCommentInterface) { | 123 | function handleSubmitEvent(event: MovieCommentInterface) { |
110 | isSubmitting.value = true; | 124 | isSubmitting.value = true; |
111 | event.movie_id = unref(movieId); | 125 | event.movie_id = unref(movieId); |
126 | + event.createdAt = `${new Date(Date.now())}` | ||
112 | useRepo(MovieComment).save(event); | 127 | useRepo(MovieComment).save(event); |
113 | isSubmitting.value = false; | 128 | isSubmitting.value = false; |
114 | } | 129 | } |
@@ -190,6 +205,9 @@ onMounted(() => { | @@ -190,6 +205,9 @@ onMounted(() => { | ||
190 | <!-- Comments form. --> | 205 | <!-- Comments form. --> |
191 | <h3 class="text-xl font-bold mt-8 mb-4">Ajouter un commentaire</h3> | 206 | <h3 class="text-xl font-bold mt-8 mb-4">Ajouter un commentaire</h3> |
192 | <form-movie-comment-form @event:submit="handleSubmitEvent" /> | 207 | <form-movie-comment-form @event:submit="handleSubmitEvent" /> |
208 | + | ||
209 | + <!-- Liste des commentaires --> | ||
210 | + <movie-comment-list :comments="comments as unknown as MovieCommentInterface[]" /> | ||
193 | </section> | 211 | </section> |
194 | </div> | 212 | </div> |
195 | </div> | 213 | </div> |
-
Please register or login to post a comment