Skip to content
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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

yesongoget
Copy link
Contributor

✨ 구현 기능 명세

  • 기본 과제

✅ 기상 카드

  1. 날씨에 따른 이미지 ✔
  2. 온도 ✔
  3. 체감온도 ✔
  4. 최저,최고 ✔
  5. 구름 % ✔

✅ 일간 / 주간 + 지역(영어)검색

  1. 날씨 검색 타입 ✔
    1. 오늘 → 하루
    2. 주간 → 5일 예보
  2. 검색 기능 ✔
    1. /day/:area or /week/:area 와 같이 params로 검색한 지역을 넘겨줍니다. :: hint) useParams
    2. 이를 가져와 오늘/ 주간 날씨를 렌더링

✅ Outlet + Route

  1. Outlet과 Route를 활용하여 페이지 내의 컴포넌트를 변경해주세요!
    1. 헤더는 고정
    2. 기상 정보 카드들만 경로에 따라 변경됩니다.
  2. 에러페이지 처리도 필수!

🌼 PR Point

filter 메소드를 사용해서 weather 객체의 weather 배열에서 첫번째 요소의 description과 WEATHER_TYPE 배열의 description 속성값과 비교하여 그에 해당하는 이미지 URL을 가져오도록 했습니다!
또한 weather 객체의 weather 배열이 존재하지 않거나 일치하는 속성값이 없는 경우에는 WEATHER_TYPE 배열의 첫번째 객체의 imgURL 값을 가져오도록 해줬어요!

const imgURL = WEATHER_TYPE.filter( (item) => item.description === weather.weather?.[0].description )[0]?.imgURL || WEATHER_TYPE[0].imgURL;

주간 컴포넌트에서는 imgURL을 weatherList 맵 함수 안에서 매번 계산함으로써 각 카드에 대해 적절한 이미지가 렌더링되도록 해줬습니다!

{weatherList.map((item, index) => { const imgURL = WEATHER_TYPE.filter( (type) => type.description === item.weather?.[0].description )[0]?.imgURL || WEATHER_TYPE[0].imgURL;

주간 컴포넌트에서 기존 40개의 날씨 배열을 각 요일에 하나씩 렌더링되도록 하는 부분이 좀 어려웠는데...
다른 분들은 어떻게 했는지 궁금해요!

const weatherList = weather.filter((_, index) => (index - 2) % 8 === 0);
우선 저는 날씨 데이터가 24시간 기준 3시간마다 업데이트되기 때문에, 결국 하루에 총 8번씩 날씨 정보가 업데이트 되므로, 8로 나누어 떨어지는 인덱스들만 추려냄으로써 총 다섯 개의 날씨 정보만 가져올 수 있도록 했습니닷...

🥺 소요 시간, 어려웠던 점

  • 20h +(?)
  • API 연결을 처음해보다보니까.... 연결하는 부분에서 많이 헤맸던 것 같아요,.!
    그리고 주간 옵션에서 40개 날씨 배열을 요일별로 하나씩 총 5개로 자르기까지 생각하는 게 좀 어려웠던 것 같습니다!
    다른 분들은 어떻게 해결하셨는지 궁금하네용

🌈 구현 결과물

week4.1.mp4

Comment on lines +1 to +3
import React from "react";
import styled from "styled-components";
import { useState } from "react";
Copy link

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"; 로 한번에 쓰면 더 깔꼼하겠다잉!!

Comment on lines +27 to +32
<St.ComboBox>
<select onChange={handleSelect}>
<option value="day">오늘</option>
<option value="week">주간</option>
</select>
</St.ComboBox>
Copy link

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};
      }
    }
  `,

로 해도 좋을 것 같앙~~~

Copy link

@Dangpy Dangpy left a comment

Choose a reason for hiding this comment

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

왕!! 진짜 코드 깔끔하게 잘했돠!!! 굿이에오!! 굿!!!
image

Copy link

@eastlaw80 eastlaw80 left a comment

Choose a reason for hiding this comment

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

같은 과제지만 3명 다 조금씩 다른 방식으로 구조를 짜서 코드 읽으면서 배우는게 많네...! props 전달하는게 귀찮다면 하위 컴포넌트가 적을때는 예현이처럼 그냥 각각 하위 컴포넌트에서 api 받아오는게 좋은거 같다! 아주 깔끔해지는거 같아. 고생했어 예현이!!!

Comment on lines +16 to +30
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]);
Copy link

@eastlaw80 eastlaw80 Jun 2, 2023

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);

Choose a reason for hiding this comment

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

또 다른 방식의 필터링이다,,,!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants