import React from "react"; import sunriseIcon from "../assets/icons/sunrise-fill.svg"; import sunsetIcon from "../assets/icons/sunset-fill.svg"; const WeatherData: React.FC = () => { const weatherRaw = localStorage.getItem("weather"); const weatherData = JSON.parse(weatherRaw || "{}"); // OpenWeatherMap Icon-URL const iconCode = weatherData?.weather?.[0]?.icon; const iconUrl = iconCode ? `https://openweathermap.org/img/wn/${iconCode}@4x.png` : ""; return (

{weatherData?.name}

{weatherData?.main?.temp}{" "} {localStorage.getItem("unit") === "metric" ? "°C" : localStorage.getItem("unit") === "imperial" ? "°F" : localStorage.getItem("unit") === "standard" ? "K" : "°C"}

{weatherData?.sys?.country && ( <> {weatherData.sys.country} {weatherData.sys.country} )}

{weatherData?.weather?.[0]?.description}

{iconUrl && ( {weatherData?.weather?.[0]?.description} )}
Sunrise Icon Sunrise:{" "} {weatherData?.sys?.sunrise ? new Date(weatherData.sys.sunrise * 1000).toLocaleTimeString( "de-DE", { hour: "2-digit", minute: "2-digit" } ) : "--:--"}
Sunset Icon Sunset:{" "} {weatherData?.sys?.sunset ? new Date(weatherData.sys.sunset * 1000).toLocaleTimeString( "de-DE", { hour: "2-digit", minute: "2-digit" } ) : "--:--"}
); }; export default WeatherData;