Skip to content

Commit

Permalink
Merge pull request #6 from MOVIEJOJO7/Feature/#5
Browse files Browse the repository at this point in the history
Feat : 모든 오픈 채팅방 목록 불러오기
  • Loading branch information
JitHoon authored Nov 9, 2023
2 parents c6b95f1 + 5265eee commit e6f751b
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Components/Wrapper.tsx
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;
7 changes: 6 additions & 1 deletion app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';
import ClientProviders from '@/Components/Provider/ClientProvider';
import Wrapper from '@/Components/Wrapper';

const inter = Inter({ subsets: ['latin'] });

Expand All @@ -18,7 +19,11 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<ClientProviders>{children}</ClientProviders>
<ClientProviders>
<div className="bg-gray-500 h-screen">
<Wrapper>{children}</Wrapper>
</div>
</ClientProviders>
</body>
</html>
);
Expand Down
1 change: 1 addition & 0 deletions app/open/open.constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const 문자열 = '문자열';
3 changes: 3 additions & 0 deletions app/open/open.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type 모든것 = {
name: string;
};
12 changes: 12 additions & 0 deletions app/open/open.utils.ts
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;
};
30 changes: 30 additions & 0 deletions app/open/page.tsx
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;
17 changes: 17 additions & 0 deletions app/search/page.tsx
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;
9 changes: 9 additions & 0 deletions app/search/search.constant.ts
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';
36 changes: 36 additions & 0 deletions app/search/search.type.ts
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;
};
};
19 changes: 19 additions & 0 deletions app/search/search.utils.ts
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;
};
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"next": "14.0.1",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.48.2",
"recoil": "^0.7.7",
"socket.io": "^4.7.2"
},
Expand Down
5 changes: 5 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ const config: Config = withMT({
'path-to-your-node_modules/@material-tailwind/react/theme/components/**/*.{js,ts,jsx,tsx}',
],
theme: {
screens: {
sm: '425px',
md: '768px',
lg: '1024px',
},
extend: {
colors: {
primary: '#FF6363',
Expand Down

0 comments on commit e6f751b

Please sign in to comment.