import { useEffect, useState } from "react"; import { NewsData, NewsFeed } from "../components/NewsFeed"; import { useParams, useSearchParams } from "react-router-dom"; import { getGameTitle } from "../utils.ts"; import TitleBar from "../components/TitleBar"; import { GameNotes } from "../components/GameNotes"; interface ArcadeNewsAPIData { fetch_time: number; news_posts: Array; } export default function Home() { const { gameId } = useParams<{ gameId?: string }>(); const [searchParams] = useSearchParams(); const isMoe = searchParams.has("moe"); const newsAPIBase = import.meta.env.VITE_NEWS_BASE_URL const [newsFeedData, setNewsFeedData] = useState( null, ); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); useEffect(() => { const fetchNews = async () => { setLoading(true); setError(false); const newsDataFileName = gameId ? `${gameId}_news.json` : "news.json"; try { const response = await fetch( newsAPIBase+"/" + `${newsDataFileName}`, ); if (!response.ok) { throw new Error(`Failed to fetch news: ${response.statusText}`); } const data: ArcadeNewsAPIData = await response.json(); setNewsFeedData(data); } catch (e) { console.error(e); setError(true); } finally { setLoading(false); } }; fetchNews(); }, [gameId, newsAPIBase]); // Re-fetch when gameId changes if (loading) { return ( <>
); } if (error || newsFeedData === null) { return ( <>
404

News Not Found

{gameId ? `Unable to fetch news for ${getGameTitle(gameId)}` : "Unable to fetch news feed" }

The news feed you're looking for might be temporarily unavailable or doesn't exist.

Return Home
); } return ( <>
{gameId ? (

{getGameTitle(gameId)} News

{GameNotes(isMoe)[gameId] && (
{GameNotes(isMoe)[gameId]}
)}
) : (

Welcome to 573-UPDATES

News and Information for various arcade games is aggregated here!

Please see the{" "} GitHub {" "} for API information

)}
); }