diff --git a/src/api/ConnectionApi.tsx b/src/api/ConnectionApi.tsx index 0bf5ac4..39dbd21 100644 --- a/src/api/ConnectionApi.tsx +++ b/src/api/ConnectionApi.tsx @@ -7,13 +7,7 @@ export const getFollowersList = async ( size: number ): Promise => { try { - const response = await axiosInstance.get(`/member/follow?page=${page}&size=${size}`, { - params: { - page: page, - size: size, - }, - }); - console.log('내 친구 목록', response.data); + const response = await axiosInstance.get(`/member/follow?page=${page}&size=${size}`); return response.data.data; } catch (error) { console.error('Error fetching data:', error); @@ -31,10 +25,29 @@ export const getSearchFriendsList = async ( const response = await axiosInstance.get( `/member/follow/search/all?keyword=${keyword}&page=${page}&size=${size}` ); - console.log('검색 친구 목록', response.data); return { - followInfoResDto: response.data.data.memberInfoForFollowResDtos, // 원하는 필드 이름으로 매핑 + followInfoResDto: response.data.data.memberInfoForFollowResDtos, + pageInfoResDto: response.data.data.pageInfoResDto, + }; + } catch (error) { + console.error('Error fetching data:', error); + return null; + } +}; + +// * 추천 친구 get +export const getRecommendedFriendsList = async ( + page: number, + size: number +): Promise => { + try { + const response = await axiosInstance.get( + `/member/follow/recommended?page=${page}&size=${size}` + ); + + return { + followInfoResDto: response.data.data.recommendedFollowInfoResDtos, pageInfoResDto: response.data.data.pageInfoResDto, }; } catch (error) { diff --git a/src/hooks/useFollowersList.ts b/src/hooks/useFollowersList.ts index 7b58785..b312031 100644 --- a/src/hooks/useFollowersList.ts +++ b/src/hooks/useFollowersList.ts @@ -1,6 +1,10 @@ import { useQuery } from '@tanstack/react-query'; import { FollowersListData } from '../types/ConnectionType'; -import { getFollowersList, getSearchFriendsList } from '../api/ConnectionApi'; +import { + getFollowersList, + getRecommendedFriendsList, + getSearchFriendsList, +} from '../api/ConnectionApi'; export const useFollowersList = (page: number, size: number) => { return useQuery({ @@ -17,3 +21,11 @@ export const useSearchFriendsList = (keyword: string, page: number, size: number staleTime: 1000 * 60 * 5, }); }; + +export const useRecommendFriendsList = (page: number, size: number) => { + return useQuery({ + queryKey: ['followersList', page, size], + queryFn: () => getRecommendedFriendsList(page, size), + staleTime: 1000 * 60 * 5, + }); +}; diff --git a/src/pages/ConnectionsPage/ConnectionsPage.tsx b/src/pages/ConnectionsPage/ConnectionsPage.tsx index 094e838..2e9e9ff 100644 --- a/src/pages/ConnectionsPage/ConnectionsPage.tsx +++ b/src/pages/ConnectionsPage/ConnectionsPage.tsx @@ -6,7 +6,7 @@ import leftarrow from '../../img/leftarrow.png'; import Connection from '../../components/Connection/Connection'; import Pagination from '../../components/CustomPagination'; import { useNavigate } from 'react-router-dom'; -import { useFollowersList } from '../../hooks/useFollowersList'; +import { useFollowersList, useRecommendFriendsList } from '../../hooks/useFollowersList'; import { useState } from 'react'; const ConnectionsPage = () => { @@ -14,7 +14,7 @@ const ConnectionsPage = () => { const [currentPage, setCurrentPage] = useState(0); const { data: followersList } = useFollowersList(currentPage, 8); - console.log(followersList); + const { data: recommendList } = useRecommendFriendsList(currentPage, 10); // * 페이지네이션 페이지 변경 감지 함수 const handleChangePage = (event: React.ChangeEvent, value: number) => { @@ -41,18 +41,20 @@ const ConnectionsPage = () => { + + {followersList?.followInfoResDto.length == 0 ?

추천 친구

:

내 친구 목록

} +
+ - {followersList?.followInfoResDto.map((follower, index) => ( - - ))} + {followersList?.followInfoResDto.length === 0 + ? recommendList?.followInfoResDto.map((follower, index) => ( + + )) + : followersList?.followInfoResDto.map((follower, index) => ( + + ))} - {followersList?.followInfoResDto.length == 0 && ( - -

친구가 없습니다.

-
- )} - {followersList?.followInfoResDto.length !== 0 && (