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

[5주차] 한규진 미션 제출합니다. #11

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cc6896b
feat : 기초 설정 & 데이터 설정
9yujin May 2, 2022
2f4a9d8
feat : 채팅기록 렌더링
9yujin May 3, 2022
7eece65
feat : recoil setting
9yujin May 3, 2022
0e06566
feat : getuser api
9yujin May 3, 2022
b5aee19
feat : api 디렉토리구조...
9yujin May 4, 2022
952997f
feat : sendMessage api
9yujin May 4, 2022
0fe9c05
feat : 스타일링 & 스크롤 내리기
9yujin May 4, 2022
ed4cb3c
feat : 스크롤 최하단으로 가기 버튼
9yujin May 5, 2022
786ea32
feat : 채팅 말풍선 스타일
9yujin May 5, 2022
d4d7379
feat : 사용자 전환 기능
9yujin May 5, 2022
841006d
rename : 깃에 파일 대소문자변경 반영되지 않던 오류
9yujin May 5, 2022
2adbab1
design : 매우자잘한.. 시간 띄어쓰기없애기
9yujin May 5, 2022
a8a0d70
fix: 제출전.. 경고없애기
9yujin May 5, 2022
107b6c1
refactor : react.memo 최적화
9yujin May 7, 2022
9a7bc20
feat : 페이지 라우팅 설정, 전체 구조 디자인-설정
9yujin May 9, 2022
6ae7a9a
feat : 친구목록, 채팅방 라우팅 구현
9yujin May 10, 2022
d258c45
rename ChatDataType to RoomType
9yujin May 10, 2022
a6e2e82
feat : 채팅목록 스타일링, 구현
9yujin May 10, 2022
c36c2c3
feat : 카카오로그인 구현
9yujin May 11, 2022
16ad2e7
fix : 마지막 채팅이 긴 문자열일때 프로필사진 작아지는 오류 수정
9yujin May 11, 2022
30098a7
feat : 친구목록 검색기능 구현
9yujin May 11, 2022
f2325b3
searchBox autoFocus
9yujin May 11, 2022
7e9aaf0
아맞다 border radius...
9yujin May 11, 2022
f291fd5
끝끝
9yujin May 11, 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
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "no-loops"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"],
"rules": {
"no-console": 2,
"no-loops/no-loops": 2
}
}
Comment on lines +1 to +10

Choose a reason for hiding this comment

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

👍👏

55,954 changes: 28,429 additions & 27,525 deletions package-lock.json

Large diffs are not rendered by default.

94 changes: 58 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,60 @@
{
"name": "react-messenger-15th",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
"name": "react-messenger-15th",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.1.1",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.182",
"@types/node": "^17.0.31",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"@types/styled-components": "^5.1.25",
"@types/uuid": "^8.3.4",
"dayjs": "^1.11.1",
"lodash": "^4.17.21",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-kakao-login": "^2.1.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"recoil": "^0.7.2",
"styled-components": "^5.3.5",
"styled-normalize": "^8.0.7",
"typescript": "^4.6.4",
"uuid": "^8.3.2",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"eslint": "^8.14.0",
"eslint-plugin-no-loops": "^0.3.0"
}
}
37 changes: 21 additions & 16 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<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" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<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" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700&display=swap" rel="stylesheet" />
<script src="https://developers.kakao.com/sdk/js/kakao.js"></script>
<script>
Kakao.init('1da4996513f2ad5ab840e4af1bcba99d');
Kakao.isInitialized();
</script>
<title>9yujin</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
5 changes: 0 additions & 5 deletions src/App.js

This file was deleted.

43 changes: 43 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import GlobalStyle from './styles/GlobalStyle';
import { Main } from './styles/Container';
import { RecoilRoot } from 'recoil';
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import Router from './pages/Router';
import Login from './pages/Login';
import RequireAuth from './utils/RequireAuth';
import ChatRoom from './pages/ChatRoom';

function App() {
return (
<>
<GlobalStyle />
<RecoilRoot>
<BrowserRouter>
Comment on lines +13 to +15

Choose a reason for hiding this comment

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

image

GlobalStyle, RecoilRoot, BrowserRouter는 일반적으로 src/index.tsx 에서 App을 감싸는 형태로 사용합니다.
App.tsx 리턴문 안의 컴포넌트들의 인덴팅이 과도하게 복잡해진것 같습니다.

<Main>
<Routes>
<Route path="/login" element={<Login />} />
<Route
path="/*"
element={
<RequireAuth>
<Router />
</RequireAuth>
Comment on lines +22 to +24

Choose a reason for hiding this comment

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

image
Route의 children으로 들어가는 JSX 엘리먼트(중첩 라우트)를 보여줄땐 리액트 라우터에서 제공하는 Outlet 컴포넌트를 사용합니다.

}
/>
<Route
path="/room/:roomId"
element={
<RequireAuth>
<ChatRoom />
</RequireAuth>
}
/>
</Routes>
</Main>
</BrowserRouter>
</RecoilRoot>
</>
);
}

export default App;
27 changes: 27 additions & 0 deletions src/Interface.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export interface ChatType {
userId: number;
content: string;
date: string;
like: boolean;
chatId: string;
}
export interface RoomType {
roomId: number;
user: {
userId: number;
}[];
chat: ChatType[];
}

export interface UserType {
userId: number;
userName: string;
profileImage: string;
statusMessage: string;
}

export interface AuthType {
userName: string;
profileImage: string;
init: boolean;
}
34 changes: 34 additions & 0 deletions src/api/chatRoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { SetterOrUpdater } from 'recoil';
import { RoomType, ChatType, UserType } from '../Interface';
import { getUserInfoById } from './userInfo';

// 채팅 내역 가져오기
export const getChats = (roomId: number, chatData: RoomType[]) => {
const [chatObj] = chatData.filter((room) => room.roomId === roomId);
if (!chatObj) throw new Error('존재하지 않는 ID');
return chatObj.chat;
};

// 채팅방 내 대화상대 id 가져오기
export const getUserIdListByRoom = (roomId: number, chatData: RoomType[]): number[] => {
const [chatObj] = chatData.filter((room) => room.roomId === roomId);
const userIdList = chatObj['user'].map((user) => user['userId']);
return userIdList;
};

// 채팅방 내 대화상대 정보 가져오기
export const getUserInfoListByRoomId = (roomId: number, chatData: RoomType[], userData: UserType[]): UserType[] => {
const userIdList = getUserIdListByRoom(roomId, chatData);
//const userInfoList = userData.filter((user, index) => user.userId === userIdList[index]);
const userInfoList = userIdList.map((userId) => getUserInfoById(userId, userData));
return userInfoList;
};

// 채팅보내기
export const postMessage = (roomId: number, MessageObj: ChatType, chatData: RoomType[], setChatData: SetterOrUpdater<RoomType[]>) => {
const [chatObj] = chatData.filter((room) => room.roomId === roomId);

const newChatObj: RoomType = { ...chatObj, chat: [...chatObj.chat, MessageObj] };
setChatData(chatData.map((room) => (room.roomId === roomId ? newChatObj : room)));
return { status: 200 };
};
2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './chatRoom';
export * from './userInfo';
33 changes: 33 additions & 0 deletions src/api/userInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AuthType, RoomType, UserType } from '../Interface';
import { SetterOrUpdater } from 'recoil';
// userId 로 유저 정보 가져오기
export const getUserInfoById = (userId: number, userData: UserType[]): UserType => {
const [userObj] = userData.filter((user) => user.userId === userId);
return userObj;
};

// userId로 roomId 가져오기 (갠톡)
export const getRoomIdByUser = (userId: number, chatData: RoomType[]): number => {
const [chatObj] = chatData.filter((room) => room.user[1]['userId'] === userId);
return chatObj.roomId;
};

// 로그인
export const login = (name: string, image: string, setAuth: SetterOrUpdater<AuthType>, users: UserType[], setUsers: SetterOrUpdater<UserType[]>) => {
setAuth({ userName: name, profileImage: image, init: true });
setUsers(
users.map((user) =>
user.userId === 0
? {
userId: 0,
userName: name,
profileImage: image,
statusMessage: '',
myAccount: true,
}
: user
)
);
localStorage.setItem('name', name);
localStorage.setItem('image', image);
};
3 changes: 3 additions & 0 deletions src/assets/bottom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/chat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/check.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/friends.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/threeDot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading