Skip to content

Commit 1834599

Browse files
committed
feat: 유저 페이지 구현
1 parent 02acc8d commit 1834599

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

src/pages/userpage/UserPage.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Loading } from '@/components/loading';
2+
import { Outlet, useParams } from 'react-router';
3+
import { useInfiniteUserEmotionRecords, useUserProfileInfo } from '@/pages/userpage/hooks';
4+
import { UserEmotionRecordSection, UserProfileSection } from '@/pages/userpage/components';
5+
6+
export default function UserPage() {
7+
const userId = useParams().userId!;
8+
const { isLoading: isProfileLoading } = useUserProfileInfo(userId); // 유저 정보 가져오기
9+
const { isLoading: isEmotionRecordsLoading } = useInfiniteUserEmotionRecords(userId);
10+
return (
11+
<>
12+
<div className="flex flex-col items-center w-full h-full gap-5 py-4">
13+
<UserProfileSection userId={userId} />
14+
<UserEmotionRecordSection userId={userId} />
15+
</div>
16+
{(isProfileLoading || isEmotionRecordsLoading) && <Loading />}
17+
<Outlet />
18+
</>
19+
);
20+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { EmotionRecordSection } from '@/components';
2+
import { useInfiniteUserEmotionRecords } from '@/pages/userpage/hooks';
3+
4+
interface UserEmotionRecordSectionProps {
5+
userId: string;
6+
}
7+
8+
const UserEmotionRecordSection = ({ userId }: UserEmotionRecordSectionProps) => {
9+
const {
10+
data, // 불러온 감정 기록 페이지 데이터
11+
fetchNextPage, // 다음 페이지 데이터를 불러오는 함수
12+
hasNextPage, // 다음 페이지가 존재하는지 여부 (boolean)
13+
isFetchingNextPage, // 다음 페이지를 현재 불러오고 있는 중인지 여부 (boolean)
14+
} = useInfiniteUserEmotionRecords(userId);
15+
16+
const records = data?.pages.flatMap((page) => page.data.records) ?? [];
17+
18+
return (
19+
<EmotionRecordSection
20+
records={records}
21+
fetchNextPage={fetchNextPage}
22+
hasNextPage={hasNextPage}
23+
isFetchingNextPage={isFetchingNextPage}
24+
/>
25+
);
26+
};
27+
28+
export default UserEmotionRecordSection;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { UserProfileCard } from '@/components';
2+
import { useUserProfileInfo } from '@/pages/userpage/hooks';
3+
4+
interface UserProfileSectionProps {
5+
userId: string;
6+
}
7+
8+
const UserProfileSection = ({ userId }: UserProfileSectionProps) => {
9+
// 유저 정보 가져오기
10+
const { data: userData } = useUserProfileInfo(userId);
11+
12+
return <UserProfileCard userData={userData} />;
13+
};
14+
15+
export default UserProfileSection;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import UserEmotionRecordSection from './UserEmotionRecordSection';
2+
import UserProfileSection from './UserProfileSection';
3+
4+
export { UserProfileSection, UserEmotionRecordSection };

src/pages/userpage/hooks/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { useInfiniteUserEmotionRecords } from './useInfiniteUserEmotionRecords';
2+
import { useUserProfileInfo } from './useUserProfileInfo';
3+
4+
export { useUserProfileInfo, useInfiniteUserEmotionRecords };
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { getUserEmotionRecords } from '@/apis/emotionRecord';
2+
import { useInfiniteQuery } from '@tanstack/react-query';
3+
4+
export const useInfiniteUserEmotionRecords = (userId: string) => {
5+
return useInfiniteQuery({
6+
queryKey: ['userPosts', userId],
7+
queryFn: ({ pageParam = 1 }) => getUserEmotionRecords(userId, pageParam),
8+
getNextPageParam: (last) => {
9+
if (last.data.currentPage < last.data.totalPages) {
10+
return last.data.currentPage + 1;
11+
}
12+
return undefined;
13+
},
14+
initialPageParam: 1,
15+
staleTime: 5 * 60 * 1000,
16+
});
17+
};

0 commit comments

Comments
 (0)