1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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<string, unknown>[];
}
const SongInfoDisplay = ({
scores = [],
}: SongInfoDisplayProps) => {
const [chartInfo, setChartInfo] = useState<ChartInfo | null>(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<string, DifficultyInfo>();
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 (
<div className="bg-slate-900/80 backdrop-blur-sm rounded-xl border border-slate-700 p-6 mb-8">
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Left - Song Details */}
<div className="lg:col-span-2 space-y-4">
{chartInfo.game && (
<div className="text-center">
<span className="text-sm font-medium text-slate-300 uppercase tracking-wide">
{chartInfo.game}
</span>
</div>
)}
<div className="text-center">
<h3 className="text-2xl font-bold text-white mb-2">
{chartInfo.title}
</h3>
<p className="text-lg text-slate-300">
{chartInfo.artist}
</p>
</div>
{chartInfo.notes && (
<div className="text-center mt-4">
<span className="block text-xs text-slate-400 mb-1">Notes</span>
<span className="text-sm text-white">{chartInfo.notes}</span>
</div>
)}
</div>
{/* Right - Charts */}
<div>
<h4 className="text-sm font-semibold text-white mb-3 text-center">Known Difficulties</h4>
<div className="space-y-2">
{chartInfo.difficulties.map((diff, index) => (
<div
key={index}
className="bg-slate-800/50 rounded-lg p-3 border border-slate-600 text-center"
>
<div className="font-medium text-white text-sm">
{diff.difficulty.toUpperCase()}
{diff.level !== undefined && ` ${diff.level}`}
</div>
</div>
))}
</div>
</div>
</div>
</div>
);
};
export default SongInfoDisplay;
|