This commit is contained in:
2026-04-15 23:23:38 +02:00
parent c5e35f0889
commit efe3739626

View File

@@ -226,7 +226,7 @@
<div class="np-number" id="np-number"></div>
<div class="np-song" id="np-song"></div>
<div class="np-eta" id="np-eta" style="display:none">
⏱ Næste dans starter om ca. <b id="np-eta-val"></b>
⏱ Næste dans starter ca. kl. <b id="np-eta-val"></b>
</div>
<!-- Fremgangsbar NEDERST -->
<div class="progress-section">
@@ -299,6 +299,10 @@ function fmtDur(secs) {
return s === 0 ? `${m} min` : `${m}:${String(s).padStart(2,'0')}`;
}
function fmtClock(date) {
return date.toLocaleTimeString('da-DK', { hour: '2-digit', minute: '2-digit' });
}
function fmtTime(d) {
if (!d) return '';
return new Date(d).toLocaleTimeString('da-DK', { hour:'2-digit', minute:'2-digit', second:'2-digit' });
@@ -425,17 +429,17 @@ function render(data) {
document.getElementById('np-song').textContent = '';
}
// ETA til næste dans
// ETA til næste dans — klokkeslæt
const etaEl = document.getElementById('np-eta');
const etaValEl = document.getElementById('np-eta-val');
if (playing && currentIdx >= 0) {
// Find næste pending sang
if (playing && currentIdx >= 0 && data.updated_at) {
const nextIdx = songs.findIndex((s, i) => i > currentIdx && s.status === 'pending');
if (nextIdx >= 0) {
// Varighed af nuværende sang + pause
const updatedAt = new Date(data.updated_at);
const remainSecs = songDuration(playing) + BETWEEN_DANCE_SEC;
etaEl.style.display = '';
etaValEl.textContent = fmtDur(remainSecs);
const nextStart = new Date(updatedAt.getTime() + remainSecs * 1000);
etaEl.style.display = '';
etaValEl.textContent = fmtClock(nextStart);
} else {
etaEl.style.display = 'none';
}
@@ -460,9 +464,15 @@ function render(data) {
document.getElementById('divider').style.display = hasList ? '' : 'none';
document.getElementById('next-label').style.display = hasList ? '' : 'none';
// Beregn kumulative tidsestimater fra nuværende position
// Beregn klokkeslæt for alle sange ud fra updated_at
// Udgangspunkt: updated_at = hvornår nuværende sang startede
const baseTime = data.updated_at ? new Date(data.updated_at) : null;
const playingIdx = songs.findIndex(s => s.status === 'playing');
let cumSecs = 0;
let cumSecs = 0; // akkumuleret tid fra nuværende sang
// Nuværende sang: start = baseTime, slutter baseTime + songDuration
// Næste sang: starter baseTime + songDuration + BETWEEN_DANCE_SEC
// Osv.
document.getElementById('song-list').innerHTML = songs.map((s, i) => {
const icon = s.status === 'played' ? '✓' :
@@ -472,13 +482,23 @@ function render(data) {
const name = getDanceName(s);
const sub = (!s.is_workshop && s.title) ? s.title + (s.artist ? ' · ' + s.artist : '') : '';
// ETA for pending sange efter den der spiller
let etaTxt = '';
if (s.status === 'pending' && playingIdx >= 0 && i > playingIdx) {
cumSecs += songDuration(songs[i-1] || s) + BETWEEN_DANCE_SEC;
if (cumSecs > 0) etaTxt = `~${fmtDur(cumSecs)}`;
} else if (s.status === 'playing') {
cumSecs = 0;
if (s.status === 'playing' && baseTime) {
// Aktuel sang — viser ikke ETA (den vises i np-eta)
cumSecs = songDuration(s) + BETWEEN_DANCE_SEC;
} else if (s.status === 'pending' && playingIdx >= 0 && i > playingIdx && baseTime) {
// Pending sang efter den aktive — beregn klokkeslæt
const startTime = new Date(baseTime.getTime() + cumSecs * 1000);
etaTxt = 'ca. ' + fmtClock(startTime);
cumSecs += songDuration(s) + BETWEEN_DANCE_SEC;
} else if (s.status === 'pending' && playingIdx < 0 && baseTime) {
// Ingen sang spiller — estimér fra nu
const startTime = new Date(baseTime.getTime() + cumSecs * 1000);
etaTxt = 'ca. ' + fmtClock(startTime);
cumSecs += songDuration(s) + BETWEEN_DANCE_SEC;
}
return `