Take into account case when there are no active news

This commit is contained in:
Julien Fastré 2023-11-29 13:28:50 +01:00
parent 53d18c7748
commit 6787612071
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 9 additions and 7 deletions

View File

@ -1,5 +1,5 @@
<template>
<div>
<div v-if="newsItems.length > 0">
<h1>{{ $t('widget.news.title') }}</h1>
<ul class="scrollable">
<NewsItem v-for="item in newsItems" :item="item" :key="item.id" />
@ -9,7 +9,7 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { makeFetch } from '../../../lib/api/apiMethods';
import { fetchResults } from '../../../lib/api/apiMethods';
import Modal from '../../_components/Modal.vue';
import { NewsItemType } from '../../../types';
import NewsItem from './NewsItem.vue';
@ -17,10 +17,12 @@ import NewsItem from './NewsItem.vue';
const newsItems = ref<NewsItemType[]>([])
onMounted(() => {
makeFetch('GET', '/api/1.0/main/news.json')
.then((response: { results: NewsItemType[] }) => {
fetchResults<NewsItemType>('/api/1.0/main/news/current.json')
.then((news): Promise<void> => {
// console.log('news articles', response.results)
newsItems.value = response.results
newsItems.value = news;
return Promise.resolve();
})
.catch((error: string) => {
console.error('Error fetching news items', error);

View File

@ -40,9 +40,9 @@
</div>
<div class="mbloc col col-lg-12 col-lg-4" v-if="this.dashboardItems">
<div v-for="dashboardItem in this.dashboardItems">
<template v-for="dashboardItem in this.dashboardItems">
<News v-if="dashboardItem.type === 'news'"/>
</div>
</template>
</div>
</div>