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
16 changes: 12 additions & 4 deletions src/components/CurrentWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import {
Temperature,
WeatherCode,
} from "./styles/StyledComponents";
import { getWeatherDescription } from "../utils/weather";
import { getWeatherDescription, formatHourlyData } from "../utils/weather";

const CurrentWeather = ({ weatherData, isLoading }) => {
if (isLoading) {
return <div>채워주세요</div>;
return <div>Loading...</div>;
}

return <div>채워주세요</div>;
const hourlyData = formatHourlyData(weatherData);
const current = hourlyData[0];

return (
<CurrentWeatherWrapper>
<Temperature>{current.temperature ? `${Math.round(current.temperature)}°C` : "N/A"}</Temperature>
<WeatherCode>{current.weather}</WeatherCode>
</CurrentWeatherWrapper>
);
};

export default CurrentWeather;
export default CurrentWeather;
13 changes: 12 additions & 1 deletion src/components/DailyForecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,18 @@ 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}>
<span>{day.date}</span>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

여기서는 span 태그를 쓰시고

<span>{day.weather}</span>
<span>{Math.round(day.temperature)}°C</span>
</DailyItem>
))}
</DailyForecastWrapper>
);

};

export default DailyForecast;
12 changes: 11 additions & 1 deletion 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((item, index) => (
<HourlyItem key={index}>
<p>{item.time}</p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

여기서는 p태그를 쓰셨는데 다르게 하신 이유가 따로 있나요??
없다면 태그의 특성을 고려해서 더 적합한 걸로 써주는게 좋을 것 같아요!
https://inpa.tistory.com/entry/HTML-%F0%9F%93%9A-p-div-span-%ED%83%9C%EA%B7%B8-%EC%A0%95%EB%A6%AC
⬆️ 해당 사이트 참고하면 좋을 것 같습니다!

<p>{item.temperature}°C</p>
<p>{item.weather}</p>
</HourlyItem>
))}
</HourlyForecastWrapper>
);
};

export default HourlyForecast;
34 changes: 32 additions & 2 deletions src/utils/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,41 @@ export const getWeatherDescription = (code) => {
export const formatHourlyData = (weatherData) => {
if (!weatherData) return [];
// 밑에 코드 채워주세요
return [];
const { time, temperature_2m, weather_code } = weatherData.hourly;

/*
- `latitude`, `longitude`: 서울 좌표 (37.566°N, 126.9784°E)
- `hourly`: 시간별 날씨 데이터 포함:
- `temperature_2m`: 섭씨 온도
- `weather_code`: 날씨 상태 코드
- `daily`: 일별 날씨 데이터 포함:
- `weather_code`: 일별 날씨 상태 코드
- `temperature_2m_max`: 일 최고 기온
- `timezone`: Asia/Tokyo
- `forecast_days`: 7일 예보
*/

return time.slice(0, 12).map((t, i) => ({
time: new Date(t).toLocaleTimeString("ko-KR", { hour: "2-digit" , hour12: true }),
temperature: temperature_2m[i], // 온도
weather: getWeatherDescription(weather_code[i]), // 날씨 설명
}));

};

export const formatDailyData = (weatherData) => {
if (!weatherData) return [];
// 밑에 코드 채워주세요
return [];

const { time, temperature_2m_max, weather_code } = weatherData.daily;

return time.slice(0, 7).map((t, i) => ({
date: new Date(t).toLocaleDateString("ko-KR", {
month: "long",
day: "numeric",
weekday: "short",
}),
weather: getWeatherDescription(weather_code[i]),
temperature: temperature_2m_max[i],
}));
};