-
Notifications
You must be signed in to change notification settings - Fork 10
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
[5주차] 김채림 미션 제출합니다. #16
base: main
Are you sure you want to change the base?
Changes from 32 commits
558c64f
68e5196
f88e8a3
1fa59cb
d8ab759
d93bcfb
853c304
fb7863e
d3b98dd
a4bc798
654d846
45e884a
9f3b7c7
930c318
2a30610
7f400ef
a232d32
bb1dd5f
f502ab8
0197867
eff40d7
a76d7e6
ebefc6d
b2ad9f5
007f422
293bf5a
56d3826
c237ae2
7a7c2a4
d9a926a
98cc50d
c4ee182
9456954
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} |
Large diffs are not rendered by default.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Route, Routes } from 'react-router-dom'; | ||
import GlobalStyle from './Globalstyle'; | ||
import styled from 'styled-components'; | ||
import FriendList from './routes/FriendList'; | ||
import ChatList from './routes/ChatList'; | ||
import Setting from './routes/Setting'; | ||
Comment on lines
+4
to
+6
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. 페이지와 관련된 컴포넌트들은 보통 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. 넵 !! 수정해보겠습니다!!! |
||
import MessengerBox from './components/Message/MessengerBox'; | ||
|
||
const App = () => { | ||
return ( | ||
<> | ||
<GlobalStyle /> | ||
<MessengerContainer> | ||
<Routes> | ||
<Route path="/" element={<FriendList />} /> | ||
<Route path="/chatlist" element={<ChatList />} /> | ||
<Route path="/messengerbox/:userName" element={<MessengerBox />} /> | ||
<Route path="/setting" element={<Setting />} /> | ||
</Routes> | ||
</MessengerContainer> | ||
</> | ||
); | ||
}; | ||
export default App; | ||
|
||
const MessengerContainer = styled.div` | ||
/* 너비 | 스타일 | 색 */ | ||
border: 0.08rem solid #c2bbbb; | ||
margin: 0 auto; | ||
margin-top: 5rem; | ||
background: white; | ||
border-radius: 0.5rem; | ||
height: 43rem; | ||
width: 26rem; | ||
justify-content: flex-start; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { createGlobalStyle } from 'styled-components'; | ||
|
||
//페이지 전체에 적용될 style | ||
const GlobalStyle = createGlobalStyle` | ||
|
||
button { | ||
&:hover{ | ||
cursor: pointer; | ||
} | ||
Comment on lines
+6
to
+9
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. 버튼까지 전역으로 스타일링 좋네요 |
||
border: none; | ||
background: none; | ||
font-size: 17px; | ||
} | ||
|
||
::-webkit-scrollbar { | ||
width: 0.9rem; | ||
margin: 0; | ||
} | ||
|
||
::-webkit-scrollbar-thumb { | ||
height: 17%; | ||
background-color: #c2bbbb; | ||
border-radius: 10px; | ||
background-clip: padding-box; | ||
border: 0.3rem solid transparent; | ||
} | ||
`; | ||
|
||
export default GlobalStyle; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import styled from 'styled-components'; | ||
import { IChattingsProps } from '../../interface/interface'; | ||
import { | ||
LinkToChat, | ||
ListItem, | ||
ProfileImg, | ||
UserName, | ||
} from '../layout/CommonStyle'; | ||
const Chattings = ({ userId, userName, message }: IChattingsProps) => { | ||
return ( | ||
<ChattingRooms> | ||
<LinkToChat to={`/messengerbox/${userName}`}> | ||
<ProfileImg src={`/assets/${userId}.jpg`} /> | ||
<ListItem> | ||
<UserName>{userName}</UserName> | ||
<LastMessage>{message}</LastMessage> | ||
</ListItem> | ||
</LinkToChat> | ||
</ChattingRooms> | ||
Comment on lines
+12
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. 이런 방식이라면 확실히 리코일 없이 데이터가 관리가 편했겠네요. |
||
); | ||
}; | ||
|
||
export default Chattings; | ||
|
||
const ChattingRooms = styled.div` | ||
display: flex; | ||
padding-left: 1rem; | ||
margin: 0.5rem; | ||
`; | ||
|
||
const LastMessage = styled.div` | ||
font-weight: lighter; | ||
font-size: 14px; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import styled from 'styled-components'; | ||
import { IFriendsProps } from '../../interface/interface'; | ||
import { | ||
LinkToChat, | ||
ListItem, | ||
ProfileImg, | ||
UserName, | ||
} from '../layout/CommonStyle'; | ||
const Friends = ({ userProfile, userName, userStatus }: IFriendsProps) => { | ||
return ( | ||
<FriendList> | ||
<LinkToChat to={`/messengerbox/${userName}`}> | ||
<ProfileImg src={`/assets/${userProfile}`} /> | ||
<ListItem> | ||
<UserName>{userName}</UserName> | ||
<UserStatus>{userStatus}</UserStatus> | ||
</ListItem> | ||
</LinkToChat> | ||
</FriendList> | ||
Comment on lines
+11
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.
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. 이제와서 보니 정말 구조가 비슷하네요 컴포넌트를 재사용해봐야겠어요 반영해서 수정해보겠습니당 |
||
); | ||
}; | ||
|
||
export default Friends; | ||
|
||
const FriendList = styled.div` | ||
display: flex; | ||
padding-left: 1rem; | ||
margin: 0.5rem; | ||
`; | ||
|
||
const UserStatus = styled.div` | ||
font-weight: lighter; | ||
font-size: 14px; | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import styled from 'styled-components'; | ||
import { BsSearch } from 'react-icons/bs'; | ||
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. 꿀팁 배워갑니다 |
||
import useInput from '../../hooks/useInput'; | ||
import { useEffect } from 'react'; | ||
import { IFilteredUser } from '../../interface/interface'; | ||
|
||
const SearchUser = ({ filteredUser }: IFilteredUser) => { | ||
const { textinput, handleInputChange } = useInput(''); | ||
|
||
useEffect(() => filteredUser(textinput), [filteredUser, textinput]); | ||
return ( | ||
<SearchContainer> | ||
<BsSearch size={18} className="searchLogo" /> | ||
<SearchInput | ||
placeholder="Search . . . " | ||
value={textinput} | ||
type="text" | ||
onChange={handleInputChange} | ||
/> | ||
</SearchContainer> | ||
); | ||
}; | ||
export default SearchUser; | ||
|
||
const SearchInput = styled.input` | ||
margin-left: 1rem; | ||
width: 16rem; | ||
height: 1.5rem; | ||
border-radius: 0.5rem; | ||
border: 0.08rem solid #c2bbbb; | ||
padding-left: 1rem; | ||
`; | ||
const SearchContainer = styled.div` | ||
padding: 1rem; | ||
height: 2rem; | ||
text-align: center; | ||
|
||
.searchLogo { | ||
line-height: 3rem; | ||
position: relative; | ||
top: 0.3rem; | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import styled from 'styled-components'; | ||
import SingleMessage from './SingleMessage'; | ||
import { IMessageData } from '../../interface/interface'; | ||
|
||
const MessageList = ({ messageData }: { messageData: Array<IMessageData> }) => { | ||
const scrollbarRef = useRef<HTMLDivElement>(null); | ||
|
||
const scrollToBottom = () => { | ||
if (scrollbarRef.current) { | ||
scrollbarRef.current.scrollTop = scrollbarRef.current.scrollHeight; | ||
} | ||
}; | ||
useEffect(() => { | ||
scrollToBottom(); | ||
}, [messageData]); | ||
Comment on lines
+9
to
+16
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.
|
||
|
||
return ( | ||
<ListContainer ref={scrollbarRef}> | ||
<ShowList> | ||
{messageData.map((chat: IMessageData) => ( | ||
<SingleMessage chat={chat} key={chat.userId} /> | ||
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. userId를 key값으로 주면 동일한 값으로 들어가게 되네요. 데이터에 chatId와 같은 값을 추가하는게 좋을것 같습니다. |
||
))} | ||
</ShowList> | ||
</ListContainer> | ||
); | ||
}; | ||
|
||
export default MessageList; | ||
|
||
const ListContainer = styled.div` | ||
height: 26rem; | ||
padding: 1rem; | ||
overflow-y: auto; | ||
overflow-x: hidden; | ||
`; | ||
const ShowList = styled.div``; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import UserNav from '../layout/UserNav'; | ||
import { useState } from 'react'; | ||
import user from '../../data/user.json'; | ||
import message from '../../data/message.json'; | ||
import MessengerInput from './MessengerInput'; | ||
import MessageList from './MessageList'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
const MessengerBox = () => { | ||
// 사용자 나부터 시작 | ||
const otherUser = useParams(); | ||
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.
|
||
const userindex = message.findIndex( | ||
(message) => message.userName === otherUser.userName | ||
); | ||
const userMessageData = message[userindex]; | ||
|
||
const [currentUser, setCurrentUser] = useState(user[0]); | ||
const [messageData, setMessageData] = useState(userMessageData.messages); | ||
return ( | ||
<> | ||
<UserNav | ||
currentUser={currentUser} | ||
setCurrentUser={setCurrentUser} | ||
otherUser={otherUser} | ||
/> | ||
<MessageList messageData={messageData} /> | ||
|
||
<MessengerInput | ||
currentUser={currentUser} | ||
messageData={messageData} | ||
setChatList={setMessageData} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export default MessengerBox; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { useCallback } from 'react'; | ||
import styled from 'styled-components'; | ||
import useInput from '../../hooks/useInput'; | ||
import { IMessengerInputProps } from '../../interface/interface'; | ||
const MessengerInput = ({ currentUser, messageData, setChatList }: any) => { | ||
const { textinput, handleInputChange, handleInputInitialize } = useInput(''); | ||
|
||
const handleInputSubmit = useCallback( | ||
(e: React.FormEvent<HTMLFormElement>) => { | ||
//공백이 아닐 때에만 send 가능 | ||
if (textinput.replace(/\s+/g, '')) { | ||
const date = new Date(); | ||
const hours = String(date.getHours()).padStart(2, '0'); | ||
const minutes = String(date.getMinutes()).padStart(2, '0'); | ||
const messageObject = { | ||
userId: currentUser.userId, | ||
userName: currentUser.userName, | ||
text: textinput, | ||
time: `${hours}:${minutes}`, | ||
}; | ||
|
||
setChatList([...messageData, messageObject]); | ||
|
||
//공백일 경우 alert | ||
} else { | ||
alert('메세지를 입력하세요 ! '); | ||
} | ||
|
||
handleInputInitialize(); | ||
|
||
//새로고침 방지 | ||
e.preventDefault(); | ||
}, | ||
[messageData] | ||
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. [messageData,textinput] |
||
); | ||
|
||
return ( | ||
<SubmitForm onSubmit={handleInputSubmit}> | ||
<InputBoxWrapper> | ||
<InputBox | ||
value={textinput} | ||
onChange={handleInputChange} | ||
placeholder="Send Message . . ." | ||
type="text" | ||
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. required 속성을 추가해줘도 편하더라구요 |
||
/> | ||
</InputBoxWrapper> | ||
|
||
<SendButton>🕸</SendButton> | ||
</SubmitForm> | ||
); | ||
}; | ||
|
||
export default MessengerInput; | ||
|
||
const SubmitForm = styled.form` | ||
align-items: center; | ||
border-top-style: solid; | ||
border-color: #c2bbbb; | ||
border-width: 0.08rem; | ||
padding: 0; | ||
height: 6rem; | ||
display: flex; | ||
justify-content: space-evenly; | ||
`; | ||
|
||
const InputBoxWrapper = styled.div` | ||
padding-left: 2rem; | ||
`; | ||
|
||
const InputBox = styled.input` | ||
padding-left: 1rem; | ||
line-height: 5.5rem; | ||
border-color: #c2bbbb; | ||
border-width: 0.08rem; | ||
border-style: solid; | ||
Comment on lines
+78
to
+80
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. 이 세 줄을 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. 저번에 효정님이 짚어주셨는데 또 이런짓을 했군요 수정하겠습니다 ㅠ ㅠ |
||
border-radius: 0.5rem; | ||
width: 18rem; | ||
height: 2.3rem; | ||
margin: 0; | ||
line-height: 6rem; | ||
`; | ||
const SendButton = styled.button` | ||
line-height: 6rem; | ||
background-color: transparent; | ||
font-size: 1.5rem; | ||
`; |
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.
시도의 흔적