-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat : 모든 오픈 채팅방 목록 불러오기
- Loading branch information
Showing
13 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react'; | ||
|
||
const Wrapper = ({ children }: { children: React.ReactNode }) => { | ||
return ( | ||
<section className="w-full sm:w-[425px] md:w-[645px] px-5 h-screen flex flex-col mx-auto bg-orange-300"> | ||
<header className="flex h-10 justify-between items-center bg-blue-700"> | ||
헤더 | ||
</header> | ||
{children} | ||
</section> | ||
); | ||
}; | ||
|
||
export default Wrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const 문자열 = '문자열'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export type 모든것 = { | ||
name: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const fetchAllChat = async (token: string, userId: string) => { | ||
const res = await fetch('https://fastcampus-chat.net/chat', { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token}`, | ||
serverId: process.env.SERVER_KEY as string, | ||
}, | ||
}); | ||
const data = await res.json(); | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { fetchAllChat } from './open.utils'; | ||
|
||
type ChatData = { | ||
id: string; | ||
name: string; | ||
users: string[]; | ||
isPrivate: boolean; | ||
latestMessage: string; | ||
updatedAt: string; | ||
}; | ||
|
||
const Open = async () => { | ||
const accessToken = process.env.ACCESS_TOKEN as string; | ||
const result = await fetchAllChat(accessToken, 'minseob'); | ||
console.log(result); | ||
return ( | ||
<div className="flex flex-col bg-red-300"> | ||
{result.chats.map((chat: ChatData) => { | ||
return ( | ||
<div key={chat.id}> | ||
<div>{chat.name}</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default Open; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { fetchAllOpenChat } from './search.utils'; | ||
|
||
const accessToken = process.env.ACCESSTOKEN as string; // 임시 access token | ||
|
||
const Search = async () => { | ||
const allOpenChat = await fetchAllOpenChat(accessToken); | ||
console.log(allOpenChat); | ||
|
||
return ( | ||
<> | ||
<h1>Search 페이지</h1> | ||
</> | ||
); | ||
}; | ||
|
||
export default Search; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// http Method | ||
export const GET = 'GET'; | ||
|
||
// API URL | ||
export const BASE_URL = 'https://fastcampus-chat.net/'; | ||
export const GET_CHAT_ALL = 'chat/all'; | ||
|
||
// API Request 조건 정보 | ||
export const CONTENT_TYPE = 'application/json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export type AllOpenChat = Chat[]; | ||
|
||
export type AllOpenChatJSON = { | ||
chats: AllOpenChat; | ||
}; | ||
|
||
type Chat = { | ||
id: string; | ||
name: string; | ||
users: User[]; | ||
isPrivate: boolean; | ||
latestMessage: Message | null; | ||
updatedAt: Date; | ||
}; | ||
|
||
type User = { | ||
id: string; | ||
name: string; | ||
picture: string; | ||
}; | ||
|
||
type Message = { | ||
id: string; | ||
text: string; | ||
userId: string; | ||
createAt: Date; | ||
}; | ||
|
||
export type Request = { | ||
method: string; | ||
headers: { | ||
'content-type': string; | ||
serverId: string; | ||
Authorization: string; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Request, AllOpenChatJSON, AllOpenChat } from './search.type'; | ||
import { GET, CONTENT_TYPE, BASE_URL, GET_CHAT_ALL } from './search.constant'; | ||
|
||
export const fetchAllOpenChat = async (accessToken: string) => { | ||
const Request: Request = { | ||
method: GET, | ||
headers: { | ||
'content-type': CONTENT_TYPE, | ||
serverId: process.env.SERVER_ID as string, // 서버 아이디 임시 사용 | ||
Authorization: `Bearer ${accessToken}`, | ||
}, | ||
}; | ||
|
||
const res = await fetch(`${BASE_URL}${GET_CHAT_ALL}`, Request); | ||
const resJson: AllOpenChatJSON = await res.json(); | ||
const allOpenChat: AllOpenChat = resJson.chats; | ||
|
||
return allOpenChat; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters