-
Notifications
You must be signed in to change notification settings - Fork 6
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
[DEV] 메인 페이지 구현 #12
base: main
Are you sure you want to change the base?
[DEV] 메인 페이지 구현 #12
Conversation
submit 버튼을 누르면 자동으로 리렌더링 되도록 수정
안전성 유지를 위해 useState에 Emotion, Weather type을 명시하도록 수정
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.
tailwind 파일에 btn 스타일 추가해서 활용하는 부분이 인상적입니다! 굿입니다
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.
그동안 무슨 일들이 있으셨던 겁니까..!
처음 이 프로젝트할 때보다 훨씬 많이 성장하신 것 같아요..👍👍
많이 배워갑니다~ 고생하셨어요!
const emotions: Emotion[] = ['bad', 'soso', 'good', 'great', 'awesome'] | ||
const weathers: Weather[] = ['sunny', 'cloud', 'rain', 'snow'] | ||
|
||
export const DIARYKEY = 'diary-storage' |
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.
이런 것은 constants 폴더에 따로 관리해주면 좋을 것 같아요!
} | ||
|
||
const DiaryStorage = () => { | ||
const storedData: Diary[] = JSON.parse(localStorage.getItem(DIARYKEY)!) || [] |
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.
localSotrage를 사용해서 일기를 저장하고 불러오는 것도 좋지만, 구현되어 있는 useContext
hook을 사용해서 전역으로 관리해보는 것도 추천드립니다~
const [contents, setContents] = useState('') | ||
const [selectedEmotion, setSelectedEmotion] = useState<Emotion | undefined>() | ||
const [selectedWeather, setSelectedWeather] = useState<Weather | undefined>() | ||
const [isValid, setValid] = useState(false) |
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.
변수 작명을 정말 깔끔하고 가독성있게 잘 하시는 것 같아요
정말 부럽습니다 ..
setSelectedEmotion(emotion as Emotion) | ||
} | ||
const handleWeatherClick = (weather: string) => { | ||
setSelectedWeather(weather as Weather) |
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.
type관리 너무 좋아요.. 이것까지 챙기다니.. 배워갑니다
diary: Diary | ||
} | ||
|
||
export const DiaryCard: React.FC<DiaryProps> = ({ diary }) => { |
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.
카드만 따로 잘 분리하신 것 같아요 👍👍
} | ||
|
||
return ( | ||
<Link to={`detail/${diary.id}`} key={diary.id}> |
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.
Link
태그에 key값을 두신 이유가 궁금해요
awesome: '😎', | ||
} | ||
return <span>{icons[emotion]}</span> | ||
} |
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.
컴포넌트로도 만들 수가 있군요!
이모티콘들을 상수 폴더에 저장해서 그냥 EmotionIcon[diary.emotion]으로 접근하는 것도 좋을 것 같은 의견입니다!
|
||
.blue-btn { | ||
@apply p-1 rounded-lg text-sm border border-transparent bg-blue-100 text-blue-600 hover:border-blue-600 | ||
} |
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.
문제 풀다가 답지를 본 기분이네요..ㅎㅎ 저도 빠르게 구현 마치고 리팩토링 들어가고 싶습니다! 한 수 배우고 가용~
}, [title, contents, selectedEmotion, selectedWeather]) | ||
|
||
return ( | ||
<form id="write-form" className="flex-col gap-4 p-4 rounded-lg bg-white border border-gray-100 h-2/3"> |
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.
<form>
태그를 쓰는 게 좋겠군요! 참고하겠습니다
|
||
.blue-btn { | ||
@apply p-1 rounded-lg text-sm border border-transparent bg-blue-100 text-blue-600 hover:border-blue-600 | ||
} |
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.
유효성 검사와 유지보수에 초점을 둔 것이 코드에도 느껴지네요!
기능단위로 커밋한 점도 좋은 것 같습니당👍🏻
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 { createContext, useContext, useState } from 'react' | ||
import { Diary } from '../interface/diary' | ||
|
||
const DiaryValueContext = createContext<Diary[] | undefined>(undefined) |
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.
DiaryValueContext와 DiaryUpdateContext로 데이터를 읽고 업데이트하는 역할을 분리해서 사용하신 덕분에 더 직관적이고 확장 가능한 구조를 만든 것 같습니다!
상태 관리 라이브러리를 사용하지 않고도 전역 상태를 관리할 수 있는 좋은 방법인거 같습니다😄
import DiaryEmotionPage from '../app/emotions/[emotion]/page' | ||
|
||
export type DiaryRouterPath = '/' | `/detail/${string}` | '/emotions' | `/emotions/${string}` | ||
const diaryRouter = createBrowserRouter([ |
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.
리액트 라우터를 이용해 라우팅을 구성하고, 각 경로에 맞는 컴포넌트를 매핑한 부분도 정말 배울 점이 많았습니다!
Summary
메인 페이지 구현을 완료하였습니다.
Description
코드 리뷰는 무엇이든지 언제나 환영입니다!!😊