From 3d924d70f3d0d16fbb4ae8828c7010f87bcb1951 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sat, 2 Aug 2025 18:34:57 -0700 Subject: preliminary song info display for individual charts --- frontend/src/components/modals/SongInfoDisplay.tsx | 125 +++++++++++++++++++++ frontend/src/pages/Chart.tsx | 15 ++- 2 files changed, 132 insertions(+), 8 deletions(-) create mode 100644 frontend/src/components/modals/SongInfoDisplay.tsx (limited to 'frontend') diff --git a/frontend/src/components/modals/SongInfoDisplay.tsx b/frontend/src/components/modals/SongInfoDisplay.tsx new file mode 100644 index 0000000..946b209 --- /dev/null +++ b/frontend/src/components/modals/SongInfoDisplay.tsx @@ -0,0 +1,125 @@ +import { useEffect, useState, useCallback } from "react"; + +interface ChartInfo { + title: string; + artist: string; + notes?: number; + game?: string; + difficulties: DifficultyInfo[]; +} + +interface DifficultyInfo { + difficulty: string; + level?: number; +} + +interface SongInfoDisplayProps { + scores?: Record[]; +} + +const SongInfoDisplay = ({ + scores = [], +}: SongInfoDisplayProps) => { + const [chartInfo, setChartInfo] = useState(null); + + const extractInfoFromScores = useCallback(() => { + if (scores.length === 0) { + setChartInfo(null); + return; + } + + const firstScore = scores[0]; + const title = firstScore.title as string || "Unknown Title"; + const artist = firstScore.artist as string || "Unknown Artist"; + const notes = firstScore.notes as number; + const game = firstScore.game as string; + + const difficultyMap = new Map(); + + scores.forEach(score => { + if (score.difficulty !== undefined) { + const diffKey = (score.diff_lamp as string) || (score.difficulty as string).toString(); + if (!difficultyMap.has(diffKey)) { + difficultyMap.set(diffKey, { + difficulty: diffKey, + level: score.difficulty as number, + }); + } + } + }); + + const difficulties = Array.from(difficultyMap.values()).sort((a, b) => { + if (a.level !== undefined && b.level !== undefined) { + return a.level - b.level; + } + return a.difficulty.localeCompare(b.difficulty); + }); + + setChartInfo({ + title, + artist, + notes, + game, + difficulties + }); + }, [scores]); + + useEffect(() => { + extractInfoFromScores(); + }, [extractInfoFromScores]); + + if (!chartInfo) return null; + + return ( +
+
+ {/* Left - Song Details */} +
+ {chartInfo.game && ( +
+ + {chartInfo.game} + +
+ )} + +
+

+ {chartInfo.title} +

+

+ {chartInfo.artist} +

+
+ + {chartInfo.notes && ( +
+ Notes + {chartInfo.notes} +
+ )} +
+ + {/* Right - Charts */} +
+

Known Difficulties

+
+ {chartInfo.difficulties.map((diff, index) => ( +
+
+ {diff.difficulty.toUpperCase()} + {diff.level !== undefined && ` ${diff.level}`} +
+
+ ))} +
+
+
+
+ ); +}; + +export default SongInfoDisplay; diff --git a/frontend/src/pages/Chart.tsx b/frontend/src/pages/Chart.tsx index 4271abe..78f6d76 100644 --- a/frontend/src/pages/Chart.tsx +++ b/frontend/src/pages/Chart.tsx @@ -5,6 +5,7 @@ import { NavBar } from "../components/NavBar"; import SessionExpiredPopup from "../components/SessionExpiredPopup"; import ScoreDisplay from "../components/displays/GenericScoreDisplay"; import DancerushScoreDisplay from "../components/displays/DancerushScoreDisplay"; +import SongInfoDisplay from "../components/modals/SongInfoDisplay"; type SortField = string; type SortDirection = "asc" | "desc"; @@ -22,6 +23,7 @@ const Chart = () => { const [sortField, setSortField] = useState(""); const [sortDirection, setSortDirection] = useState("asc"); const [requestOrder, setRequestOrder] = useState("timestamp"); + const chartIdHash = new URLSearchParams(window.location.search).get("chartId") || ""; if (!chartIdHash) { navigate("/home"); @@ -130,16 +132,12 @@ const Chart = () => {
+
-
-

- {scores.length === 0 ? "Unknown Chart" : scores[0].title} -

-

- {scores.length === 0 ? "Unknown Artist" : scores[0].artist} -

-
+
+
); }; -- cgit v1.2.3