From 04c68e863b079ab0346616b2b32ff2145e0cf6c9 Mon Sep 17 00:00:00 2001 From: Tatiana Villa Ema Date: Sun, 22 Feb 2026 23:59:45 +0100 Subject: [PATCH] frontend pilotos --- f1.html | 28 ++++++++++++----------- js/f1.js | 63 ++++++++++++++++++++++++++++++++++++++++------------ pilotos.html | 44 +----------------------------------- 3 files changed, 65 insertions(+), 70 deletions(-) diff --git a/f1.html b/f1.html index 0a80220..9f60b07 100644 --- a/f1.html +++ b/f1.html @@ -21,20 +21,22 @@
-

Cargando sesión...

-
Buscando señal...
- - - - - - - - - - +

Pilotos

+
PilotoEscuderíaSiglas
+ + + + + + + + + + + + -
#NombreApellidoEquipoNacionalidadCódigo
+
diff --git a/js/f1.js b/js/f1.js index d3e4b35..0d6038c 100644 --- a/js/f1.js +++ b/js/f1.js @@ -1,17 +1,21 @@ - // =============================== // FUNCIONES DE CONSULTA API -// https://ergast.com/mrd/overview/f1/ // =============================== +// Obtener calendario completo de la temporada actual async function obtenerCalendario() { - // Cargar la programación completa de la actual temporada - const response = await fetch("https://api.jolpi.ca/ergast/f1/current.json"); - const data = await response.json(); - const carreras = data.MRData.RaceTable.Races; - return carreras; + try { + const response = await fetch("https://api.jolpi.ca/ergast/f1/current.json"); + const data = await response.json(); + const carreras = data.MRData.RaceTable.Races; + return carreras; + } catch (error) { + console.error("Error al obtener calendario:", error); + return []; + } } +// Encontrar la siguiente carrera function encontrarSiguienteCarrera(carreras) { const ahora = new Date(); for (let carrera of carreras) { @@ -50,6 +54,36 @@ function iniciarCuentaAtras(fechaCarrera) { setInterval(actualizar, 1000); } +// =============================== +// PILOTOS +// =============================== +async function cargarPilotos() { + try { + const response = await fetch('/f1/api/pilotos'); + const pilotos = await response.json(); + const tbody = document.querySelector('#pilotos-table tbody'); + + tbody.innerHTML = ''; // Limpiamos antes de rellenar + + pilotos.forEach(p => { + const fila = document.createElement('tr'); + fila.innerHTML = ` + ${p.numero} + ${p.nombre} + ${p.apellido} + ${p.equipo || '-'} + ${p.nacionalidad} + ${p.codigo} + `; + tbody.appendChild(fila); + }); + } catch (error) { + console.error('Error cargando pilotos:', error); + const tbody = document.querySelector('#pilotos-table tbody'); + tbody.innerHTML = `No se pudieron cargar los pilotos`; + } +} + // =============================== // INIT PRINCIPAL // =============================== @@ -66,26 +100,27 @@ async function init() { return; } - // Mostramos el nombre de la próxima carrera + // 3) Mostrar nombre de la próxima carrera document.querySelector(".cuenta-atras h3").textContent = `Cuenta atrás para el GP de ${proxima.raceName}`; - // 3) Poner la cuenta atrás + // 4) Iniciar cuenta atrás iniciarCuentaAtras(proxima.fecha); - // 4) Si estamos en fin de semana de carrera o justo comienza + // 5) Indicar modo carrera o pronóstico const ahora = new Date(); if (ahora >= proxima.fecha) { - // Aquí puedes pedir sesiones o tiempos reales si la API lo soporta - console.log("Estamos en modo carrera"); document.getElementById("session-info").textContent = "Modo carrera — datos en vivo o resultados"; } else { - // Modo pronóstico/previo - console.log("Estamos antes del fin de semana de carrera"); document.getElementById("session-info").textContent = `Próxima sesión de ${proxima.raceName}`; } + + // 6) Cargar pilotos al inicio y cada minuto + cargarPilotos(); + setInterval(cargarPilotos, 60000); // refresco cada 60 segundos } +// Arrancar todo al cargar la página document.addEventListener("DOMContentLoaded", init); \ No newline at end of file diff --git a/pilotos.html b/pilotos.html index 9e81339..dec6c90 100644 --- a/pilotos.html +++ b/pilotos.html @@ -41,49 +41,7 @@

Pilotos de F1

- - - - - - - - - - - - - - -
#NombreApellidoEquipoNacionalidadCódigo
+ - \ No newline at end of file