Skip to content

[3주차] 이승범 미션 제출합니다.#11

Open
sbl133 wants to merge 17 commits intoCEOS-Developers:mainfrom
sbl133:sbl133
Open

[3주차] 이승범 미션 제출합니다.#11
sbl133 wants to merge 17 commits intoCEOS-Developers:mainfrom
sbl133:sbl133

Conversation

@sbl133
Copy link
Copy Markdown

@sbl133 sbl133 commented Apr 28, 2021

미션기간이 길었지만 학교에서 과제가 많이 나오는 시기랑 겹쳐서 좀 각박하게 미션수행을 했던거 같습니다.
나름 열심히 만들었는데 실력이 많이 부족해서 아쉬움이 많이 남아요..
react-router 존재만 알고 실제로 구현해본적이 없었는데 이번 미션을 계기로 react-router에 대해서 제대로 알게 된것 같아 많은 도움이 되었습니다. 아직 SSR과 SPA같은 네트워크(?) 개념이 부족한거 같지만 스터디전까지 열심히 공부해 보겠습니다.
감사합니다!
배포주소 : https://react-messenger-13th-eta.vercel.app/

Copy link
Copy Markdown

@comforest comforest left a comment

Choose a reason for hiding this comment

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

중복 소스 코드가 조금 있네요.
데이터를 총괄적으로 관리하지 못한것도 조금 아쉬워요. (어렵긴 하죠...)
특히 아래와 같은 코드가 있던데

if(condition1) {
  state1
} else {
  if(condition2) {
    state2
  }
}

이런 코드는

if(condition1) {
  state1
} else if(condition2) {
  state2
}

처럼 하는게 더 낫겠죠? 특히 state1 이랑 state2 가 같다면

if(condition1 || condition2) {
  state1
}

로 하는게 훨씬 좋습니다

Comment thread src/ChatData.json
@@ -0,0 +1,58 @@
{
"black" : [
{"isMe": false, "text": "hey wassup You to party tonight?"},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
{"isMe": false, "text": "hey wassup You to party tonight?"},
{"userId": 0, "text": "hey wassup You to party tonight?"},

추후 단톡방 기능과 같이 확장성을 생각하면 userId를 이용해 본인 userID 와 비교해서 isMe 여부를 파악하는게 좋을 것 같아요.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

저도 이 말에 동의합니다 ㅎㅎ

Comment thread src/Chat.js
Comment on lines +51 to +63
<WhiteChat key={i}>
<Text>
{v.text}
</Text>
<ChatIcon src="/img/white.png" alt="img" />
</WhiteChat>
:
<BlackChat key={i}>
<ChatIcon src={`/img/${id}.png`} alt="img" />
<Text>
{v.text}
</Text>
</BlackChat>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

같은 컴포넌트 구성이더라도
flex-direction 같은걸 이용해서 구현이 가능합니다.
말 주머니에 시간 정보를 추가하는등 여러 수정사항이 들어올 때마다
두 컴포넌트 모두 수정하기보단 css만 수정하는게 훨씬 편하겠죠?

Comment thread src/ChattingPage.js
`;

const ChattingPage = ({ match }) => {
const [isMe, setIsMe] = useState(true);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

위에서 언급한 것 처럼 id 같은걸 사용하는게 확장성에 용이합니다

Comment thread src/ChatListPage.js


const ChatListPage = () => {
const friendList = initialList;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

App 에서 props로 관리해야 페이지간 데이터 관리가 가능 할 것 같아요

Comment thread src/FriendListPage.js
Comment on lines +53 to +59
if (text === ''){
return <FriendState props={v} where={'FriendList'}/>;
} else {
if (v.name.includes(text)){
return <FriendState props={v} where={'FriendList'}/>;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (text === ''){
return <FriendState props={v} where={'FriendList'}/>;
} else {
if (v.name.includes(text)){
return <FriendState props={v} where={'FriendList'}/>;
}
}
if (text === '' || v.name.includes(text)){
return <FriendState props={v} where={'FriendList'}/>;
}

중복된 코드는 줄이는 방향으로

Comment thread src/FriendListPage.js
<Top>
<H3>친구 {friendList.length}</H3>
<Icon>
<BsPersonPlus size="24" padding-right="10"/>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
<BsPersonPlus size="24" padding-right="10"/>
<BsPersonPlus size="24" padding-right="10"/>

들여쓰기 안되어 있네요

Comment thread src/FriendState.js
@@ -0,0 +1,39 @@
import React,{} from 'react';
import styled from 'styled-components';
import ChatData from './ChatData.json';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

역시 props로 관리 했으면 더 좋았을 것 같아요.

Comment thread src/FriendState.js
<Icon src = {img} alt="img" />
<div>
<Name>{name}</Name>
{where === 'FriendList' ? <Message>{message}</Message> : <Message>{lastChat}</Message>}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
{where === 'FriendList' ? <Message>{message}</Message> : <Message>{lastChat}</Message>}
{<Message>{where === 'FriendList' ? message : lastChat}</Message>}

Comment thread src/Top.js
Comment on lines +22 to +23
{isMe ? <TopIcon src="/img/white.png" alt="image" /> :
<TopIcon src={`/img/${id}.png`} alt="image" />}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
{isMe ? <TopIcon src="/img/white.png" alt="image" /> :
<TopIcon src={`/img/${id}.png`} alt="image" />}
<TopIcon src={isMe ? "/img/white.png" : `/img/${id}.png`} alt="image" />

중복 코드를 줄이는 방향으로

Comment thread src/ChatListPage.js
Comment on lines +58 to +72
if (text === ''){
return (
<StyledLink to={`/ChattingPage/${v.id}`}>
<FriendState props={v} where={'ChatList'}/>
</StyledLink>
);
} else {
if (v.name.includes(text)){
return (
<Link to={`/ChattingPage/${v.id}`}>
<FriendState props={v} where={'ChatList'}/>
</Link>
);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (text === ''){
return (
<StyledLink to={`/ChattingPage/${v.id}`}>
<FriendState props={v} where={'ChatList'}/>
</StyledLink>
);
} else {
if (v.name.includes(text)){
return (
<Link to={`/ChattingPage/${v.id}`}>
<FriendState props={v} where={'ChatList'}/>
</Link>
);
}
}
if (text === '' || v.name.includes(text)){
return (
<StyledLink to={`/ChattingPage/${v.id}`}>
<FriendState props={v} where={'ChatList'}/>
</StyledLink>
);
}

위랑 같죠? 심지어 여긴 StyledLink 가 아니라 Link를 써서 검색을 하면 밑줄이 나오네요.
이러한 문제 때문에 동일한 소스코드를 복붙해서 쓰는건 피해야합니다

Comment thread src/App.js
Comment on lines +84 to +98
<StyledLink to="/">
<BsFillPersonFill size="30" />
</StyledLink>
</StyledLi>
<StyledLi>
<StyledLink to="/ChatListPage">
<BsFillChatFill size="25" />
</StyledLink>
</StyledLi>
<StyledLi>
<StyledLink to="/SettingPage">
<BsThreeDots size="30" />
</StyledLink>
</StyledLi>
</StyledUl>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Depth가 너무 깊어져서 가독성이 많이 떨어집니다.
Component를 다른 파일로 분리하는건 어떨까요?

Copy link
Copy Markdown

@kather0220 kather0220 left a comment

Choose a reason for hiding this comment

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

승범님 코드 보면서 이해도 잘 되고 깔끔해서 제가 많이 드릴 말씀이 없네요. 덕분에 배워가는 것도 많아요. 특히 js를 굉장히 잘 써먹으시는 거 같아요. styled components에 대한 이해도 잘 하시고 계시는 거 같구요! 코멘트를 작성하면서도 제가 하는 말이 맞나 싶었어서 그냥 느낀점이라고 생각해주시면 좋을거 같습니다.미션 하시느라 수고하셨습니다!

Comment thread src/Form.js
border: 0;
border-radius: 20px;
margin-right: 5px;
`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

styled components 를 export 해주셨네요! 그런데 다른 파일에서는 이것들을 안 쓰는 거 같은데 굳이 export 해주신 이유가 있으신가요? 아니면 그냥 별 의미 없이 하신 걸까요? 이유가 궁금합니다.

Comment thread src/ChatListPage.js
</StyledLink>
);
} else {
if (v.name.includes(text)){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

승범님도 includes를 통해서 검색 기능을 구현하셨네요! 저도 이렇게 했는데, 이 방법이 영어로 검색할 때는 대문자까지 그대로 검색해야만 되는 거라 원래의 메신저 검색 기능을 온전히 구현하지 못하는 것 같아요. 그래서 이런 식으로 바꿔주면 어떨까요? 저도 수정하려고 했는데 깜빡한 부분이라 아쉬움이 남아서 코멘트 남겨요.

Suggested change
if (v.name.includes(text)){
if (v.name.toLowerCase().includes(text)){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

정말 세심한 포인트네요!

Comment thread src/FriendState.js

const FriendState = ({props, where}) => {
const {id, name, message, img} = props;
const lastChat = ChatData[id][ChatData[id].length-1].text;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

마지막 메시지를 표시하는 방법 저두 이렇게 시도해보려구 했는데 제 코드가 그럴 상황이 안돼서 시도를 못했거든요. 역시 승범님은 잘 구현하셨네요!!

Comment thread src/ChatData.json
{"isMe": true, "text": "My professor just uploaded a new assignment, and the due is tomorrow"},
{"isMe": false, "text": "보라색과 한 마지막 대화"}
]
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

json 파일이 깔끔하게 정리된 거 같아요! 그만큼 승범님이 코드를 효율적으로 작성하셨다는 거 같아요.

Comment thread src/SettingPage.js
list-style: none;
padding: 15px;
`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

styled components 들이 비교적으로 간결하게 작성된 거 같아요. 저두 styled components를 좀 더 잘 이해하면 이렇게 할 수 있을텐데..ㅎㅎ 복잡하지 않아서 보기도 편하네요. 한 수 배워갑니다!

Copy link
Copy Markdown

@sebastianrcnt sebastianrcnt left a comment

Choose a reason for hiding this comment

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

승범님 안녕하세요 ㅎㅎ

깔끔하게 잘 짜 주셨기도 했고, 호연님과 소정님이 리뷰를 훌륭하게 해주셔서 제가 특별히 해드릴게 없네요. 제가 늘 강조하는 부분인 네이밍과 중복 방지, 코드의 일관성만 계속 고민해보시면 더 좋은 코드가 될 수 있을 것 같습니다.

특히 최적화 해주신 부분이 또 인상적이네요 ㅎㅎ

오늘 특히 스터디에서 그림 그려서 설명하시는 부분이 정말 인상적이었습니다 ㅎㅎ

Comment thread src/App.js
Comment on lines +36 to +37
// border: solid;
// border-width: 1px;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

주석은 지워줍시당~!

Comment thread src/App.js
Comment on lines +48 to +51
const StyledLink = styled(Link)`
text-decoration: none;
color: black;
`;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

styled-components 상속을 정말 잘 사용해주셨네요~ㅎㅎ

Comment thread src/App.js
<GlobalStyle/>
<AppContainer>
<AppLayout>
<StyledUl>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

StyledUl 보다는 좀 더 컴포넌트의 역할을 잘 드러낼 수 있는 네이밍이었으면 좋겠네용. Styled가 접두어로 붙은 모든 컴포넌트들도 마찬가지로요 ㅎㅎ

Comment thread src/App.js
Comment on lines +100 to +107
<div>
<Switch>
<Route exact path="/" component={FriendListPage} />
<Route path={`/ChattingPage/:id`} component={ChattingPage} />
<Route path="/ChatListPage" component={ChatListPage} />
<Route path="/SettingPage" component={SettingPage} />
</Switch>
</div>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

굳이 div를 넣을 이유가 있을까요?

Comment thread src/Chat.js
border-radius: 50%;
`

const Chat = memo(({ chatting, id }) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

최적화를 잘 해주셨네요 ㅎㅎ

Comment thread src/Form.js
Comment on lines +30 to +36
const onChangeText = (e) => {
setText(e.target.value)
};

const onSubmitHandler = (e) => {
e.preventDefault();
if (text==='') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
const onChangeText = (e) => {
setText(e.target.value)
};
const onSubmitHandler = (e) => {
e.preventDefault();
if (text==='') {
const handleTextChange = (e) => {
setText(e.target.value)
};
const handleFormSubmit = (e) => {
e.preventDefault();
if (text==='') {

Comment thread src/Form.js
Comment on lines +45 to +48
<StyledForm onSubmit={onSubmitHandler}>
<Input placeholder="Message..." value={text} onChange={onChangeText} />
<Button>전송</Button>
</StyledForm>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
<StyledForm onSubmit={onSubmitHandler}>
<Input placeholder="Message..." value={text} onChange={onChangeText} />
<Button>전송</Button>
</StyledForm>
<Wrapper onSubmit={onSubmitHandler}>
<Input placeholder="Message..." value={text} onChange={onChangeText} />
<Button>전송</Button>
</Wrapper>

한 파일 안에 하나의 컴포넌트가 있다면, 그 컴포넌트의 styled-component는 Wrapper로 네이밍하는 경우가 많더라구요~!

Comment thread src/FriendListPage.js
</Top>
<Input placeholder=" 이름 검색" value={text} onChange={onChangeText} />
{friendList.map((v) => {
if (text === ''){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
if (text === ''){
if (!text){

if 문 내부의 값은 boolean으로 자동으로 귀결됩니다. 요렇게만 해도 괜찮습니다 ㅎㅎ

Comment thread src/FriendState.js
font-size: 12px;
`;

const FriendState = ({props, where}) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

흠.. props를 이렇게 가져오는 게 맞나요?
where도 좀 더 구체적으로 네이밍 했으면 좋을 것 같네요 ㅎㅎ

Comment thread src/SettingPage.js
const H3 = styled.h3`
padding-left: 10px;
`;
const Ver = styled.div`
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
const Ver = styled.div`
const VersionInfo = styled.div`

이렇게 좀 더 구체적으로?!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants