'use client' import { Skeleton } from '@thedaviddias/design-system/skeleton' import { logger } from '@thedaviddias/logging' import { ArrowRight, ExternalLink, Rss } from 'lucide-react' import Link from 'next/link' import { useEffect, useState } from 'react' import { RSS_FEED_URL } from '@/app/api/rss-feed/route' import { Card } from '@/components/ui/card' import { getRoute } from '@/lib/routes' interface NewsItem { title: string link: string pubDate: string } const NUMBER_OF_NEWS_ITEMS = 4 /** * Displays a list of the latest news items fetched from the RSS feed */ export function LatestNews() { const [news, setNews] = useState([]) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) useEffect(() => { /** * Fetches news items from the RSS feed API */ async function fetchNews() { try { setIsLoading(true) const response = await fetch('/api/rss-feed') if (!response.ok) { throw new Error('Failed to fetch news') } const data = await response.json() setNews(data.items.slice(0, NUMBER_OF_NEWS_ITEMS)) } catch (error) { logger.error('Failed to fetch news:', { data: error, tags: { type: 'component' } }) setError('Failed to load latest news. Please try again later.') } finally { setIsLoading(false) } } fetchNews() }, []) if (isLoading) { return (

Latest News

RSS Feed for latest news
All news
{Array.from({ length: NUMBER_OF_NEWS_ITEMS }).map((_, index) => ( ))}
) } if (error) { return
{error}
} return (

Latest News

RSS Feed for latest news
All news
{isLoading ? ( Array.from({ length: NUMBER_OF_NEWS_ITEMS }).map((_, index) => ( )) ) : news.length > 0 ? ( news.map((item, index) => (

{item.title}

{new Date(item.pubDate).toLocaleDateString()}

)) ) : (

No news items available at the moment.

)}
) }