From f43388c37760646d043c4bdfc37c23afe305b4a0 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 4 May 2025 16:40:32 +0200 Subject: [PATCH] news widget --- components/news.tsx | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/components/news.tsx b/components/news.tsx index caf0e9d4..fa2b6fd0 100644 --- a/components/news.tsx +++ b/components/news.tsx @@ -5,13 +5,12 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { RefreshCw, Telescope } from "lucide-react"; import { useSession } from "next-auth/react"; -import { formatDistance } from 'date-fns'; -import { fr } from 'date-fns/locale'; interface NewsItem { id: number; title: string; - date: string; + displayDate: string; + timestamp: string; source: string; description: string | null; category: string | null; @@ -36,6 +35,14 @@ export function News() { } const data = await response.json(); + + // Debug log the date values + console.log('News data dates:', data.map((item: NewsItem) => ({ + id: item.id, + displayDate: item.displayDate, + timestamp: item.timestamp + }))); + setNews(data); setError(null); } catch (err) { @@ -53,25 +60,6 @@ export function News() { } }, [status]); - const formatDate = (dateString: string) => { - try { - const date = new Date(dateString); - - // Check if date is valid before using formatDistance - if (isNaN(date.getTime())) { - return dateString; // Return original string if date is invalid - } - - return formatDistance(date, new Date(), { - addSuffix: true, - locale: fr - }); - } catch (err) { - console.error('Error formatting date:', err); - return dateString; - } - }; - if (status === 'loading' || loading) { return ( @@ -123,7 +111,7 @@ export function News() { >
- {formatDate(item.date)} + {item.displayDate}

{item.title}