correction news widget v2
This commit is contained in:
parent
0efc3c7dbb
commit
6075a0ed1c
2
.env
2
.env
@ -46,3 +46,5 @@ ROCKET_CHAT_TOKEN=w91TYgkH-Z67Oz72usYdkW5TZLLRwnre7qyAhp7aHJB
|
|||||||
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
ROCKET_CHAT_USER_ID=Tpuww59PJKsrGNQJB
|
||||||
LEANTIME_TOKEN=lt_lsdShQdoYHaPUWuL07XZR1Rf3GeySsIs_UDlll3VJPk5EwAuILpMC4BwzJ9MZFRrb
|
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 { Button } from "@/components/ui/button";
|
||||||
import { RefreshCw } from "lucide-react";
|
import { RefreshCw } from "lucide-react";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
|
import { formatDistance } from 'date-fns';
|
||||||
|
import { fr } from 'date-fns/locale';
|
||||||
|
|
||||||
interface NewsItem {
|
interface NewsItem {
|
||||||
id: string;
|
id: number;
|
||||||
title: string;
|
title: string;
|
||||||
date: string;
|
date: string;
|
||||||
category: string;
|
source: string;
|
||||||
|
description: string | null;
|
||||||
|
category: string | null;
|
||||||
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function News() {
|
export function News() {
|
||||||
@ -22,19 +27,16 @@ export function News() {
|
|||||||
|
|
||||||
const fetchNews = async (isRefresh = false) => {
|
const fetchNews = async (isRefresh = false) => {
|
||||||
if (isRefresh) setRefreshing(true);
|
if (isRefresh) setRefreshing(true);
|
||||||
setLoading(true);
|
if (!isRefresh) 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' },
|
|
||||||
];
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Simulate API call
|
const response = await fetch('/api/news');
|
||||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
if (!response.ok) {
|
||||||
setNews(mockNews);
|
throw new Error('Failed to fetch news');
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
setNews(data);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Failed to fetch news');
|
setError('Failed to fetch news');
|
||||||
@ -51,6 +53,19 @@ export function News() {
|
|||||||
}
|
}
|
||||||
}, [status]);
|
}, [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) {
|
if (status === 'loading' || loading) {
|
||||||
return (
|
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">
|
<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>
|
<CardTitle className="text-lg font-semibold text-gray-800">News</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="p-6">
|
<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>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
@ -89,15 +106,25 @@ export function News() {
|
|||||||
news.map((item) => (
|
news.map((item) => (
|
||||||
<div
|
<div
|
||||||
key={item.id}
|
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">
|
<div className="flex items-center justify-between mb-1">
|
||||||
<span className="text-sm text-gray-500">{item.date}</span>
|
<span className="text-sm text-gray-500">{formatDate(item.date)}</span>
|
||||||
<span className="text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600">
|
{item.category && (
|
||||||
{item.category}
|
<span className="text-xs px-2 py-0.5 rounded-full bg-blue-50 text-blue-600">
|
||||||
</span>
|
{item.category}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
</div>
|
</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>
|
</div>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -11,6 +11,11 @@ datasource db {
|
|||||||
url = env("DATABASE_URL")
|
url = env("DATABASE_URL")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
datasource newsdb {
|
||||||
|
provider = "postgresql"
|
||||||
|
url = env("NEWSDB_URL")
|
||||||
|
}
|
||||||
|
|
||||||
model Calendar {
|
model Calendar {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
name String
|
name String
|
||||||
@ -41,3 +46,23 @@ model Event {
|
|||||||
@@index([calendarId])
|
@@index([calendarId])
|
||||||
@@index([userId])
|
@@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