Skip to content

Commit

Permalink
Merge pull request #331 from depromeet/feat/#330
Browse files Browse the repository at this point in the history
#330 feat: follow layout api call 수정
  • Loading branch information
YelynnOh authored Apr 13, 2024
2 parents 3ef0349 + b7b5c6b commit 04185ab
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 186 deletions.
7 changes: 5 additions & 2 deletions src/app/follow/[id]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import { useRouter } from 'next/navigation';
import { usePathname, useRouter } from 'next/navigation';
import { ReactNode } from 'react';

import Header from '@components/common/Header';
Expand All @@ -12,7 +12,10 @@ export default function Layout({ children }: { children: ReactNode }) {
router.back();
};

const { data: userProfile } = useGetUserProfile();
const pathname = usePathname();
const userId = Number(pathname.split('/').pop());

const { data: userProfile } = useGetUserProfile(Number(userId));

return (
<main className="w-full max-w-[480px] h-[100dvh]">
Expand Down
2 changes: 1 addition & 1 deletion src/app/follow/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function Page() {
const type = searchParams.get('type');

const { data: followerList } = useGetFollowingList(userId, 'FOLLOWER');
const { data: followingList } = useGetFollowingList(userId, 'FOLLOWER');
const { data: followingList } = useGetFollowingList(userId, 'FOLLOWING');

return (
<div>
Expand Down
63 changes: 0 additions & 63 deletions src/app/mypage/layout.tsx

This file was deleted.

114 changes: 0 additions & 114 deletions src/app/mypage/page.tsx

This file was deleted.

19 changes: 13 additions & 6 deletions src/hooks/api/useGetUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import { AxiosError } from 'axios';
import { ApiResponse, axiosRequest } from '../../api/api-config';

export interface UserInfo {
nickname: string;
level: '맨밥이' | '배고픈' | '또밥이' | '또또밥이';
isMine: boolean;
userId: number;
profileImgUrl: string;
nickname: string;
feedCnt: number;
follwerCnt: number;
followingCnt: number;
isFollowed: boolean;
}

const getUserProfile = (): Promise<ApiResponse<UserInfo>> => {
return axiosRequest('get', '/api/v1/users/profile');
const getUserProfile = (userId: number): Promise<ApiResponse<UserInfo>> => {
return axiosRequest('get', `/api/v1/profile/${userId}`);
};

export const useGetUserProfile = (): UseQueryResult<UserInfo, AxiosError> => {
export const useGetUserProfile = (
userId: number,
): UseQueryResult<UserInfo, AxiosError> => {
return useQuery({
queryKey: ['get-userProfile'],
queryFn: getUserProfile,
queryFn: () => getUserProfile(userId),
select: (data) => data.data,
});
};

0 comments on commit 04185ab

Please sign in to comment.