-
Notifications
You must be signed in to change notification settings - Fork 0
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
[4주차] 기본과제 :🌈 예손의 날씨예보 🌈 #7
base: main
Are you sure you want to change the base?
Conversation
import React from "react"; | ||
import styled from "styled-components"; | ||
import { useState } from "react"; |
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.
별건아닌데 요거 import React, {useState} from "react"; 로 한번에 쓰면 더 깔꼼하겠다잉!!
<St.ComboBox> | ||
<select onChange={handleSelect}> | ||
<option value="day">오늘</option> | ||
<option value="week">주간</option> | ||
</select> | ||
</St.ComboBox> |
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.
요기둥! 바로
<St.ComboBox onChange={handleSelect}>
<option value="day">오늘</option>
<option value="week">주간</option>
</St.ComboBox>
ComboBox: styled.select`
& > select {
${({ theme }) => theme.fonts.Content};
color: ${({ theme }) => theme.colors.Blue};
border: 0.2rem solid ${({ theme }) => theme.colors.Blue};
border-radius: 0.5rem;
padding: 0.5rem;
:hover {
background-color: ${({ theme }) => theme.colors.Blue};
color: ${({ theme }) => theme.colors.White};
}
}
`,
로 해도 좋을 것 같앙~~~
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.
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.
같은 과제지만 3명 다 조금씩 다른 방식으로 구조를 짜서 코드 읽으면서 배우는게 많네...! props 전달하는게 귀찮다면 하위 컴포넌트가 적을때는 예현이처럼 그냥 각각 하위 컴포넌트에서 api 받아오는게 좋은거 같다! 아주 깔끔해지는거 같아. 고생했어 예현이!!!
useEffect(() => { | ||
axios | ||
.get( | ||
`https://api.openweathermap.org/data/2.5/weather?q=${area}&appid=${ | ||
import.meta.env.VITE_APP_WEATHER | ||
}&units=metric` | ||
) | ||
.then((response) => { | ||
console.log(response.data); | ||
setWeather(response.data); | ||
}) | ||
.catch((error) => { | ||
console.log(error); | ||
}); | ||
}, [area]); |
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.
오호 그냥 각각 오늘, 주간 날씨 컴포넌트 안에서 api를 받아왔구나! 명지하고는 또 다르네
}); | ||
}, [area]); | ||
|
||
const weatherList = weather.filter((_, index) => (index - 2) % 8 === 0); |
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.
또 다른 방식의 필터링이다,,,!
✨ 구현 기능 명세
✅
기상 카드
✅
일간 / 주간 + 지역(영어)검색
✅
Outlet + Route
✔🌼 PR Point
const imgURL = WEATHER_TYPE.filter( (item) => item.description === weather.weather?.[0].description )[0]?.imgURL || WEATHER_TYPE[0].imgURL;
{weatherList.map((item, index) => { const imgURL = WEATHER_TYPE.filter( (type) => type.description === item.weather?.[0].description )[0]?.imgURL || WEATHER_TYPE[0].imgURL;
const weatherList = weather.filter((_, index) => (index - 2) % 8 === 0);
우선 저는 날씨 데이터가 24시간 기준 3시간마다 업데이트되기 때문에, 결국 하루에 총 8번씩 날씨 정보가 업데이트 되므로, 8로 나누어 떨어지는 인덱스들만 추려냄으로써 총 다섯 개의 날씨 정보만 가져올 수 있도록 했습니닷...
🥺 소요 시간, 어려웠던 점
20h +(?)
그리고 주간 옵션에서 40개 날씨 배열을 요일별로 하나씩 총 5개로 자르기까지 생각하는 게 좀 어려웠던 것 같습니다!
다른 분들은 어떻게 해결하셨는지 궁금하네용
🌈 구현 결과물
week4.1.mp4