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 [newsFeedData, setNewsFeedData] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchNews = async () => { setLoading(true); const jsonFile = gameId ? `${gameId}_news.json` : "news.json"; try { const response = await fetch("https://arcade-news.pinapelz.com/"+`${jsonFile}`); 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); } finally { setLoading(false); } }; fetchNews(); }, [gameId]); // Re-fetch when gameId changes if (loading || newsFeedData === null) { return ( <>
); } 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

)}
); }