document.addEventListener("DOMContentLoaded", () => { const atletaId = sessionStorage.getItem("userId"); if (!atletaId) { document.getElementById("rutinas-list").innerHTML = "
No se encontró tu sesión. Inicia sesión nuevamente.
"; return; } fetch(`/api/rutinas/atleta/${atletaId}`) .then(res => { if (!res.ok) { throw new Error("Error al obtener rutinas"); } return res.json(); }) .then(rutinas => { const contenedor = document.getElementById("rutinas-list"); if (rutinas.length === 0) { contenedor.innerHTML = "No tienes rutinas asignadas todavía.
"; return; } rutinas.forEach(rutina => { const card = document.createElement("div"); card.className = "card my-3"; card.innerHTML = `${rutina.nombreCompetencia || "Sin descripción"}
Error al cargar tus rutinas.
"; }); }); function verRutina(id) { window.location.href = `simulador.html?routineId=${id}`; } function logout() { sessionStorage.clear(); alert("Sesión cerrada"); window.location.href = "../index.html"; } // Mostrar nombre del usuario logueado en el header window.addEventListener('DOMContentLoaded', async () => { const userId = sessionStorage.getItem("userId"); if (!userId) { alert("Sesión expirada, inicia sesión de nuevo."); window.location.href = "index.html"; return; } try { const res = await fetch(`/api/users/${userId}`); const user = await res.json(); if (user?.name) { document.getElementById("nombreUsuarioHeader").textContent = user.name; document.getElementById("nombreUsuarioDropdown").textContent = "Coach " + user.name; } } catch (err) { console.error("❌ Error al obtener datos del usuario:", err); } });