"use client"; import { useEffect, useState } from "react"; import { Newspaper } from "lucide-react"; import Link from "next/link"; interface NewsItem { id: string; title: string; summary: string; } const NewsPage = () => { const [news, setNews] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchNews = async () => { try { console.log("Fetching news..."); const response = await fetch( "https://raw.githubusercontent.com/newspedia-crew/newspedia-web/intern-change/public/data/index.json", ); console.log("Response status:", response.status); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log("Fetched data:", data); setNews(data); } catch (error) { console.error("Error fetching news:", error); setError(`Failed to load news. Error: ${error instanceof Error ? error.message : String(error)}`); } finally { setLoading(false); } }; fetchNews(); }, []); return (

News

{loading ? (

Loading news...

) : (error ? (

Failed to load news.

{error}

) : (
{news.length === 0 ? (

No news available.

) : ( news.map(item => (

{item.title}

{item.summary}

)) )}
))}
); }; export default NewsPage;