69 lines
2.3 KiB
JavaScript
69 lines
2.3 KiB
JavaScript
/* VitFit display.js — used by workout-display.html and crossfit-display.html */
|
|
'use strict';
|
|
|
|
const Display = (() => {
|
|
let _keepAliveEl = null;
|
|
|
|
function renderWorkout(workout) {
|
|
const nameEl = document.getElementById('display-workout-name');
|
|
const dateEl = document.getElementById('display-workout-date');
|
|
const listEl = document.getElementById('display-workout-list');
|
|
|
|
if (nameEl) nameEl.textContent = workout.name || '';
|
|
if (dateEl && workout.workoutDate) {
|
|
dateEl.textContent = new Date(workout.workoutDate).toLocaleDateString('en-US', { month: 'long', day: 'numeric' });
|
|
}
|
|
|
|
if (listEl) {
|
|
listEl.innerHTML = '';
|
|
(workout.videos || []).filter(s => s.video).forEach(slot => {
|
|
const li = document.createElement('li');
|
|
li.className = 'display-workout-item';
|
|
li.innerHTML = `
|
|
<span class="display-workout-item-name">${slot.video.description || 'Exercise'}</span>
|
|
${slot.reps ? `<span class="display-workout-item-reps">${slot.reps} reps</span>` : ''}
|
|
`;
|
|
listEl.appendChild(li);
|
|
});
|
|
}
|
|
}
|
|
|
|
function renderCrossfit(workout) {
|
|
const nameEl = document.getElementById('display-cf-name');
|
|
const dateEl = document.getElementById('display-cf-date');
|
|
const listEl = document.getElementById('display-cf-list');
|
|
|
|
if (nameEl) nameEl.textContent = workout.name || '';
|
|
if (dateEl && workout.workoutDate) {
|
|
dateEl.textContent = new Date(workout.workoutDate).toLocaleDateString('en-US', { month: 'long', day: 'numeric' });
|
|
}
|
|
|
|
if (listEl) {
|
|
listEl.innerHTML = '';
|
|
(workout.workoutItems || []).forEach(item => {
|
|
const li = document.createElement('li');
|
|
li.className = 'display-crossfit-item';
|
|
li.textContent = item;
|
|
listEl.appendChild(li);
|
|
});
|
|
}
|
|
}
|
|
|
|
function setOffline(isOffline) {
|
|
document.getElementById('display-offline-banner')?.classList.toggle('visible', isOffline);
|
|
}
|
|
|
|
function startKeepAlive() {
|
|
if (_keepAliveEl) return;
|
|
_keepAliveEl = document.createElement('div');
|
|
_keepAliveEl.className = 'keep-alive';
|
|
document.body.appendChild(_keepAliveEl);
|
|
}
|
|
|
|
function applyBranding(branding) {
|
|
Branding.apply(branding);
|
|
}
|
|
|
|
return { renderWorkout, renderCrossfit, setOffline, startKeepAlive, applyBranding };
|
|
})();
|