|
| 1 | +import Image from "next/image"; |
| 2 | +import { FC } from "react"; |
| 3 | + |
| 4 | +enum WeatherIcon { |
| 5 | + ClearSky = "01d", |
| 6 | + FewClouds = "02d", |
| 7 | + ScatteredClouds = "03d", |
| 8 | + BrokenClouds = "04d", |
| 9 | + ShowerRain = "09d", |
| 10 | + Rain = "10d", |
| 11 | + Thunderstorm = "11d", |
| 12 | + Snow = "13d", |
| 13 | + Mist = "50d", |
| 14 | +} |
| 15 | + |
| 16 | +const WeatherIconMap: Record<string, WeatherIcon> = { |
| 17 | + "Clear sky": WeatherIcon.ClearSky, |
| 18 | + "Few clouds": WeatherIcon.FewClouds, |
| 19 | + "Scattered clouds": WeatherIcon.ScatteredClouds, |
| 20 | + "Broken clouds": WeatherIcon.BrokenClouds, |
| 21 | + "Shower rain": WeatherIcon.ShowerRain, |
| 22 | + Rain: WeatherIcon.Rain, |
| 23 | + Thunderstorm: WeatherIcon.Thunderstorm, |
| 24 | + Snow: WeatherIcon.Snow, |
| 25 | + Mist: WeatherIcon.Mist, |
| 26 | +}; |
| 27 | + |
| 28 | +type Weather = { |
| 29 | + city: string; |
| 30 | + temp: number; |
| 31 | + description: string; |
| 32 | +}; |
| 33 | + |
| 34 | +const WeatherPage: FC<Weather> = (weather) => { |
| 35 | + return ( |
| 36 | + <div className="min-h-screen bg-gradient-to-r from-blue-500 via-purple-500 to-indigo-500 flex items-center justify-center"> |
| 37 | + <div className="max-w-5xl w-full grid grid-cols-2 gap-4 p-6"> |
| 38 | + {/* Left Column: City Image with Name */} |
| 39 | + <div className="relative h-96"> |
| 40 | + <Image |
| 41 | + src={`/images/${weather.city.toLowerCase()}.jpg`} |
| 42 | + alt={`Image of ${weather.city}`} |
| 43 | + layout="fill" |
| 44 | + objectFit="cover" |
| 45 | + className="rounded-lg" |
| 46 | + /> |
| 47 | + {/* City Name Overlay */} |
| 48 | + <div className="absolute bottom-0 w-full bg-black bg-opacity-60 text-white py-2 text-center"> |
| 49 | + <h1 className="text-5xl font-bold">{weather.city}</h1> |
| 50 | + </div> |
| 51 | + </div> |
| 52 | + |
| 53 | + {/* Right Column: Weather Information */} |
| 54 | + <div className="flex flex-col justify-center items-center items-start p-6 bg-white bg-opacity-80 rounded-lg shadow-lg"> |
| 55 | + {/* Weather Icon */} |
| 56 | + <Image |
| 57 | + src={`http://openweathermap.org/img/wn/${ |
| 58 | + WeatherIconMap[weather.description] |
| 59 | + }@2x.png`} |
| 60 | + alt={weather.description} |
| 61 | + width={100} |
| 62 | + height={100} |
| 63 | + className="mb-4" |
| 64 | + /> |
| 65 | + |
| 66 | + {/* Temperature */} |
| 67 | + <p className="text-4xl font-bold text-gray-800 mb-2"> |
| 68 | + {weather.temp}°C |
| 69 | + </p> |
| 70 | + |
| 71 | + {/* Weather Description */} |
| 72 | + <p className="text-lg text-gray-600 capitalize"> |
| 73 | + {weather.description} |
| 74 | + </p> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +}; |
| 80 | + |
| 81 | +export default WeatherPage; |
0 commit comments