diff --git a/src/components/CurrentWeather.js b/src/components/CurrentWeather.js index ce926d9..126c6b3 100644 --- a/src/components/CurrentWeather.js +++ b/src/components/CurrentWeather.js @@ -7,11 +7,20 @@ import { import { getWeatherDescription } from "../utils/weather"; const CurrentWeather = ({ weatherData, isLoading }) => { - if (isLoading) { - return
채워주세요
; + if (isLoading || !weatherData) { + return
날씨 정보를 불러오는 중입니다...
; } - return
채워주세요
; + const currentTemp = weatherData.hourly.temperature_2m[0]; + const currentCode = weatherData.hourly.weather_code[0]; + const description = getWeatherDescription(currentCode); + + return ( + + {currentTemp}°C + {description} + + ); }; -export default CurrentWeather; +export default CurrentWeather; \ No newline at end of file diff --git a/src/components/DailyForecast.js b/src/components/DailyForecast.js index 7300228..aa0eeb5 100644 --- a/src/components/DailyForecast.js +++ b/src/components/DailyForecast.js @@ -5,7 +5,17 @@ import { getWeatherDescription, formatDailyData } from "../utils/weather"; const DailyForecast = ({ weatherData }) => { const dailyData = formatDailyData(weatherData); - return
채워주세요
; + return ( + + {dailyData.map((day, index) => ( + +
{day.date}
+
{getWeatherDescription(day.code)}
+
{day.temp}°C
+
+ ))} +
+ ); }; -export default DailyForecast; +export default DailyForecast; \ No newline at end of file diff --git a/src/components/HourlyForecast.js b/src/components/HourlyForecast.js index 67c3645..5d6c5dd 100644 --- a/src/components/HourlyForecast.js +++ b/src/components/HourlyForecast.js @@ -5,7 +5,17 @@ import { getWeatherDescription, formatHourlyData } from "../utils/weather"; const HourlyForecast = ({ weatherData }) => { const hourlyData = formatHourlyData(weatherData); - return
채워주세요
; + return ( + + {hourlyData.map((hour, index) => ( + +
{hour.time}
+
{getWeatherDescription(hour.code)}
+
{hour.temp}°C
+
+ ))} +
+ ); }; -export default HourlyForecast; +export default HourlyForecast; \ No newline at end of file diff --git a/src/utils/weather.js b/src/utils/weather.js index e357680..f734649 100644 --- a/src/utils/weather.js +++ b/src/utils/weather.js @@ -21,12 +21,44 @@ export const getWeatherDescription = (code) => { export const formatHourlyData = (weatherData) => { if (!weatherData) return []; - // 밑에 코드 채워주세요 - return []; + + const times = weatherData.hourly.time; + const temps = weatherData.hourly.temperature_2m; + const codes = weatherData.hourly.weather_code; + + const now = new Date(); + const currentHour = now.getHours(); + + const result = []; + for (let i = 0; i < times.length; i++) { + const hour = new Date(times[i]).getHours(); + if (hour >= currentHour && result.length < 12) { + result.push({ + time: `${hour}시`, + temp: temps[i], + code: codes[i], + }); + } + if (result.length >= 12) break; + } + + return result; }; export const formatDailyData = (weatherData) => { if (!weatherData) return []; - // 밑에 코드 채워주세요 - return []; -}; + + const dates = weatherData.daily.time; + const temps = weatherData.daily.temperature_2m_max; + const codes = weatherData.daily.weather_code; + + return dates.map((dateStr, index) => { + const date = new Date(dateStr); + const weekday = date.toLocaleDateString("ko-KR", { weekday: "long" }); + return { + date: weekday, + temp: temps[index], + code: codes[index], + }; + }); +}; \ No newline at end of file