-
Notifications
You must be signed in to change notification settings - Fork 9
[3주차] 이호연 과제 제출합니다. #16
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: comforest
Are you sure you want to change the base?
Changes from all commits
eff77d3
d8ecbac
c9bf039
5a61b68
840d381
6b767e9
597b1cc
596c00a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| .idea/ | ||
|
|
||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,44 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <link rel="icon" href="%PUBLIC_URL%/muji.jpg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <meta name="theme-color" content="#000000" /> | ||
| <meta | ||
| name="description" | ||
| content="Web site created using create-react-app" | ||
| /> | ||
| <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> | ||
| <!-- | ||
| manifest.json provides metadata used when your web app is installed on a | ||
| user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
| --> | ||
| <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
| <!-- | ||
| Notice the use of %PUBLIC_URL% in the tags above. | ||
| It will be replaced with the URL of the `public` folder during the build. | ||
| Only files inside the `public` folder can be referenced from the HTML. | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <link href="%PUBLIC_URL%/muji.jpg" rel="icon" /> | ||
| <meta content="width=device-width, initial-scale=1" name="viewport" /> | ||
| <meta content="#000000" name="theme-color" /> | ||
| <meta | ||
| content="Web site created using create-react-app" | ||
| name="description" | ||
| /> | ||
| <link href="%PUBLIC_URL%/index.css" rel="text/css" /> | ||
| <link href="%PUBLIC_URL%/logo192.png" rel="apple-touch-icon" /> | ||
| <!-- | ||
| manifest.json provides metadata used when your web app is installed on a | ||
| user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
| --> | ||
| <link href="%PUBLIC_URL%/manifest.json" rel="manifest" /> | ||
| <!-- | ||
| Notice the use of %PUBLIC_URL% in the tags above. | ||
| It will be replaced with the URL of the `public` folder during the build. | ||
| Only files inside the `public` folder can be referenced from the HTML. | ||
|
|
||
| Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
| work correctly both with client-side routing and a non-root public URL. | ||
| Learn how to configure a non-root public URL by running `npm run build`. | ||
| --> | ||
| <title>카카오톡 따라하기</title> | ||
| </head> | ||
| <body> | ||
| <noscript>You need to enable JavaScript to run this app.</noscript> | ||
| <div id="root"></div> | ||
| <!-- | ||
| This HTML file is a template. | ||
| If you open it directly in the browser, you will see an empty page. | ||
| Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
| work correctly both with client-side routing and a non-root public URL. | ||
| Learn how to configure a non-root public URL by running `npm run build`. | ||
| --> | ||
| <title>카카오톡 따라하기</title> | ||
| </head> | ||
| <body> | ||
| <noscript>You need to enable JavaScript to run this app.</noscript> | ||
| <div id="root"></div> | ||
| <!-- | ||
| This HTML file is a template. | ||
| If you open it directly in the browser, you will see an empty page. | ||
|
|
||
| You can add webfonts, meta tags, or analytics to this file. | ||
| The build step will place the bundled scripts into the <body> tag. | ||
| You can add webfonts, meta tags, or analytics to this file. | ||
| The build step will place the bundled scripts into the <body> tag. | ||
|
|
||
| To begin the development, run `npm start` or `yarn start`. | ||
| To create a production bundle, use `npm run build` or `yarn build`. | ||
| --> | ||
| </body> | ||
| To begin the development, run `npm start` or `yarn start`. | ||
| To create a production bundle, use `npm run build` or `yarn build`. | ||
| --> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,11 @@ | ||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||
| import styled, { createGlobalStyle } from 'styled-components'; | ||||||||||||||||||||
| import Header from './Header'; | ||||||||||||||||||||
| import ChatContainer from './ChatContainer'; | ||||||||||||||||||||
| import ChatInput from './ChatInput'; | ||||||||||||||||||||
| import ChatList from './ChatList/index'; | ||||||||||||||||||||
| import User from './User/index'; | ||||||||||||||||||||
| import Setting from './Setting/index'; | ||||||||||||||||||||
| import Nav from './Nav'; | ||||||||||||||||||||
| import { BrowserRouter as Router, Switch, Route, Link } from 'react-router-dom'; | ||||||||||||||||||||
| import { sampleChatList, sampleUserList } from './SampleData'; | ||||||||||||||||||||
| import { useState } from 'react'; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const StyledGlobal = createGlobalStyle` | ||||||||||||||||||||
| body { | ||||||||||||||||||||
|
|
@@ -13,103 +16,38 @@ const StyledGlobal = createGlobalStyle` | |||||||||||||||||||
|
|
||||||||||||||||||||
| const StyledContainer = styled.div` | ||||||||||||||||||||
| display: flex; | ||||||||||||||||||||
| flex-direction: column; | ||||||||||||||||||||
| height: auto; | ||||||||||||||||||||
| min-height: 100%; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| background: #9bbbd4; | ||||||||||||||||||||
| flex-direction: row; | ||||||||||||||||||||
| `; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const userList = [ | ||||||||||||||||||||
| { | ||||||||||||||||||||
| id: 0, | ||||||||||||||||||||
| img: `${process.env.PUBLIC_URL}/muji.jpg`, | ||||||||||||||||||||
| name: '무지', | ||||||||||||||||||||
| status: '현재 접속 중', | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| id: 1, | ||||||||||||||||||||
| img: `${process.env.PUBLIC_URL}/corn.png`, | ||||||||||||||||||||
| name: '콘', | ||||||||||||||||||||
| status: '현재 접속 중', | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| ]; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sampleChat = [ | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[0], | ||||||||||||||||||||
| chatList: ['안녕하세요'], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[1], | ||||||||||||||||||||
| chatList: [ | ||||||||||||||||||||
| '안녕하세요', | ||||||||||||||||||||
| '저도 반갑습니다', | ||||||||||||||||||||
| `저는 ${userList[1].name}입니다.`, | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[0], | ||||||||||||||||||||
| chatList: ['안녕하세요', '반갑습니다', `저는 ${userList[0].name}입니다.`], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[1], | ||||||||||||||||||||
| chatList: [ | ||||||||||||||||||||
| '안녕하세요', | ||||||||||||||||||||
| '저도 반갑습니다', | ||||||||||||||||||||
| `저는 ${userList[1].name}입니다.`, | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[0], | ||||||||||||||||||||
| chatList: [ | ||||||||||||||||||||
| '안녕하세요', | ||||||||||||||||||||
| '반갑습니다', | ||||||||||||||||||||
| `테스트 입력입니다테스트 입력입니다테스트 입력입니다테스트 입력입니다`, | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| { | ||||||||||||||||||||
| user: userList[1], | ||||||||||||||||||||
| chatList: [ | ||||||||||||||||||||
| '안녕하세요', | ||||||||||||||||||||
| '저도 반갑습니다', | ||||||||||||||||||||
| `저는 ${userList[1].name}입니다.`, | ||||||||||||||||||||
| ], | ||||||||||||||||||||
| }, | ||||||||||||||||||||
| ]; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export default () => { | ||||||||||||||||||||
| const [currentUser, setCurrentUser] = useState(userList[0]); | ||||||||||||||||||||
| const [ownerUser, setOwnerUser] = useState(userList[0]); | ||||||||||||||||||||
| const [chatData, setChatData] = useState(sampleChat); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const sendMessage = (message) => { | ||||||||||||||||||||
| if (message === '') { | ||||||||||||||||||||
| alert('빈 텍스트 입니다'); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const lastChatItem = chatData[chatData.length - 1]; | ||||||||||||||||||||
| if (lastChatItem.user.id === currentUser.id) { | ||||||||||||||||||||
| lastChatItem.chatList.push(message); | ||||||||||||||||||||
| setChatData([...chatData]); | ||||||||||||||||||||
| } else { | ||||||||||||||||||||
| const nextChatItem = { user: currentUser, chatList: [message] }; | ||||||||||||||||||||
| const newChatData = [...chatData, nextChatItem]; | ||||||||||||||||||||
| setChatData(newChatData); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| }; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const toggleCurrentUser = () => { | ||||||||||||||||||||
| setCurrentUser(currentUser.id === 0 ? userList[1] : userList[0]); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| const [chatList, setChatList] = useState(sampleChatList); | ||||||||||||||||||||
| const [userList, setUserList] = useState(sampleUserList); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <StyledContainer> | ||||||||||||||||||||
| <Router> | ||||||||||||||||||||
| <StyledGlobal /> | ||||||||||||||||||||
| <Header user={currentUser} onClickImage={toggleCurrentUser} /> | ||||||||||||||||||||
| <ChatContainer chatData={chatData} ownerUserId={ownerUser.id} /> | ||||||||||||||||||||
| <ChatInput onSendMessage={sendMessage} /> | ||||||||||||||||||||
| </StyledContainer> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <StyledContainer> | ||||||||||||||||||||
| <Switch> | ||||||||||||||||||||
| <Route | ||||||||||||||||||||
| path={['/', '/user', '/chat', '/setting']} | ||||||||||||||||||||
| component={Nav} | ||||||||||||||||||||
| exact | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| </Switch> | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <Switch> | ||||||||||||||||||||
| <Route | ||||||||||||||||||||
| path="/user" | ||||||||||||||||||||
| render={(props) => <User {...props} userList={userList} />} | ||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 일반적으로 Component의 이름과 파일 이름을 동일하게 설정하는 편인데 User/index.js에 있다고 설명이 있으면 좋을 듯 합니다 |
||||||||||||||||||||
| /> | ||||||||||||||||||||
|
Comment on lines
+40
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
혹시 이렇게 해도 작동 하던가요?? |
||||||||||||||||||||
| <Route | ||||||||||||||||||||
| path="/chat" | ||||||||||||||||||||
| render={(props) => <ChatList {...props} chatList={chatList} />} | ||||||||||||||||||||
| /> | ||||||||||||||||||||
| <Route path="/setting" component={Setting} /> | ||||||||||||||||||||
| </Switch> | ||||||||||||||||||||
| </StyledContainer> | ||||||||||||||||||||
| </Router> | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| }; | ||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||
| import { useEffect, useRef } from 'react'; | ||||||||||||||
| import { Fragment, useEffect, useRef } from 'react'; | ||||||||||||||
| import styled from 'styled-components'; | ||||||||||||||
| import ChatItemContainer from './ChatItemsContainer'; | ||||||||||||||
| import * as ReactDOM from 'react-dom'; | ||||||||||||||
|
|
@@ -17,7 +17,7 @@ export default (props) => { | |||||||||||||
| const list = props.chatData.map((item, index) => { | ||||||||||||||
| return ( | ||||||||||||||
| <ChatItemContainer | ||||||||||||||
|
Comment on lines
17
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list보다는 좀 더 구체적인 이름이면 좋을 것 같아요.
Suggested change
|
||||||||||||||
| chatList={item.chatList} | ||||||||||||||
| chatList={item.chat} | ||||||||||||||
| user={item.user} | ||||||||||||||
| ownerUserId={props.ownerUserId} | ||||||||||||||
| ref={index === props.chatData.length - 1 ? lastItem : undefined} | ||||||||||||||
|
Comment on lines
17
to
23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요 부분에서 index === props.chatData.length - 1을 쓰는것보다 그 위에서 const isLatestChat = index === props.chatData.length - 1;이렇게 해보는건 어떨까요? 그러면 이 줄을 ref={isLatestChat ? lastItem : 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.
웹페이지를 처음 시작할때 안에 내용이 없고 레이아웃만 뜨던데
제 생각에는 아마 여기서 path = "/" 일때 반환하는 component가 없어서 그런거 같아요
웹페이지가 처음 시작할때 path가 "/"인것을 감안해서 그 경우에도 반환하는 component가 있을면 좋을거 같습니다