From 073fc8fe92e60fd4662580e8216600379a0edfae Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Mon, 14 Apr 2025 03:13:02 -0700 Subject: chore: refactor id to game title conversion to shared module --- site/src/components/NewsFeed.tsx | 20 +++----------------- site/src/pages/Homepage.tsx | 35 ++++------------------------------- site/src/utils.ts | 10 ++++++++++ 3 files changed, 17 insertions(+), 48 deletions(-) create mode 100644 site/src/utils.ts diff --git a/site/src/components/NewsFeed.tsx b/site/src/components/NewsFeed.tsx index 99099be..311fe75 100644 --- a/site/src/components/NewsFeed.tsx +++ b/site/src/components/NewsFeed.tsx @@ -1,3 +1,4 @@ +import { getGameTitle } from "../utils.ts"; export interface NewsData { date: string; @@ -31,7 +32,7 @@ export const NewsFeed: React.FC = ({ newsItems }) => { return (
{/* Header (Game Icon + Info) */} @@ -44,7 +45,7 @@ export const NewsFeed: React.FC = ({ newsItems }) => {
- {getGameName(news.identifier)} + {getGameTitle(news.identifier)} {formattedDate} @@ -122,18 +123,3 @@ export const NewsFeed: React.FC = ({ newsItems }) => {
); }; -function getGameName(identifier: string): string | null { - if(identifier.startsWith("SOUND_VOLTEX")){ - return "SOUND VOLTEX"; - } - else if(identifier.startsWith("IIDX")){ - return "beatmania IIDX"; - } - else if(identifier.startsWith("CHUNITHM_JP")){ - return "CHUNITHM (JAPAN)"; - } - else if(identifier.startsWith("MAIMAIDX_JP")){ - return "maimai DX (JAPAN)" - } - return null; -} diff --git a/site/src/pages/Homepage.tsx b/site/src/pages/Homepage.tsx index 6f53096..0e17a43 100644 --- a/site/src/pages/Homepage.tsx +++ b/site/src/pages/Homepage.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from "react"; import { NewsData, NewsFeed } from "../components/NewsFeed"; import { useParams } from "react-router-dom"; +import { getGameTitle } from "../utils.ts"; import TitleBar from "../components/TitleBar"; interface ArcadeNewsAPIData { @@ -16,23 +17,7 @@ export default function Home() { useEffect(() => { const fetchNews = async () => { setLoading(true); - let jsonFile = "news.json"; - if (gameId) { - switch(gameId) { - case "sdvx": - jsonFile = "sdvx_news.json"; - break; - case "iidx": - jsonFile = "iidx_news.json"; - break; - case "chunithm_jp": - jsonFile = "chunithm_jp_news.json"; - break; - default: - jsonFile = "news.json"; - } - } - + const jsonFile = gameId ? `${gameId}_news.json` : "news.json"; try { const response = await fetch("https://arcade-news.pinapelz.com/"+`${jsonFile}`); if (!response.ok) { @@ -60,18 +45,6 @@ export default function Home() { ); } - // Game-specific title mapping - const getGameTitle = () => { - if (!gameId) return null; - - switch(gameId) { - case "sdvx": return "SOUND VOLTEX"; - case "iidx": return "beatmania IIDX"; - case "chunithm_jp": return "CHUNITHM (JAPAN)"; - default: return gameId.toUpperCase(); - } - }; - return ( <> @@ -79,7 +52,7 @@ export default function Home() {
{gameId && (

- {getGameTitle()} News + {getGameTitle(gameId)} News

)} @@ -87,4 +60,4 @@ export default function Home() {
); -} \ No newline at end of file +} diff --git a/site/src/utils.ts b/site/src/utils.ts new file mode 100644 index 0000000..e523f5c --- /dev/null +++ b/site/src/utils.ts @@ -0,0 +1,10 @@ +export const getGameTitle = (gameId: string) => { + if (!gameId) return null; + + if (gameId.startsWith("sdvx")) return "SOUND VOLTEX"; + if (gameId.startsWith("iidx")) return "beatmania IIDX"; + if (gameId.startsWith("chunithm_jp")) return "CHUNITHM (JAPAN)"; + if (gameId.startsWith("maimaidx_jp")) return "maimai DX (JAPAN)"; + + return gameId.toUpperCase(); +}; -- cgit v1.2.3