Skip to content

Commit df4cea7

Browse files
authored
Merge pull request #8 from Toy2-team10/TALK-4--feat/chatList
Feat: 채팅방 목록 조회 기능 구현
2 parents b9b2eca + cd961dc commit df4cea7

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

apis/axios.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import axios from 'axios';
22

3+
const accessToken =
4+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNiN2ZiMTExZTp1c2VyMyIsImlhdCI6MTY5OTUzMzExMiwiZXhwIjoxNzAwMTM3OTEyfQ.4eslctzcBGQAwkcKT97IbF0i-9-MZ0kvhjY4A6sK8Wo';
5+
36
const instance = axios.create({
47
baseURL: 'https://fastcampus-chat.net',
58
// 여기에 공통 설정을 추가할 수 있습니다.
69
headers: {
710
'Content-Type': 'application/json',
11+
Authorization: `Bearer ${accessToken}`,
812
serverId: process.env.NEXT_PUBLIC_API_KEY,
913
},
1014
});

apis/chatListAPI.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import instance from './axios';
2+
3+
const chatListAPI = {
4+
// 로그인
5+
getAllChatList() {
6+
return instance.get('/chat/all');
7+
},
8+
// 회원가입
9+
getMyChatList() {
10+
return instance.get('/chat');
11+
},
12+
};
13+
14+
export default chatListAPI;

pages/all-chat-list/chatList.module.scss

Whitespace-only changes.

pages/all-chat-list/index.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useState, useEffect } from 'react';
2+
import Link from 'next/link';
3+
import chatListAPI from '../../apis/chatListAPI';
4+
5+
export default function AllChatList() {
6+
const [allChatList, setAllChatList] = useState([]);
7+
const getAllChat = async () => {
8+
const chatAllList = await chatListAPI.getAllChatList();
9+
setAllChatList(chatAllList.data.chats);
10+
};
11+
useEffect(() => {
12+
getAllChat();
13+
}, []);
14+
return (
15+
<>
16+
{allChatList.map(chat => (
17+
<Link href={`/chat/${chat.id}`} key={chat.id}>
18+
<div>{chat.name}</div>
19+
</Link>
20+
))}
21+
</>
22+
);
23+
}

pages/my-chat-list/MyChatList.module.scss

Whitespace-only changes.

pages/my-chat-list/index.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useState, useEffect } from 'react';
2+
import Link from 'next/link';
3+
import chatListAPI from '../../apis/chatListAPI';
4+
5+
export default function MyChatList() {
6+
const [myChatList, setMyChatList] = useState([]);
7+
const getMyChat = async () => {
8+
const ChatMyList = await chatListAPI.getMyChatList();
9+
setMyChatList(ChatMyList.data.chats);
10+
};
11+
useEffect(() => {
12+
getMyChat();
13+
}, []);
14+
return (
15+
<>
16+
{myChatList.map(chat => (
17+
<Link href={`/chat/${chat.id}`} key={chat.id}>
18+
<div>{chat.name}</div>
19+
</Link>
20+
))}
21+
</>
22+
);
23+
}

0 commit comments

Comments
 (0)