-
Notifications
You must be signed in to change notification settings - Fork 8
[5주차] 임시언 미션 제출합니다. #18
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?
Conversation
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.
시언님! 이번과제도 하느라 수고 많으셨어요! 시언님 코드 보면서 폴더구조라던지, 저도 적용해보고 싶은 메소드도 다시한번 공부할 수 있는 시간이였던 것 같아요🥹 다음 미션도 화이팅!
{ | ||
"me": { | ||
"id": "eonny", | ||
"name": "임시언", | ||
"profileImage": "/images/Me.png" | ||
}, | ||
"users": [ | ||
{ |
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.
저도 me와 users를 나눠서 json 파일 정리해야할 것 같아요!
참고해서 정리해보겠습니다!
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.
아무래도 채팅방을 보여줘야하는데 이거를 하나의 파일에서 관리할 수 없을까 고민하다가 채팅이 1:1대화니까 나와 다른 유저들이라고 분리해서 생각했습니다!
|
||
interface ChatInputProps { | ||
onSendMessage: (message: string) => void; | ||
isMuted: boolean; // 뮤트 상태를 나타내는 prop 추가 |
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.
지나가면서 얘기해보자면 방해금지모드를 이야기 하는 것 아닐까요 ?! 만일 방해금지모드라면 input이 비활성화 되어야 하기 떄문에,,
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.
넵 맞습니다!. 이게 알람 아이콘이길래 뮤트가 음소거라는 뜻인디 그렇게 사용하게 되었네요! 다른 분들도 쉽게 알아볼 수 있도록 저만 아는 표현은 지양하겠습니다.
} | ||
&:disabled { | ||
cursor: not-allowed; | ||
background-color: transparent; /* 배경색을 투명하게 설정 */ |
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 ChatItem: React.FC<ChatItemProps> = ({ profileImage, name, status,onClick }) => { | ||
return ( | ||
<ChatItemContainer className="chat-item" onClick={onClick}> |
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.
ChatItemContainer에 클래스 이름을 추가한 이유가 궁금합니다!
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.
ClassName은 사실 이번에 기존 css처럼 ClassName으로 불러오는 형식으로 할까 고민을 하다가 결국엔 다시 편한 방식으로 돌아갔습니다. 리액트를 공부하면서 css를 적용하는 방법이 다양해서 하나씩 해보려고 하는 편입니다.
<img | ||
src={profileImage} | ||
alt={`${name} profile`} | ||
style={{ width: '50px', height: '50px', borderRadius: '50%', marginRight: '10px' }} | ||
/> |
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.
이번에 빨리 빨리 쳐내려고 하다 보니까 우선 구조를 만들고 정리하고 이런 식으로 진행했습니다.
const handleBackClick = () => { | ||
navigate(-1); | ||
}; |
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.
넵! 미니 프로젝트 하면서도 이 방식을 적용 했습니다. 브라우저의 히스토리 스택에 의존해서 사용자가 웹 사이트를 탐색할 때 각 페이지 이동이 히스토리 스택에 저장이 되어서 한 단계 전으로 이동할 수 있다고 합니다. 이 방법을 권장하는지는 더 공부해봐야 할 것 같습니다!
useEffect(() => { | ||
fetch('/data/chatData.json') | ||
.then((response) => response.json()) | ||
.then((data) => setChatData(data)) | ||
.catch((error) => console.error('Error fetching chat data:', error)); | ||
}, []); |
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.
URL(/data/chatData.json) 부분도 상수 분리가 가능할 것 같아요!
[예시]
// constants.ts
export const API_URL = '/data/chatData.json';
export const DEFAULT_HEADER_TITLE = '채팅 목록';
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 handleBellClick = () => { | ||
setIsMuted((prev) => !prev); | ||
}; |
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.
뮤트 상태를 이런식으로 활용할 수 있군요!
}, [userId]); | ||
|
||
useEffect(() => { | ||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); |
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.
scrollIntoView 저도 스터디하면서 알게된 메소드인데! 다른분들도 다 이거 사용하시는군요!
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.
넵 처음에 적용할 때 아마 제가 마지막 메시지의 좌표를 찾아 가는 메소드를 사용했었는데 스크롤을 사용하는법을 보고 적용했습니다.
<ChatMessage | ||
key={`chat-${index}`} |
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.
JSON 파일을 구성하는게 좀 머리 아팠습니다. 유저마다 하나의 json 파일을 만들어주는 것이 너무 비효율 적인 것 같아가지고..
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 handleChatItemClick = (userId: string) => { | ||
navigate(`/chat/${userId}`); // 해당 사용자의 chat screen으로 이동 |
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.
라우팅 path도 상수로 분리하면 좋을 것 같습니다.
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.
path를 상수로 분리! 적용하겠습니다.
"chats": [ | ||
{ | ||
"index": 1, | ||
"id": "dlwlrma", |
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.
users와 chats이 분리되어 있으면 chats안에있는 users 정보도 분리해도 될 것 같습니다 ~
index는 무슨 용도인걸까요 ? 단순히 렌더링시 나와 상대를 분리하기 위함이라면 index가 아닌 userId를 넣어 구분해도 좋을 것 같습니다.
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.
맞습니다. 제일 초반 미션 때 1과 2로 분리를 했었는데 아예 User랑 Me로 구분을 해서 그렇게 구분하는 것이 좋을 것 같네요!
"time": "오후 08:48" | ||
}, | ||
{ | ||
"indexex": 2, |
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.
바로 수정했슴다!
setNewChats(savedChats); | ||
}) | ||
.catch((error) => console.error('Error fetching chat data:', error)); | ||
}, [userId]); |
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.
여기 useEffect 부분은 커스텀훅으로 분리하셔도 좋을 것 같습니다 !
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.
네!
안녕하세요. LG U+ 유레카 프론트엔드 1기 임시언 입니다.
오랜만에 과제라 많은 어려움이 있었습니다.
저는 이번에 다시 구성해보려고 처음부터 다시 만들었는데요. 괜히 했다 싶긴합니다. 아예 프로젝트 생성부터 다시 했습니다. 실제 프로젝트하면서 그래도 익숙해진 것 같아 전보다는 깔끔해진 모습이 좋습니다.
좀 더 수정이 필요하겠지만 더 추가하고 더 공부하겠습니다.
미션
🎯 미션 목표
✅ 필수 요건
🏷️ 선택 사항
⏰ 제출 기한
미니 프로젝트 기간으로 인해 스터디 일정이 변경되었습니다
2024년 10월 8일 화요일 23시 59분
📖 생각해 볼 질문들
구현
https://react-sns-six.vercel.app/