Details.client.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <LayoutContainer>
  3. <div class="news-section">
  4. <v-row class="mb-6 center-90">
  5. <v-col class="d-flex align-items-center">
  6. <v-btn
  7. to="/actualites"
  8. prepend-icon="fas fa-arrow-left"
  9. variant="outlined"
  10. class="back-button"
  11. >
  12. Retour aux actualités
  13. </v-btn>
  14. </v-col>
  15. </v-row>
  16. <div v-if="newsItem">
  17. <div class="news">
  18. <CommonMeta
  19. :title="() => newsItem.title!"
  20. :description="() => newsItem.leadText!"
  21. :image="() => getImageUrl(newsItem.attachment)"
  22. />
  23. <v-row class="center-90 mb-12">
  24. <v-col cols="12" md="6">
  25. <v-img
  26. :src="getImageUrl(newsItem.attachment) ?? undefined"
  27. cover
  28. />
  29. </v-col>
  30. <v-col cols="12" md="6" class="d-flex flex-column justify-center">
  31. <h3>
  32. {{ newsItem.title }}
  33. </h3>
  34. <strong>
  35. {{ newsItem.leadText }}
  36. </strong>
  37. <p>
  38. {{ formattedPublicationDate }}
  39. </p>
  40. </v-col>
  41. </v-row>
  42. <v-row class="center-90">
  43. <p class="description" v-html="newsItem.bodyText" />
  44. </v-row>
  45. <v-row class="d-flex justify-center align-center">
  46. <v-btn
  47. v-if="newsItem.linkButton"
  48. :href="newsItem.linkButton"
  49. target="_blank"
  50. class="btn-plus mb-12"
  51. >
  52. En savoir plus
  53. </v-btn>
  54. </v-row>
  55. <v-row class="d-flex justify-space-between center-90">
  56. <div>
  57. <p v-if="newsItem.tags.length > 0">MOTS CLÉS</p>
  58. </div>
  59. <div v-if="mdAndUp">
  60. <p>PARTAGER</p>
  61. </div>
  62. </v-row>
  63. <v-row class="d-flex justify-space-between mb-8 center-90">
  64. <p class="key-word mt-3">
  65. <span v-for="tag in newsItem.tags" :key="tag.id" class="mr-2">
  66. {{ tag.name }}
  67. </span>
  68. </p>
  69. <CommonShare v-if="mdAndUp" />
  70. </v-row>
  71. <div v-if="smAndDown" class="center-90">
  72. <p>PARTAGER</p>
  73. <CommonShare />
  74. </div>
  75. </div>
  76. </div>
  77. </div>
  78. </LayoutContainer>
  79. </template>
  80. <script setup lang="ts">
  81. import { useDisplay } from 'vuetify'
  82. import { parseISO, format } from 'date-fns'
  83. import { fr } from 'date-fns/locale'
  84. import type { ComputedRef } from 'vue'
  85. import News from '~/models/Maestro/News'
  86. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  87. const { mdAndUp, smAndDown } = useDisplay()
  88. const route = useRoute()
  89. const { fetch } = useEntityFetch()
  90. const config = useRuntimeConfig()
  91. const newsId: number = parseInt(route.params.id as string)
  92. if (!newsId || isNaN(newsId)) {
  93. throw new Error('Missing or invalid id')
  94. }
  95. // @ts-expect-error Until we can fix the typing of fetch
  96. const { data: newsItem, pending } = (await fetch(News, newsId)) as Ref<News>
  97. function sleep(time: number) {
  98. return new Promise(resolve => setTimeout(resolve, time))
  99. }
  100. onBeforeMount(async () => {
  101. console.log(newsItem)
  102. while (pending.value) {
  103. console.log('sleep')
  104. await sleep(100)
  105. }
  106. console.log(newsItem)
  107. })
  108. const getImageUrl = (attachment: string | null): string | null => {
  109. if (!attachment) {
  110. return null
  111. }
  112. return `${config.public.apiBaseUrl}/uploads/news/${attachment}`
  113. }
  114. const formattedPublicationDate: ComputedRef<string> = computed(() => {
  115. if (!newsItem.value || !newsItem.value.startPublication) {
  116. return ''
  117. }
  118. const date = parseISO(newsItem.value.startPublication)
  119. let formattedPublicationDate = format(date, "'Le' dd MMMM yyyy", {
  120. locale: fr,
  121. })
  122. formattedPublicationDate = formattedPublicationDate.replace(
  123. 'Le 01 ',
  124. 'Le 1er '
  125. )
  126. return formattedPublicationDate
  127. })
  128. </script>
  129. <style scoped>
  130. .news {
  131. .v-img {
  132. max-height: 600px;
  133. margin-left: auto;
  134. margin-right: auto;
  135. }
  136. h3 {
  137. text-decoration: none;
  138. text-transform: uppercase;
  139. font-size: 36px;
  140. font-weight: 600;
  141. color: var(--primary-color);
  142. }
  143. strong {
  144. font-size: 21px;
  145. margin-top: 16px;
  146. }
  147. .description {
  148. color: var(--primary-color);
  149. max-width: 80%;
  150. font-size: 21px;
  151. font-weight: 500;
  152. line-height: 34px;
  153. margin-left: auto;
  154. margin-right: auto;
  155. margin-bottom: 3rem;
  156. }
  157. .btn-plus {
  158. background: var(--secondary-color);
  159. color: var(--on-secondary-color);
  160. display: flex;
  161. left: 0;
  162. padding: 25px 28px;
  163. align-items: center;
  164. gap: 9px;
  165. font-size: 0.9rem;
  166. border-radius: 5px;
  167. font-weight: 700;
  168. line-height: 15px;
  169. letter-spacing: 1.3px;
  170. text-transform: uppercase;
  171. margin-bottom: -1rem;
  172. }
  173. }
  174. .back-button {
  175. text-decoration: none;
  176. color: var(--on-neutral-color);
  177. font-size: 0.9rem;
  178. font-weight: 700;
  179. line-height: 15px;
  180. letter-spacing: 1.8px;
  181. text-transform: uppercase;
  182. }
  183. .key-word {
  184. color: var(--on-neutral-color);
  185. font-size: 20px;
  186. font-weight: 500;
  187. line-height: 24px;
  188. }
  189. </style>