Skip to content

Commit

Permalink
Merge pull request #10 from MOVIEJOJO7/Feature/#7
Browse files Browse the repository at this point in the history
Feat : 모든 오픈 채팅방 목록 화면에 보여주기
  • Loading branch information
JitHoon authored Nov 9, 2023
2 parents 88b6544 + 8ddcf6c commit 971b1df
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Components/Search/FilterOpenChat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { AllOpenChat } from '@/app/search/search.type';

const FilterOpenChat = ({ initialData }: { initialData: AllOpenChat }) => {
console.log(initialData);
return (
<>
<hr />
<h2>FilterOpenChat</h2>
<hr />
</>
);
};

export default FilterOpenChat;
28 changes: 28 additions & 0 deletions Components/Search/OpenChatPicture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { User } from '@/app/search/search.type';

const OpenChatPicture = ({ openChatUsers }: { openChatUsers: User[] }) => {
let userCount = 0;

return (
<>
<ol>
{openChatUsers.map((user) => {
userCount++;

if (userCount > 4) {
return null; // 사진이 4개 이상인 경우 렌더링을 하지 않음
}

return (
<li key={user.id}>
<img src={user.picture} alt="user picture" />
</li>
);
})}
</ol>
</>
);
};

export default OpenChatPicture;
14 changes: 14 additions & 0 deletions Components/Search/OpenChatText.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Chat } from '@/app/search/search.type';

const OpenChatText = ({ openChat }: { openChat: Chat }) => {
return (
<>
<h2>{openChat.name}</h2>
<span>{openChat.users.length}</span>
<span>{openChat.updatedAt.toString()}</span>
</>
);
};

export default OpenChatText;
14 changes: 14 additions & 0 deletions Components/Search/SearchOpenChat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { AllOpenChat } from '@/app/search/search.type';

const SearchOpenChat = ({ initialData }: { initialData: AllOpenChat }) => {
console.log(initialData);
return (
<>
<hr />
<h2>SearchOpenChat</h2>
</>
);
};

export default SearchOpenChat;
20 changes: 20 additions & 0 deletions Components/Search/ShowAllOpenChat.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { AllOpenChat } from '@/app/search/search.type';
import OpenChatText from './OpenChatText';
import OpenChatPicture from './OpenChatPicture';

// 채팅방 이름, 채팅방 참여자 수, 최근 대화 시간
const ShowAllOpenChat = ({ allOpenChat }: { allOpenChat: AllOpenChat }) => {
return (
<ul>
{allOpenChat.map((openChat) => (
<li key={openChat.id}>
<OpenChatText openChat={openChat} />
<OpenChatPicture openChatUsers={openChat.users} />
</li>
))}
</ul>
);
};

export default ShowAllOpenChat;
10 changes: 7 additions & 3 deletions app/search/page.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import React from 'react';
import { fetchAllOpenChat } from './search.utils';
import SearchOpenChat from '../../Components/Search/SearchOpenChat';
import FilterOpenChat from '../../Components/Search/FilterOpenChat';
import ShowAllOpenChat from '../../Components/Search/ShowAllOpenChat';

const accessToken = process.env.ACCESSTOKEN as string; // 임시 access token
const accessToken = process.env.NEXT_PUBLIC_ACCESSTOKEN as string; // 임시 access token

const Search = async () => {
const allOpenChat = await fetchAllOpenChat(accessToken);
console.log(allOpenChat);

return (
<>
<h1>Search 페이지</h1>
<SearchOpenChat initialData={allOpenChat} />
<FilterOpenChat initialData={allOpenChat} />
<ShowAllOpenChat allOpenChat={allOpenChat} />
</>
);
};
Expand Down
6 changes: 4 additions & 2 deletions app/search/search.type.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// search.type.ts

export type AllOpenChat = Chat[];

export type AllOpenChatJSON = {
chats: AllOpenChat;
};

type Chat = {
export type Chat = {
id: string;
name: string;
users: User[];
Expand All @@ -13,7 +15,7 @@ type Chat = {
updatedAt: Date;
};

type User = {
export type User = {
id: string;
name: string;
picture: string;
Expand Down
2 changes: 1 addition & 1 deletion app/search/search.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const fetchAllOpenChat = async (accessToken: string) => {
method: GET,
headers: {
'content-type': CONTENT_TYPE,
serverId: process.env.SERVER_ID as string, // 서버 아이디 임시 사용
serverId: process.env.NEXT_PUBLIC_SERVER_ID as string, // 서버 아이디 임시 사용
Authorization: `Bearer ${accessToken}`,
},
};
Expand Down

0 comments on commit 971b1df

Please sign in to comment.