import { useEffect, useState } from "react"; import { NewsData, NewsFeed } from "../components/NewsFeed"; import { Link, useParams, useSearchParams } from "react-router-dom"; import { getGameTitle } from "../utils.ts"; import TitleBar from "../components/TitleBar"; import { GameNotes } from "../components/GameNotes"; import NotificationButton from "../components/NotificationButton"; 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 rssFeedUrl = import.meta.env.VITE_NEWS_BASE_URL + "/" + gameId + "_news.xml"; const newsAPIBase = import.meta.env.VITE_NEWS_BASE_URL; const [newsFeedData, setNewsFeedData] = useState( null, ); const [loading, setLoading] = useState(true); const [error, setError] = useState(false); const [subscribedGames, setSubscribedGames] = useState([]); const [showSubscribedDropdown, setShowSubscribedDropdown] = useState(false); useEffect(() => { // Load subscribed games from localStorage const loadSubscribedGames = () => { const topics = JSON.parse( localStorage.getItem("subscribed_topics") || "[]", ); setSubscribedGames(topics); }; loadSubscribedGames(); // Listen for storage changes to update subscribed games list const handleStorageChange = () => { loadSubscribedGames(); }; window.addEventListener("storage", handleStorageChange); return () => { window.removeEventListener("storage", handleStorageChange); }; }, []); 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 // Update subscribed games when localStorage changes locally useEffect(() => { const checkSubscriptions = () => { const topics = JSON.parse( localStorage.getItem("subscribed_topics") || "[]", ); setSubscribedGames(topics); }; const interval = setInterval(checkSubscriptions, 500); return () => clearInterval(interval); }, []); 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

SECOND STYLE

News and Information for various arcade games is aggregated here!

RSS feeds are available on each game's individual page

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

{/* Subscribed Games Display */} {subscribedGames.length > 0 && (
{showSubscribedDropdown && (
{subscribedGames.map((gameId) => ( {getGameTitle(gameId)} ))}
)}
)}
)}
); }