diff --git a/Components/Search/FilterOpenChat.tsx b/Components/Search/FilterOpenChat.tsx new file mode 100644 index 0000000..c98f940 --- /dev/null +++ b/Components/Search/FilterOpenChat.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import { AllOpenChat } from '@/app/search/search.type'; + +const FilterOpenChat = ({ initialData }: { initialData: AllOpenChat }) => { + console.log(initialData); + return ( + <> +
+

FilterOpenChat

+
+ + ); +}; + +export default FilterOpenChat; diff --git a/Components/Search/OpenChatPicture.tsx b/Components/Search/OpenChatPicture.tsx new file mode 100644 index 0000000..94ffe97 --- /dev/null +++ b/Components/Search/OpenChatPicture.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { User } from '@/app/search/search.type'; + +const OpenChatPicture = ({ openChatUsers }: { openChatUsers: User[] }) => { + let userCount = 0; + + return ( + <> +
    + {openChatUsers.map((user) => { + userCount++; + + if (userCount > 4) { + return null; // 사진이 4개 이상인 경우 렌더링을 하지 않음 + } + + return ( +
  1. + user picture +
  2. + ); + })} +
+ + ); +}; + +export default OpenChatPicture; diff --git a/Components/Search/OpenChatText.tsx b/Components/Search/OpenChatText.tsx new file mode 100644 index 0000000..291e6a3 --- /dev/null +++ b/Components/Search/OpenChatText.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { Chat } from '@/app/search/search.type'; + +const OpenChatText = ({ openChat }: { openChat: Chat }) => { + return ( + <> +

{openChat.name}

+ {openChat.users.length} + {openChat.updatedAt.toString()} + + ); +}; + +export default OpenChatText; diff --git a/Components/Search/SearchOpenChat.tsx b/Components/Search/SearchOpenChat.tsx new file mode 100644 index 0000000..7185aac --- /dev/null +++ b/Components/Search/SearchOpenChat.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { AllOpenChat } from '@/app/search/search.type'; + +const SearchOpenChat = ({ initialData }: { initialData: AllOpenChat }) => { + console.log(initialData); + return ( + <> +
+

SearchOpenChat

+ + ); +}; + +export default SearchOpenChat; diff --git a/Components/Search/ShowAllOpenChat.tsx b/Components/Search/ShowAllOpenChat.tsx new file mode 100644 index 0000000..15e91d3 --- /dev/null +++ b/Components/Search/ShowAllOpenChat.tsx @@ -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 ( + + ); +}; + +export default ShowAllOpenChat; diff --git a/app/search/page.tsx b/app/search/page.tsx index c01a8b1..c1d1d4f 100644 --- a/app/search/page.tsx +++ b/app/search/page.tsx @@ -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 ( <> -

Search 페이지

+ + + ); }; diff --git a/app/search/search.type.ts b/app/search/search.type.ts index ca070aa..8b42afd 100644 --- a/app/search/search.type.ts +++ b/app/search/search.type.ts @@ -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[]; @@ -13,7 +15,7 @@ type Chat = { updatedAt: Date; }; -type User = { +export type User = { id: string; name: string; picture: string; diff --git a/app/search/search.utils.ts b/app/search/search.utils.ts index 01af8c8..427ce2e 100644 --- a/app/search/search.utils.ts +++ b/app/search/search.utils.ts @@ -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}`, }, };