From ae2265df218c088f4b8a4e75dc15d563efc89bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 16:00:46 +0100 Subject: [PATCH] fix errors with data structure --- .../ChillMainBundle/Resources/public/types.ts | 4 +-- .../DashboardWidgets/NewsItem.vue | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/types.ts b/src/Bundle/ChillMainBundle/Resources/public/types.ts index 79dae2695..2e33b8248 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/types.ts +++ b/src/Bundle/ChillMainBundle/Resources/public/types.ts @@ -165,6 +165,6 @@ export interface NewsItemType { id: number; title: string; content: string; - startdate: { date: DateTime }; - enddate: { date: DateTime | null} + startDate: DateTime; + endDate: DateTime | null; } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue index 345545fe9..f4a7cd0eb 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/DashboardWidgets/NewsItem.vue @@ -15,7 +15,7 @@ @@ -30,12 +30,17 @@ import DOMPurify from 'dompurify'; import { DateTime, NewsItemType } from "../../../types"; import type { PropType } from 'vue' import { defineProps, ref } from "vue"; -import {dateToISO} from "../../../chill/js/date"; +import {ISOToDatetime} from "../../../chill/js/date"; const props = defineProps({ item: { type: Object as PropType, required: true + }, + maxLength: { + type: Number, + required: false, + default: 200, } }) @@ -52,13 +57,13 @@ const closeModal = () => { showModal.value = false; }; -const shouldTruncate = (content: string, maxLength = 100): boolean => { - return content.length > maxLength; +const shouldTruncate = (content: string): boolean => { + return content.length > props.maxLength; }; -const truncateContent = (content: string, maxLength = 100): string => { - if (shouldTruncate(content, maxLength)) { - let truncatedContent = content.slice(0, maxLength); +const truncateContent = (content: string): string => { + if (shouldTruncate(content)) { + let truncatedContent = content.slice(0, props.maxLength); let linkDepth = 0; let linkStartIndex = -1; @@ -103,13 +108,13 @@ const convertMarkdownToHtml = (markdown: string): string => { return DOMPurify.sanitize(rawHtml) }; -const prepareContent = (content: string, maxLength = 200): string => { +const prepareContent = (content: string): string => { const htmlContent = convertMarkdownToHtml(content); - return truncateContent(htmlContent, maxLength); + return truncateContent(htmlContent); }; -const formatDate = (datetime: DateTime): string|null => { - return dateToISO(new Date(datetime.toString())) +const newsItemStartDate = (): null|Date => { + return ISOToDatetime(props.item?.startDate.datetime); }