Skip to content
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

[4주차] 임채리 미션 제출합니다. #22

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6da31f4
[FEAT] 전체 구조, iChatIInput 구현 (추후 ts로 변환 예정 ...)
Sep 28, 2022
d5b2b16
[FEAT] json + input 화면에 출력
Sep 28, 2022
f30fff5
[FIX] id -> msgId, userId 구분
Sep 28, 2022
966fcc1
[FEAT] currentUser 추가
Sep 29, 2022
868dc9a
[STYLE] ] styled-components 적용, UserImg test ...
Sep 29, 2022
110561e
[FEAT] chat에 currentUser 연결
Sep 29, 2022
6b22e7c
[FEAT] 빈 Input 전송 막기
Sep 29, 2022
b547e76
[FEAT-ERR] user Toggle 기능 구현 (오류 수정 예정)
Sep 29, 2022
fb558bf
[FEAT] UserImg 추가
Sep 29, 2022
dd9104c
[STYLE] css 수정
Sep 29, 2022
545d73e
[FIX] js -> ts
Sep 30, 2022
8911384
[FIX] toggle 해결, img 엑박 해결
Sep 30, 2022
b652549
[CHORE] style 수정
Sep 30, 2022
e8eee80
[FEAT] scroll 기능 구현
Sep 30, 2022
d1287b1
[STYLE] CurrentUser img hover 색 변경
Sep 30, 2022
7bb6932
[STYLE] button active css
Sep 30, 2022
e294746
[FIX] user별 메세지 위치 지정
Oct 2, 2022
0488d3e
[FIX] user mesessage 위치 문제 해결
Oct 2, 2022
c3aa5f4
[REFACTOR] recoil 사용
Oct 29, 2022
ed39bca
[FEAT] Router 추가
Oct 30, 2022
477c450
[FEAT] NavBar 추가
Oct 30, 2022
6881ec7
[FEAT] FriendsPage - user 전체 출력 & user.json 추가
Oct 30, 2022
fbd57b0
[FEAT] user.json 상태메세지(status) 추가, 화면 출력, message.json 수정 중
Oct 31, 2022
50d015a
[FEAT] 채팅 목록 (ChatRoomList) 출력
Nov 1, 2022
0f0694b
[CHORE] prettier 적용
Nov 1, 2022
824308b
[FEAT] 채팅리스트 link 연결 (수정 중)
Nov 1, 2022
49b6612
[CHORE] font style 수정
Nov 2, 2022
5e91548
[FEAT] 채팅리스트 마지막 채팅 출력/ 채팅방별 연결 .. 수정 중 ❌
Nov 2, 2022
41e5f06
[FEAT] 검색 기능 구현
Nov 2, 2022
37d218e
[ERR]
Nov 3, 2022
4eae14a
[FIX] 채팅리스트 출력 오류 해결
Nov 4, 2022
b7b05ec
[CHORE] css 픽셀 수정
Nov 4, 2022
10db4bf
[FEAT] 친구리스트와 나 구분
Nov 4, 2022
abfcbc4
[FEAT] 더보기 페이지 링크 추가
Nov 4, 2022
92cad81
[FIX] input 채팅리스트에 적용하기 수정
Nov 4, 2022
5cc0761
vercel 배포
Nov 4, 2022
baa0dd3
[FIX] 채팅 잘리는 것 방지 (줄 넘어가기)
Nov 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
465 changes: 451 additions & 14 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.11.60",
"@types/react": "^18.0.21",
"@types/react-dom": "^18.0.6",
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@types/react-router-dom": "^5.3.3",
"history": "5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^4.6.0",
"react-router-dom": "^6.4.2",
"react-scripts": "5.0.1",
"recoil": "^0.7.6",
"styled-components": "^5.3.6",
"typescript": "^4.8.3",
"web-vitals": "^2.1.4"
},
Expand All @@ -39,5 +45,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/styled-components": "^5.1.26"
}
}
Binary file added public/img/banana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/ch9eri.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/grape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/watermelon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 63 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
import styled from 'styled-components';
import { createGlobalStyle } from 'styled-components';
import { RecoilRoot } from 'recoil';
import ChatRoomListPage from './pages/ChatRoomListPage';
import FriendsPage from './pages/FriendsPage';
import SettingsPage from './pages/SettingsPage';
import ChatsPage from './pages/ChatsPage';
import NavBar from './NavBar';
import { BrowserRouter, Route, Routes } from 'react-router-dom';
//vercel 배포
function App() {
return <div>화이팅!!</div>;
return (
<BrowserRouter>
<RecoilRoot>
<GlobalStyle />
<Wrapper>
<Container>
<NavBar />
<Routes>
<Route path="/" element={<FriendsPage />} />
<Route path="/chatlist" element={<ChatRoomListPage />} />
<Route path="/chatroom/:roomid" element={<ChatsPage />} />
<Route path="/settings" element={<SettingsPage />} />
</Routes>
</Container>
</Wrapper>
</RecoilRoot>
</BrowserRouter>
);
}

const GlobalStyle = createGlobalStyle`
body {
font-family: "Helvetica", "Arial", sans-serif;
width: 100%;
height: 100%;
background-color: white;
}

button {
background-color: transparent;
font-size: 20px;
cursor: pointer;
border: none;
}

`;

const Wrapper = styled.div`
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
border-radius: 20px;
`;

const Container = styled.div`
border-radius: 20px;
width: 400px;
height: 600px;
box-shadow: 1px 1px 10px gray;
display: grid;
grid-template-columns: 1fr 5fr;
`;

export default App;
42 changes: 42 additions & 0 deletions src/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import { BsPersonFill, BsChatFill, BsThreeDots } from 'react-icons/bs';

const NavBar = () => {
return (
<Nav>
<Icons>
<Link to="/">
<BsPersonFill color={'#696969'} />
</Link>
</Icons>
<Icons>
<Link to="/chatlist">
<BsChatFill color={'#696969'} />
</Link>
</Icons>
<Icons>
<Link to="/settings">
<BsThreeDots color={'#696969'} />
</Link>
</Icons>
</Nav>
);
};

const Nav = styled.div`
display: flex;
flex-direction: column;
background-color: #dcdcdc;
border-radius: 20px 0px 0px 20px;
`;

const Icons = styled.li`
list-style: none;
font-size: 30px;
margin-top: 20px;
display: flex;
justify-content: center;
`;

export default NavBar;
15 changes: 15 additions & 0 deletions src/atoms.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { atom } from 'recoil';
import message from './data/message.json';
import user from './data/user.json';
import { IChatBoard,IUser } from './interface';


export const listAtom = atom<IChatBoard[]>({
key: 'chatList',
default: message
});

export const userAtom = atom<IUser>({
key: 'user',
default: user[0]
})
42 changes: 42 additions & 0 deletions src/components/ChatRoomLists/ChatRoom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import React from 'react';
import styled from 'styled-components';
import { IChatRoomList } from '../../interface';

const ChatRoom = ({ text, name }: IChatRoomList) => {
return (
<ChatRoomContainer>
<ChatRoomImg src={`./img/${name}.png`} />
<div>
<ChatRoomName>{name}</ChatRoomName>
<ChatRoomText>{text}</ChatRoomText>
</div>
</ChatRoomContainer>
);
};

const ChatRoomContainer = styled.div`
display: grid;
grid-template-columns: 1fr 5fr;
height: 50px;
margin-bottom: 10px;
margin-left: 10px;
`;

const ChatRoomImg = styled.img`
width: 40px;
height: 40px;
border-radius: 50%;
`;

const ChatRoomName = styled.div`
font-size: 17px;
font-weight: 500;
`;

const ChatRoomText = styled.div`
color: gray;
font-size: 13px;
margin-top: 2px;
`;

export default ChatRoom;
25 changes: 25 additions & 0 deletions src/components/ChatRoomLists/ChatRoomList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import message from '../../data/message.json';
import ChatRoom from './ChatRoom';
import { Link } from 'react-router-dom';

function ChatRoomList() {
return (
<div>
{message.map((Msg) => (
<Link
to={`/chatroom/${Msg.roomid}`}
style={{ textDecoration: 'none', color: 'black' }}
>
Copy link
Member

Choose a reason for hiding this comment

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

채팅방 목록에서 나와의 채팅방으로 이동할때 경로가 "/chatroom/undefined" 이렇게 이동되어서 화면이 안뜨는데 혹시 이유가 뭘까요..! 친구목록에서 나와의 채팅방은 "/chatroom/0" 이 경로로 잘 들어가지네요!

<ChatRoom
key={Msg.userid}
text={Msg.msg[Msg.msg.length - 1].text}
name={Msg.name}
roomid={Msg.roomid}
/>
</Link>
))}
</div>
);
}

export default ChatRoomList;
77 changes: 77 additions & 0 deletions src/components/Chats/Chat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react';
import styled from 'styled-components';
import { IUser, IChatRoomList } from '../../interface';
import { userAtom } from '../../atoms';
import { useRecoilState } from 'recoil';

const Chat = ({ name, text }: IChatRoomList) => {
const [currentUser] = useRecoilState<IUser>(userAtom);

return (
<>
{name === currentUser.name ? (
<Li1>
<UserImg src={`../img/${name}.png`} />
<div>
<UserName1>{name}</UserName1>
<Text>{text}</Text>
</div>
</Li1>
) : (
<Li2>
<UserImg src={`../img/${name}.png`} />
<div>
<UserName2>{name}</UserName2>
<Text>{text}</Text>
</div>
</Li2>
)}
</>
);
};

const Li1 = styled.li`
display: flex;
flex-direction: row-reverse;
margin-right: 20px;
margin-bottom: 10px;
`;

const Li2 = styled.li`
display: flex;
flex-direction: row;
margin-bottom: 10px;
`;

Copy link
Member

Choose a reason for hiding this comment

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

Li1 과 Li2 에서 사용하는 속성이 중복되는게 많은 것 같아서 flex-direction 이랑 margin-right를 props로 주어 하나의 style로 만들어주면 어떨까싶습니다!

const UserImg = styled.img`
width: 30px;
height: 30px;
border-radius: 50%;
`;

const UserName1 = styled.span`
display: flex;
flex-direction: row-reverse;
padding: 5px;
margin-bottom: 5px;
margin-right: 5px;
`;

const UserName2 = styled.span`
display: flex;
flex-direction: row;
padding: 5px;
margin-bottom: 5px;
margin-left: 5px;
`;

const Text = styled.span`
background-color: white;
margin: 10px;
padding: 10px;
border-radius: 10px;
font-size: 13px;
margin-top: 10px;
`;
Copy link
Member

Choose a reason for hiding this comment

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

혹시 여기는 margin-top 에만 20px를 주고싶어서 margin과 margin top을 따로 써주신걸까요??
만약 그러시다면 margin: 20px 10px 10px 10px 이렇게 한번에 작성할 수 있을 것 같습니다~

참고하시라고 margin 방향 나눠서 작성하는 법 놓고가요!
margin : 위 오른쪽 아래 왼쪽 (시계방향)
margin : 상하 좌우 (Ex) margin: 10px 20px= 위아래 10px 양쪽 20px


export default Chat;
44 changes: 44 additions & 0 deletions src/components/Chats/ChatBoard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useRef, useEffect } from 'react';
import Chat from './Chat';
import styled from 'styled-components';
import { IChatBoard } from '../../interface';
import { listAtom } from '../../atoms';
import { useRecoilState } from 'recoil';

function ChatBoard({ roomid }: any) {
const [chatList] = useRecoilState<IChatBoard[]>(listAtom);
const chatBoardRef = useRef<HTMLDivElement>(null);

const scrollDown = () => {
if (chatBoardRef.current) {
chatBoardRef.current.scrollTop = chatBoardRef.current.scrollHeight;
}
};

useEffect(() => {
scrollDown();
}, [chatList]);

const currentChatList = chatList[roomid].msg;

return (
<ChatBoardContainer ref={chatBoardRef}>
<UserChat>
{currentChatList.map((li: any) => (
Copy link
Member

Choose a reason for hiding this comment

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

저는 map을 쓸 때 옆에 타입을 지정해주지 않았는데 혹시 이거 지정해주신 이유가 있을까요??? (혹시 썼어야하는건지 잘 몰라서요 ..!! / 혹은 제가 map을 썼을 경우와 다른 점이 있나싶어서.!)

<Chat key={li.name} name={li.name} text={li.text} />
))}
</UserChat>
</ChatBoardContainer>
);
}

const ChatBoardContainer = styled.div`
background-color: #85c1e9;
overflow: auto;
`;

const UserChat = styled.ul`
list-style: none;
`;

export default ChatBoard;
Loading