correction news widget v2
This commit is contained in:
parent
0efc3c7dbb
commit
6075a0ed1c
4
.env
4
.env
@ -45,4 +45,6 @@ NEXT_PUBLIC_IFRAME_AI_ASSISTANT_URL=https://alma.slm-lab.net
|
||||
ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
|
||||
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
||||
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
||||
LEANTIME_API_URL=https://agilite.slm-lab.net
|
||||
LEANTIME_API_URL=https://agilite.slm-lab.net
|
||||
|
||||
NEWSDB_URL=postgresql://alma:Sict33711###@cube.governance-labs.com/rivacube
|
||||
30
app/api/news/route.ts
Normal file
30
app/api/news/route.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const news = await prisma.news.findMany({
|
||||
orderBy: {
|
||||
date: 'desc'
|
||||
},
|
||||
take: 5,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
date: true,
|
||||
source: true,
|
||||
description: true,
|
||||
category: true,
|
||||
url: true
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json(news);
|
||||
} catch (error) {
|
||||
console.error('Error fetching news:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to fetch news' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -5,12 +5,17 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { RefreshCw } from "lucide-react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { formatDistance } from 'date-fns';
|
||||
import { fr } from 'date-fns/locale';
|
||||
|
||||
interface NewsItem {
|
||||
id: string;
|
||||
id: number;
|
||||
title: string;
|
||||
date: string;
|
||||
category: string;
|
||||
source: string;
|
||||
description: string | null;
|
||||
category: string | null;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function News() {
|
||||
@ -22,19 +27,16 @@ export function News() {
|
||||
|
||||
const fetchNews = async (isRefresh = false) => {
|
||||
if (isRefresh) setRefreshing(true);
|
||||
setLoading(true);
|
||||
|
||||
// Placeholder data - replace with actual API call
|
||||
const mockNews = [
|
||||
{ id: '1', title: 'New Project Management Features Released', date: '2024-03-20', category: 'Product Update' },
|
||||
{ id: '2', title: 'Team Meeting Schedule Changes', date: '2024-03-19', category: 'Announcement' },
|
||||
{ id: '3', title: 'Upcoming Training Sessions', date: '2024-03-18', category: 'Training' },
|
||||
];
|
||||
if (!isRefresh) setLoading(true);
|
||||
|
||||
try {
|
||||
// Simulate API call
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
setNews(mockNews);
|
||||
const response = await fetch('/api/news');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch news');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
setNews(data);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError('Failed to fetch news');
|
||||
@ -51,6 +53,19 @@ export function News() {
|
||||
}
|
||||
}, [status]);
|
||||
|
||||
const formatDate = (dateString: string) => {
|
||||
try {
|
||||
const date = new Date(dateString);
|
||||
return formatDistance(date, new Date(), {
|
||||
addSuffix: true,
|
||||
locale: fr
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error formatting date:', err);
|
||||
return dateString;
|
||||
}
|
||||
};
|
||||
|
||||
if (status === 'loading' || loading) {
|
||||
return (
|
||||
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105 bg-white/95 backdrop-blur-sm border-0 shadow-lg h-full">
|
||||
@ -58,7 +73,9 @@ export function News() {
|
||||
<CardTitle className="text-lg font-semibold text-gray-800">News</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="p-6">
|
||||
<p className="text-center text-gray-500">Loading...</p>
|
||||
<div className="flex items-center justify-center">
|
||||
<RefreshCw className="h-5 w-5 animate-spin text-gray-400" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
@ -89,15 +106,25 @@ export function News() {
|
||||
news.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="p-2 hover:bg-gray-50/50 rounded-lg transition-colors"
|
||||
className="p-2 hover:bg-gray-50/50 rounded-lg transition-colors cursor-pointer"
|
||||
onClick={() => window.open(item.url, '_blank')}
|
||||
>
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-sm text-gray-500">{item.date}</span>
|
||||
<span className="text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600">
|
||||
{item.category}
|
||||
</span>
|
||||
<span className="text-sm text-gray-500">{formatDate(item.date)}</span>
|
||||
{item.category && (
|
||||
<span className="text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600">
|
||||
{item.category}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<h3 className="text-sm font-medium text-gray-800 line-clamp-2">{item.title}</h3>
|
||||
<h3 className="text-sm font-medium text-gray-800 line-clamp-2" title={item.title}>
|
||||
{item.title}
|
||||
</h3>
|
||||
{item.description && (
|
||||
<p className="text-xs text-gray-500 mt-1 line-clamp-2" title={item.description}>
|
||||
{item.description}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
|
||||
@ -11,6 +11,11 @@ datasource db {
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
datasource newsdb {
|
||||
provider = "postgresql"
|
||||
url = env("NEWSDB_URL")
|
||||
}
|
||||
|
||||
model Calendar {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
@ -40,4 +45,24 @@ model Event {
|
||||
|
||||
@@index([calendarId])
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model News {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
url String @unique
|
||||
date DateTime
|
||||
source String
|
||||
content String?
|
||||
sentiment_score Float?
|
||||
sentiment String?
|
||||
symbols String[]
|
||||
symbol String?
|
||||
processed_at DateTime @default(now())
|
||||
description String?
|
||||
category String? @db.VarChar(50)
|
||||
|
||||
@@index([category])
|
||||
@@index([date])
|
||||
@@index([symbol])
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user