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 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 frontend/src/components/modals/SongInfoDisplay.tsx (limited to 'frontend/src/components/modals/SongInfoDisplay.tsx') 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; -- cgit v1.2.3