-
Notifications
You must be signed in to change notification settings - Fork 24
7강 정연준 과제제출 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
7강 정연준 과제제출 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,23 @@ import { getWeatherDescription, formatDailyData } from "../utils/weather"; | |
|
|
||
| const DailyForecast = ({ weatherData }) => { | ||
| const dailyData = formatDailyData(weatherData); | ||
| const days = ["월", "화", "수", "목", "금", "토", "일"]; | ||
|
|
||
| return <div>채워주세요</div>; | ||
| return ( | ||
| <DailyForecastWrapper> | ||
| {dailyData.map((data, idx) => ( | ||
| <DailyItem key={idx}> | ||
| <div> | ||
| {`${new Date(data.time).getMonth() + 1}월 ${new Date( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 날짜 및 요일과 같은 데이터 포맷 가공 로직은 관심사의 분리를 위해 weather.js의 formatDailyData에서 하는 것이 유지보수에 더 유리할 것 같아요 |
||
| data.time | ||
| ).getDate()}일 (${days[new Date(data.time).getDay()]})`} | ||
| </div> | ||
| <div>{getWeatherDescription(data.weatherCode)}</div> | ||
| <div>{Math.floor(data.temperature)}°C</div> | ||
| </DailyItem> | ||
| ))} | ||
| </DailyForecastWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default DailyForecast; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,19 @@ import { getWeatherDescription, formatHourlyData } from "../utils/weather"; | |
| const HourlyForecast = ({ weatherData }) => { | ||
| const hourlyData = formatHourlyData(weatherData); | ||
|
|
||
| return <div>채워주세요</div>; | ||
| return ( | ||
| <HourlyForecastWrapper> | ||
| {hourlyData.map((data, idx) => ( | ||
| <HourlyItem key={idx}> | ||
| <div> | ||
| {new Date(data.time).getHours().toString().padStart(2, "0")}시 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 날짜 및 요일과 같은 데이터 포맷 가공 로직은 관심사의 분리를 위해 weather.js의 formatHourlyData에서 하는 것이 유지보수에 더 유리할 것 같아요 |
||
| </div> | ||
| <div>{Math.floor(data.temperature)}°C</div> | ||
| {getWeatherDescription(data.weatherCode)} | ||
| </HourlyItem> | ||
| ))} | ||
| </HourlyForecastWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default HourlyForecast; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,63 @@ | ||
| export const getWeatherDescription = (code) => { | ||
| const weatherCodes = { | ||
| 0: "맑음", | ||
| 1: "대체로 맑음", | ||
| 2: "부분적으로 흐림", | ||
| 3: "흐림", | ||
| 45: "안개", | ||
| 48: "짙은 안개", | ||
| 51: "약한 이슬비", | ||
| 53: "보통 이슬비", | ||
| 55: "강한 이슬비", | ||
| 61: "약한 비", | ||
| 63: "보통 비", | ||
| 65: "강한 비", | ||
| 71: "약한 눈", | ||
| 73: "보통 눈", | ||
| 75: "강한 눈", | ||
| 0: "맑음 ☀️", | ||
| 1: "대체로 맑음 🌤️", | ||
| 2: "부분적으로 흐림 ⛅", | ||
| 3: "흐림 ☁️", | ||
| 45: "안개 🌫️", | ||
| 48: "짙은 안개 🌫️", | ||
| 51: "약한 이슬비 🌦️", | ||
| 53: "보통 이슬비 🌦️", | ||
| 55: "강한 이슬비 🌦️", | ||
| 61: "약한 비 🌧️", | ||
| 63: "보통 비 🌧️", | ||
| 65: "강한 비 🌧️", | ||
| 71: "약한 눈 🌨️", | ||
| 73: "보통 눈 🌨️", | ||
| 75: "강한 눈 🌨️", | ||
| 77: "싸락눈 🌨️", | ||
| 80: "약한 소나기 🌦️", | ||
| 81: "보통 소나기 🌦️", | ||
| 82: "강한 소나기 🌦️", | ||
| 85: "약한 눈 소나기 🌨️", | ||
| 86: "강한 눈 소나기 🌨️", | ||
| 95: "천둥번개 ⛈️", | ||
| 96: "우박 동반 천둥번개 ⛈️", | ||
| 99: "강한 우박 천둥번개 ⛈️", | ||
| }; | ||
| return weatherCodes[code] || "알 수 없음"; | ||
| }; | ||
|
|
||
| export const formatHourlyData = (weatherData) => { | ||
| if (!weatherData) return []; | ||
| // 밑에 코드 채워주세요 | ||
| return []; | ||
| const time = weatherData.hourly.time; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구조분해할당을 활용하면 가독성이 좋아질 것 같아요 |
||
| const temperature2m = weatherData.hourly.temperature_2m; | ||
| const weatherCode = weatherData.hourly.weather_code; | ||
| const hourlyData = []; | ||
| for (let i = 0; i < 12; i++) { | ||
| hourlyData.push({ | ||
| time: time[i].toString(), | ||
| temperature: temperature2m[i], | ||
| weatherCode: weatherCode[i], | ||
| }); | ||
| } | ||
| return hourlyData; | ||
| }; | ||
|
|
||
| export const formatDailyData = (weatherData) => { | ||
| if (!weatherData) return []; | ||
| // 밑에 코드 채워주세요 | ||
| return []; | ||
| const time = weatherData.daily.time; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 구조분해할당 활용해보는 게 어떨까요? |
||
| const temperature2mMax = weatherData.daily.temperature_2m_max; | ||
| const weatherCode = weatherData.daily.weather_code; | ||
| const dailyData = []; | ||
| for (let i = 0; i < 7; i++) { | ||
| dailyData.push({ | ||
| time: time[i].toString(), | ||
| temperature: temperature2mMax[i], | ||
| weatherCode: weatherCode[i], | ||
| }); | ||
| } | ||
|
|
||
| return dailyData; | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스켈레톤 컴포넌트 공부해서 적용해보면 좋을 것 같습니다