-
Notifications
You must be signed in to change notification settings - Fork 19
날씨앱 과제 최종 완성 #17
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?
날씨앱 과제 최종 완성 #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,48 @@ import { | |
| } from "./styles/StyledComponents"; | ||
| import { getWeatherDescription } from "../utils/weather"; | ||
|
|
||
|
|
||
| const getCurrentWeather = (weatherData) => { | ||
| const hourIndex = new Date().getHours(); | ||
| const hourly = weatherData.hourly; | ||
|
|
||
| if ( | ||
| !hourly || | ||
| !hourly.temperature_2m || | ||
| !hourly.temperature_2m[hourIndex] | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| return { | ||
| temperature: hourly.temperature_2m[hourIndex], | ||
| time: hourly.time[hourIndex], | ||
| weatherCode: hourly.weather_code[hourIndex], | ||
| }; | ||
| }; | ||
|
|
||
| const CurrentWeather = ({ weatherData, isLoading }) => { | ||
| if (isLoading) { | ||
| return <div>채워주세요</div>; | ||
| return <div>현재날씨 로딩중...</div>; | ||
| } | ||
|
|
||
| const currentData = getCurrentWeather(weatherData); | ||
|
|
||
| if (!currentData) { | ||
| return <div>현재 시각의 날씨 정보가 없습니다.</div>; | ||
| } | ||
|
|
||
| return <div>채워주세요</div>; | ||
| return ( | ||
| <CurrentWeatherWrapper> | ||
| <h3> | ||
| 현재 위치 : 서울 | ||
| <br /> | ||
| 현재 시각 : {new Date(currentData.time).getHours()}시 | ||
| </h3> | ||
|
Comment on lines
+42
to
+46
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. h3 태그 안에 br 태그를 사용하는 건 시멘틱 구조 상 좋지 않아 보입니다! |
||
| <Temperature>{Math.floor(currentData.temperature)}°C</Temperature> | ||
| <WeatherCode>{getWeatherDescription(currentData.weatherCode)}</WeatherCode> | ||
| </CurrentWeatherWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default CurrentWeather; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,71 @@ | ||
| 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; | ||
| const temperature = weatherData.hourly.temperature_2m; | ||
| const weatherCode = weatherData.hourly.weather_code; | ||
|
|
||
| const hourlyData = []; | ||
|
|
||
| for (let i = 0; i < 12; i++) { | ||
|
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 hour = new Date(time[i]).getHours() + "시"; | ||
|
|
||
| hourlyData.push({ | ||
| time: hour, | ||
| temperature: temperature[i], | ||
| weatherCode: weatherCode[i], | ||
| }); | ||
| } | ||
|
|
||
| return hourlyData; | ||
| }; | ||
|
|
||
| export const formatDailyData = (weatherData) => { | ||
| if (!weatherData) return []; | ||
| // 밑에 코드 채워주세요 | ||
| return []; | ||
| }; | ||
|
|
||
| const time = weatherData.daily.time; | ||
| const temperature = 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], | ||
| temperature: temperature[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.
메시지 하드 코딩 보다는 별도의 컴포넌트 활용해 보시면 좋을 듯 합니당