added rankings but ugly and tired

This commit is contained in:
2025-10-13 16:44:48 +02:00
parent 1139cfd5f0
commit 174e3e94ed
18 changed files with 721 additions and 51 deletions

View File

@@ -0,0 +1,35 @@
// hooks/useWeather.js
import { useState, useEffect } from 'react';
import { locations } from '../config.js';
async function fetchWeather(lat, lon) {
const url = `https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lon}&current_weather=true&temperature_unit=celsius&timezone=Europe/Paris`;
const response = await fetch(url);
const data = await response.json();
return data.current_weather;
}
export function useWeather() {
const [weatherNancy, setWeatherNancy] = useState(null);
const [weatherParis, setWeatherParis] = useState(null);
async function updateWeatherData() {
try {
const [nancy, paris] = await Promise.all([
fetchWeather(locations.Nancy.latitude, locations.Nancy.longitude),
fetchWeather(locations.Paris.latitude, locations.Paris.longitude)
]);
setWeatherNancy(nancy);
setWeatherParis(paris);
} catch (_) { }
}
useEffect(() => {
updateWeatherData();
const interval = setInterval(updateWeatherData, 60000);
return () => clearInterval(interval);
}, []);
return { weatherNancy, weatherParis };
}