mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-05 07:19:49 +00:00
add typing
This commit is contained in:
parent
d828a6b9e0
commit
ed2d41c225
@ -160,3 +160,11 @@ export interface LocationType {
|
||||
contactData: "optional" | "required";
|
||||
title: TranslatableString;
|
||||
}
|
||||
|
||||
export interface NewsItem {
|
||||
id: number;
|
||||
title: string;
|
||||
content: string;
|
||||
startdate: { date: DateTime };
|
||||
enddate: { date: DateTime | null}
|
||||
}
|
||||
|
@ -27,18 +27,17 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import {makeFetch} from "ChillMainAssets/lib/api/apiMethods";
|
||||
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
||||
import Modal from '../../_components/Modal.vue'; // Adjust the import path
|
||||
import { marked } from 'marked';
|
||||
import DOMPurify from 'dompurify';
|
||||
import { NewsItem } from "ChillMainAssets/types";
|
||||
|
||||
|
||||
|
||||
const newsItems = ref([])
|
||||
const selectedArticle = ref(null);
|
||||
const newsItems = ref<NewsItem[]>([])
|
||||
const selectedArticle = ref<NewsItem | null>(null);
|
||||
const showModal = ref(false);
|
||||
|
||||
const openModal = (item) => {
|
||||
const openModal = (item: NewsItem) => {
|
||||
selectedArticle.value = item;
|
||||
showModal.value = true;
|
||||
};
|
||||
@ -48,11 +47,11 @@ const closeModal = () => {
|
||||
showModal.value = false;
|
||||
};;
|
||||
|
||||
const shouldTruncate = (content, maxLength = 100) => {
|
||||
const shouldTruncate = (content: string, maxLength = 100): boolean => {
|
||||
return content.length > maxLength;
|
||||
};
|
||||
|
||||
const truncateContent = (content, maxLength = 100) => {
|
||||
const truncateContent = (content: string, maxLength = 100): string => {
|
||||
if (shouldTruncate(content, maxLength)) {
|
||||
return content.slice(0, maxLength) + '...';
|
||||
} else {
|
||||
@ -60,23 +59,23 @@ const truncateContent = (content, maxLength = 100) => {
|
||||
}
|
||||
};
|
||||
|
||||
const convertMarkdownToHtml = (markdown) => {
|
||||
const convertMarkdownToHtml = (markdown: string): string => {
|
||||
const rawHtml = marked(markdown);
|
||||
return DOMPurify.sanitize(rawHtml)
|
||||
};
|
||||
|
||||
const truncateMarkdownContent = (content, maxLength = 100) => {
|
||||
const truncateMarkdownContent = (content: string, maxLength = 100): string => {
|
||||
const htmlContent = convertMarkdownToHtml(content);
|
||||
return truncateContent(htmlContent, maxLength);
|
||||
};
|
||||
|
||||
const formatDate = (datetime) => {
|
||||
const formatDate = (datetime: { date: string }): string => {
|
||||
return new Date(datetime.date).toDateString()
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
makeFetch('GET', '/api/1.0/main/news.json')
|
||||
.then((response) => {
|
||||
.then((response: {results: NewsItem[]}) => {
|
||||
newsItems.value = response.results
|
||||
})
|
||||
.catch((error) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user