-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.gohtml
More file actions
249 lines (213 loc) · 5.29 KB
/
stats.gohtml
File metadata and controls
249 lines (213 loc) · 5.29 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find Favourite Song</title>
<style>
.button {
background: linear-gradient(135deg, #ffffff, #f3f3f3);
/* Subtle gradient */
border: none;
padding: 12px 20px;
margin-bottom: 25px;
font-size: 16px;
font-weight: bold;
color: #333;
background: linear-gradient(135deg, #4a78ff, #6b94ff);
border-radius: 4px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.button:hover {
background: linear-gradient(135deg, #6b94ff, #4a78ff);
transform: scale(1.05);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}
.button:active {
transform: scale(0.98);
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.playlist-container {
max-width: 600px;
width: 100%;
}
.playlist {
background: white;
border-radius: 10px;
margin-bottom: 10px;
padding: 15px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: transform 0.2s ease-in-out;
}
/*
.playlist:hover {
transform: scale(1.02);
}
*/
.playlist h2 {
margin: 0;
font-size: 18px;
color: #333;
}
.playlist-content {
display: none;
padding-top: 10px;
}
#new_statistics {
display: flex;
flex-direction: column;
gap: 20px;
padding: 20px;
max-width: 600px;
margin: auto;
}
.points-group {
margin: 15px;
background: #f9f9f9;
border-radius: 10px;
padding: 15px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.points-title {
font-size: 20px;
font-weight: bold;
color: #333;
margin-bottom: 10px;
text-align: center;
}
.song-list {
display: flex;
flex-direction: column;
gap: 10px;
}
.song-item {
background: white;
border-radius: 8px;
padding: 10px;
display: flex;
align-items: center;
gap: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.2s ease-in-out;
}
/*
.song-item:hover {
transform: scale(1.02);
}
*/
.song-wrapper {
display: flex;
align-items: center;
gap: 15px;
width: 100%;
}
.song-image {
width: 60px;
height: 60px;
border-radius: 8px;
object-fit: cover;
}
.song-details {
display: flex;
flex-direction: column;
}
.song-title {
font-size: 16px;
font-weight: bold;
color: #222;
margin: 0;
}
.song-artists {
font-size: 14px;
color: #666;
margin: 0;
}
</style>
<script>
async function fill_in_new_stats(playlist_id) {
const resp = await fetch(`/api/playlist_statistics?playlist=${playlist_id}`);
if (!resp.ok) {
console.error(`error fetching stats: ${resp.status}`)
return
}
const json = await resp.json();
console.log(json);
const points_map = Map.groupBy(json, ({points}) => points);
const new_stats = document.getElementById(`new_statistics_${playlist_id}`);
const colors = ["#ff4d4d", "#ff944d", "#ffd24d", "#99cc66", "#66b3ff", "#8c66ff"];
function getColor(points) {
const index = Math.min(Math.floor(points / 10), colors.length - 1);
return colors[index];
}
[...points_map.keys()].sort((a, b) => a - b).reverse().forEach(points => {
const points_div = document.createElement('div');
points_div.classList.add('points-group');
points_div.style.backgroundColor = getColor(points)
const points_h2 = document.createElement('h2');
points_h2.innerText = `${points} Points`;
points_h2.classList.add('points-title');
points_h2.style.backgroundColor = getColor(points);
points_div.appendChild(points_h2);
const song_list = document.createElement('div');
song_list.classList.add('song-list');
for (const item of points_map.get(points)) {
const item_div = document.createElement('div');
item_div.classList.add('song-item');
item_div.innerHTML = `
<div class="song-wrapper">
<img class="song-image" src="${item.image}" alt="${item.title}">
<div class="song-details">
<h3 class="song-title">${item.title}</h3>
<h4 class="song-artists">${item.artists}</h4>
</div>
</div>
`;
song_list.appendChild(item_div);
}
points_div.appendChild(song_list);
new_stats.appendChild(points_div);
});
}
const alreadyFetched = new Map();
function togglePlaylist(playlistId) {
const contentDiv = document.getElementById(`playlist-${playlistId}`);
if (contentDiv.style.display === "block") {
contentDiv.style.display = "none";
} else if (!alreadyFetched.get(playlistId)) {
contentDiv.style.display = "block";
fill_in_new_stats(playlistId);
alreadyFetched.set(playlistId, true);
} else {
contentDiv.style.display = "block";
}
}
</script>
</head>
<body>
<main>
<div class="playlist-container">
<button class="button" onclick="window.location.href = '/';">Select New Playlist</button>
{{ range . }}
<div class="playlist" onclick="togglePlaylist('{{ .ID }}')">
<h2>{{ .Name }}</h2>
<div id="playlist-{{ .ID }}" class="playlist-content">
<div id="new_statistics_{{ .ID }}"></div>
</div>
</div>
{{ end }}
</div>
</main>
</body>
</html>