Conversation
greetings1012
left a comment
There was a problem hiding this comment.
수고하셨습니다! 코드를 잘 작성해주셔서 이전보다 리뷰 달 내용이 많지 않네요!
몇 개 생각할 거리를 적어 놨으니, 확인 후 Reply 부탁드립니다!
|
|
||
| if (isLoading) { | ||
| return <div>채워주세요</div>; | ||
| return <div>{LOADING}</div>; |
There was a problem hiding this comment.
Loading 대신 스피너나 간단한 스켈레톤 UI를 추가해보는 것도 좋을 것 같아요!
https://blog.makerjun.com/2f7a9818-df45-4eab-9768-b79d61b4d0ec
There was a problem hiding this comment.
import { SpinnerWrapper } from "./styles/StyledComponents";
import { ClockLoader } from "react-spinners";
const Spinner = () => {
return (
<SpinnerWrapper>
<ClockLoader color="white" size={150} />
</SpinnerWrapper>
);
};
export default Spinner;
찾아보니 스피너 라이브러리가 있어서 사용해보았습니다!
| @@ -0,0 +1,23 @@ | |||
| export const isToDay = (dateInData, currentDate) => { | |||
There was a problem hiding this comment.
| export const isToDay = (dateInData, currentDate) => { | |
| export const isToday = (dateInData, currentDate) => { |
| import { getWeekdayName } from "./weeks"; | ||
|
|
||
| export const getWeatherDescription = (code) => { | ||
| const weatherCodes = { |
There was a problem hiding this comment.
constants로 분리 후, 아래와 같이 변경했습니다!
// weather.js
export const getWeatherDescription = (code) => {
return WEATHER_CODE[code] || "알 수 없음";
};
| }; | ||
|
|
||
| export const formatCurrentData = (weatherData) => { | ||
| if (!weatherData) return; |
There was a problem hiding this comment.
만약 문제가 발생해서 return했다면 console에 log라도 찍어주면 개발할 때 빠르게 어느 부분에서 문제가 생겼는지 확인할 수 있을 것 같아요!
There was a problem hiding this comment.
// logger.js
export const errorLog = (component, message) => {
console.log(`[${component}] ${message}`);
};
// weather.js
export const formatCurrentData = (weatherData) => {
if (!weatherData) {
errorLog(formatCurrentData.name, FAILED_LOAD_DATA);
return;
}
}
다음과 같이 작성했습니다!
There was a problem hiding this comment.
전체적으로 안에 포매팅 기능을 하는 부분들이 많은데, 이를 별도의 util 함수로 분리하면 좋겠습니다!
There was a problem hiding this comment.
// weather.js -> fetchWeatherData.js
export const fetchCurrentData = (weatherData) => {
if (!weatherData) {
errorLog(fetchCurrentData.name, FAILED_LOAD_DATA);
return;
}
const index = weatherData.hourly.time.findIndex((time) => isInCurrentTime(new Date(time)));
return {
time: new Date(weatherData.hourly.time[index]),
temperature: weatherData.hourly.temperature_2m[index],
weatherCode: weatherData.hourly.weather_code[index],
};
};
fetch로 시작하는 함수들로 변경하여 최대한 데이터 원본 형태로 불러오도록 수정했습니다.
| if ( | ||
| isToDay(hourlyDate, currentDate) && | ||
| isWithin12Hours(hourlyDate, currentDate) && | ||
| result.length < 12 |
There was a problem hiding this comment.
이것도 validate 로직이니까 따로 분리하면 좋을 것 같네요!
There was a problem hiding this comment.
// validators.js
export const isValidHourlyData = (hourlyDate, currentDate, collectedForecasts) => {
return (
isToday(hourlyDate, currentDate) &&
isWithin12Hours(hourlyDate, currentDate) &&
collectedForecasts.length < 12
);
};
기존에 result였던 배열명도 collectedForecasts로 변경하고 validators 안에 분리했습니다!
| timeString: hourlyDate.toISOString(), | ||
| hour: hourlyDate.getHours(), | ||
| temperature: Math.floor(weatherData.hourly.temperature_2m[index]), | ||
| weatherCode: weatherData.hourly.weather_code[index], |
There was a problem hiding this comment.
// formatWeatherData.js
export const formatHourlyData = (weatherData) => {
if (!weatherData) {
errorLog(formatHourlyData.name, FAILED_LOAD_DATA);
return null;
}
return weatherData.map(({ time, temperature, weatherCode }) => {
const date = new Date(time);
return {
time: date.toISOString(),
hour: date.getHours(),
temperature: Math.floor(temperature),
weatherCode: getWeatherDescription(weatherCode),
};
});
};
- fetchWeatherData.js와 formatWeatherData.js로 분리했습니다~
| timeString: dailyDate.toISOString(), | ||
| date: `${dailyDate.getMonth() + 1}월 ${dailyDate.getDate()}일 (${getWeekdayName( | ||
| dailyDate.getDay() | ||
| )})`, | ||
| temperature: Math.floor(weatherData.daily.temperature_2m_max[index]), | ||
| weatherCode: weatherData.daily.weather_code[index], |
There was a problem hiding this comment.
// formatWeatherData.js
export const formatDailyData = (weatherData) => {
if (!weatherData) {
errorLog(formatDailyData.name, FAILED_LOAD_DATA);
return null;
}
return weatherData.map(({ time, temperature, weatherCode }) => {
const date = new Date(time);
return {
time: date.toISOString(),
date: `${date.getMonth() + 1}월 ${date.getDate()}일 (${getWeekdayDescription(
date.getDay()
)})`,
temperature: Math.floor(temperature),
weatherCode: getWeatherDescription(weatherCode),
};
});
};
- fetchWeatherData.js와 formatWeatherData.js로 분리하여 포매팅했습니다!
greetings1012
left a comment
There was a problem hiding this comment.
수고하셨습니다!
전체적으로 파일 및 기능 분리에 대해 피드백 드렸는데, 잘 해내어 주셨네요!
다음 미션도 화이팅입니다 👍
📍 BackGround
😎 Content
파일 구조
styled-components
함수
📸 Screenshot