diff --git a/src/components/BentoSpotify.tsx b/src/components/BentoSpotify.tsx index c853915..6aaac29 100644 --- a/src/components/BentoSpotify.tsx +++ b/src/components/BentoSpotify.tsx @@ -53,7 +53,7 @@ export default function BentoSpotify() { {/* Album Art & Info Skeleton */} -
+
diff --git a/src/components/BentoWeather.tsx b/src/components/BentoWeather.tsx new file mode 100644 index 0000000..eea88a1 --- /dev/null +++ b/src/components/BentoWeather.tsx @@ -0,0 +1,235 @@ +import { useEffect, useState } from "react"; +import { Skeleton } from "./ui/skeleton"; +import { Cloud, Sun, CloudRain, CloudSnow, MoveUpRight } from "lucide-react"; + +export default function BentoWeather() { + const [weatherData, setWeatherData] = useState(null); + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + const fetchWeather = async () => { + try { + const res = await fetch("https://wttr.in/Malaga?format=j2"); + const data = await res.json(); + setWeatherData(data); + setIsLoading(false); + } catch (error) { + console.error('Error fetching weather:', error); + setIsLoading(false); + } + }; + fetchWeather(); + }, []); + + const getWeatherIcon = (description: string) => { + const desc = description.toLowerCase(); + if (desc.includes('rain') || desc.includes('drizzle')) return CloudRain; + if (desc.includes('snow')) return CloudSnow; + if (desc.includes('cloud') || desc.includes('overcast')) return Cloud; + return Sun; + }; + + if (isLoading) { + return ( +
+ {/* Background Pattern */} +
+
+
+ + {/* Weather Icon */} +
+ +
+ +
+ {/* Header Skeleton */} +
+ + +
+ + {/* Weather Info Skeleton */} +
+ + +
+ + + +
+
+ + {/* Footer Skeleton */} +
+ + +
+
+
+ ); + } + + if (!weatherData) return

Something absolutely horrible has gone wrong

; + + const current = weatherData.current_condition[0]; + const location = weatherData.nearest_area[0]; + const WeatherIcon = getWeatherIcon(current.weatherDesc[0].value); + + return ( +
+ {/* Background Pattern */} +
+
+
+ + {/* Weather Icon */} +
+ +
+ +
+ {/* Header */} +
+
+ + CURRENT WEATHER + +
+ + {/* Weather Info */} +
+
+
+ +
+
+ +
+

+ {current.temp_C}°C +

+

+ {current.weatherDesc[0].value} +

+

+ {location.areaName[0].value}, {location.country[0].value} +

+
+
+ + {/* Footer */} +
+
+
+
+
+
+ + + + +
+
+
+ ); +} + +// Types generated with AI. +interface WttrResponse { + current_condition: { + FeelsLikeC: string; + FeelsLikeF: string; + cloudcover: string; + humidity: string; + localObsDateTime: string; + observation_time: string; + precipInches: string; + precipMM: string; + pressure: string; + pressureInches: string; + temp_C: string; + temp_F: string; + uvIndex: string; + visibility: string; + visibilityMiles: string; + weatherCode: string; + weatherDesc: Array<{ value: string }>; + weatherIconUrl: Array<{ value: string }>; + winddir16Point: string; + winddirDegree: string; + windspeedKmph: string; + windspeedMiles: string; + }[]; + nearest_area: Array<{ + areaName: Array<{ value: string }>; + country: Array<{ value: string }>; + latitude: string; + longitude: string; + population: string; + region: Array<{ value: string }>; + weatherUrl: Array<{ value: string }>; + }>; + request: Array<{ + query: string; + type: string; + }>; + weather: Array<{ + astronomy: Array<{ + moon_illumination: string; + moon_phase: string; + moonrise: string; + moonset: string; + sunrise: string; + sunset: string; + }>; + avgtempC: string; + avgtempF: string; + date: string; + hourly: Array<{ + DewPointC: string; + DewPointF: string; + FeelsLikeC: string; + FeelsLikeF: string; + HeatIndexC: string; + HeatIndexF: string; + WindChillC: string; + WindChillF: string; + WindGustKmph: string; + WindGustMiles: string; + cloudcover: string; + humidity: string; + precipInches: string; + precipMM: string; + pressure: string; + pressureInches: string; + tempC: string; + tempF: string; + time: string; + uvIndex: string; + visibility: string; + visibilityMiles: string; + weatherCode: string; + weatherDesc: Array<{ value: string }>; + weatherIconUrl: Array<{ value: string }>; + winddir16Point: string; + winddirDegree: string; + windspeedKmph: string; + windspeedMiles: string; + }>; + maxtempC: string; + maxtempF: string; + mintempC: string; + mintempF: string; + sunHour: string; + totalSnow_cm: string; + uvIndex: string; + }>; +} \ No newline at end of file diff --git a/src/pages/index.astro b/src/pages/index.astro index e531496..182d49f 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,5 +1,6 @@ --- import BentoSpotify from '@/components/BentoSpotify' +import BentoWeather from '@/components/BentoWeather' import Link from '@/components/Link.astro' import PageHead from '@/components/PageHead.astro' import { Badge } from '@/components/ui/badge' @@ -102,11 +103,13 @@ const allPosts = await getRecentPosts(2)
- -
discord
+ +
+ +
- -
wakatime
+ +
Discord