Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/components/CurrentWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ import {
import { getWeatherDescription } from "../utils/weather";

const CurrentWeather = ({ weatherData, isLoading }) => {
if (isLoading) {
return <div>채워주세요</div>;
if (isLoading || !weatherData) {
return <div>날씨 정보를 불러오는 중입니다...</div>;
}

return <div>채워주세요</div>;
const currentTemp = weatherData.hourly.temperature_2m[0];
const currentCode = weatherData.hourly.weather_code[0];
const description = getWeatherDescription(currentCode);

return (
<CurrentWeatherWrapper>
<Temperature>{currentTemp}°C</Temperature>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

온도 소수점까지 반환하던데 날씨 앱에서 보통 소수점까진 출력 안하니 반올림해도 괜찮을 것 같습미당

<WeatherCode>{description}</WeatherCode>
</CurrentWeatherWrapper>
);
};

export default CurrentWeather;
export default CurrentWeather;
14 changes: 12 additions & 2 deletions src/components/DailyForecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import { getWeatherDescription, formatDailyData } from "../utils/weather";
const DailyForecast = ({ weatherData }) => {
const dailyData = formatDailyData(weatherData);

return <div>채워주세요</div>;
return (
<DailyForecastWrapper>
{dailyData.map((day, index) => (
<DailyItem key={index}>
<div>{day.date}</div>
<div>{getWeatherDescription(day.code)}</div>
<div>{day.temp}°C</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도!

</DailyItem>
))}
</DailyForecastWrapper>
);
};

export default DailyForecast;
export default DailyForecast;
14 changes: 12 additions & 2 deletions src/components/HourlyForecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ import { getWeatherDescription, formatHourlyData } from "../utils/weather";
const HourlyForecast = ({ weatherData }) => {
const hourlyData = formatHourlyData(weatherData);

return <div>채워주세요</div>;
return (
<HourlyForecastWrapper>
{hourlyData.map((hour, index) => (
<HourlyItem key={index}>
<div>{hour.time}</div>
<div>{getWeatherDescription(hour.code)}</div>
<div>{hour.temp}°C</div>
</HourlyItem>
))}
</HourlyForecastWrapper>
);
};

export default HourlyForecast;
export default HourlyForecast;
42 changes: 37 additions & 5 deletions src/utils/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Comment on lines +33 to 46
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (let i = 0; i < times.length && result.length < 12; i++) {
  const hour = new Date(times[i]).getHours();
  if (hour >= currentHour) {
    result.push({
      time: `${hour}시`,
      temp: temps[i],
      code: codes[i],
    });
  }
}

반복문 조건에 추가하면 어떨까요?


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],
};
});
};