Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#107] Feat: 유저페이지 구현 #132

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d5c5ca4
fix: 프로필페이지 구조 변경
HoberMin Jun 16, 2024
981c89d
feat: 마이페이지 구현
HoberMin Jun 16, 2024
d50632b
refactor: GNB를 레이아웃에서 페이지로 이동
HoberMin Jun 16, 2024
058d47a
fix: 레거시 코드 삭제
HoberMin Jun 16, 2024
7496c29
feat: user페이지의 공통 컴포넌트로 변경
HoberMin Jun 16, 2024
fd2df94
chore: 타입선언 및 모듈 수정
HoberMin Jun 16, 2024
eba5062
feat: 접근자 권한에 따른 강제 라우팅처리
HoberMin Jun 16, 2024
a53fff9
feat: 타 사용자 유저페이지 UI 구현
HoberMin Jun 16, 2024
698abf3
feat: 마이페이지 라우팅 코드 추가
HoberMin Jun 18, 2024
d31f219
feat: 팔로우 api 추가
HoberMin Jun 18, 2024
5130e71
feat: pathname에 따른 화면 조회 변경
HoberMin Jun 19, 2024
c79570e
fix: build 오류 수정
HoberMin Jun 19, 2024
e8297d6
feat: 프로필 페이지 로그인 로직 추가
HoberMin Jun 19, 2024
9cfbb7f
refactor: 프로필 조회 API 타입 수정
HoberMin Jun 21, 2024
5a2367e
refactor: 빈 화면 컴포넌트에 대한 수정
HoberMin Jun 21, 2024
ddf209e
fix: 레거시 코드 삭제
HoberMin Jun 21, 2024
42a8f17
refactor: 닉네임 없는 게시글 아이템으로 리팩토링
HoberMin Jun 21, 2024
d2c7ca5
feat: 유저 팔로우 로직 추가
HoberMin Jun 21, 2024
d756f22
style: CSS 변경
HoberMin Jun 21, 2024
df099a0
feat: 게시글 목록 리스트 구현 - 프로필 페이지별 사용 목적
HoberMin Jun 21, 2024
31eb374
fix: GNB 컴포넌트 하이라이팅 변경
HoberMin Jun 22, 2024
24533c7
style: GNB컴포너트 스타일링 변경
HoberMin Jun 22, 2024
b961728
feat: 로그아웃 API 연결 추가
HoberMin Jun 22, 2024
9e216ef
refactor: 코드리뷰 반영
HoberMin Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions public/icon-sprite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions src/apis/follow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { api } from './core';

const postFollow = (userId: string) => {
return api.post({
url: `/follow/${userId}`,
});
};

const deleteFollow = (userId: string) => {
return api.delete({
url: `/unfollow/${userId}`,
});
};

export const usePostFollowAPI = (userId: string) => {
const QueryClient = useQueryClient();
const { mutateAsync } = useMutation({
mutationFn: () => postFollow(userId),
onSuccess: () =>
QueryClient.invalidateQueries({
queryKey: ['profile', userId],
}),
});

return mutateAsync;
};

export const useDeleteFollowAPI = (userId: string) => {
const QueryClient = useQueryClient();

const { mutateAsync } = useMutation({
mutationFn: () => deleteFollow(userId),
onSuccess: () =>
QueryClient.invalidateQueries({
queryKey: ['profile', userId],
}),
});

return mutateAsync;
};
17 changes: 17 additions & 0 deletions src/apis/logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useMutation } from '@tanstack/react-query';

import { api } from './core';

const logout = () => {
return api.post({
url: `/user/logout`,
});
};

export const useLogoutAPI = () => {
const { mutateAsync } = useMutation({
mutationFn: () => logout(),
});

return mutateAsync;
};
4 changes: 2 additions & 2 deletions src/apis/myInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import { api } from './core';
// return data;
// };

interface UserStatus {
interface GetUserStatusResponse {
userId: number;
nickname: string;
profileImage: string | null;
login: boolean;
}

const getUserStatus = () => {
return api.get<UserStatus>({
return api.get<GetUserStatusResponse>({
url: `/user/status`,
});
};
Expand Down
73 changes: 73 additions & 0 deletions src/apis/posting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { PostingNavigation } from '@/src/app/users/profile/(posting)/layout';

import { api } from '../core';

export interface PostListContent {
postId: number;
voteId: number;
title: string;
commentCount: number;
likeCount: number;
voterCount: number;
author: string;
profileImageUrl: string | null;
postImageUrl: string | null;
createdAt: string;
}

interface PostListPageable {
pageNumber: number;
pageSize: number;
sort: PostListSort;
offset: number;
paged: boolean;
unpaged: boolean;
}

interface PostListSort {
empty: boolean;
unsorted: boolean;
sorted: boolean;
}

export interface PostList {
content: PostListContent[];
pageable: PostListPageable;
last: boolean;
totalPages: number;
totalElements: number;
first: boolean;
size: number;
number: number;
sort: PostListSort;
numberOfElements: number;
empty: boolean;
}

export interface PostListInitialParams {
page: number;
size: number;
}

export const getPosting = async (
params: PostListInitialParams,
category: PostingNavigation,
) =>
await api.get<PostList>({
url: `/posts/${category}`,
params,
});

export const useGetPostingAPI = (
params: PostListInitialParams,
category: PostingNavigation,
) => {
const { data } = useSuspenseQuery({
queryKey: ['postList', category, ...Object.values(params)],
queryFn: () => getPosting(params, category),
});

return data.body;
};
39 changes: 34 additions & 5 deletions src/apis/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,44 @@ import { useSuspenseQuery } from '@tanstack/react-query';

import { api } from './core';

interface ProfileResponse {
// interface ProfileResponse {
// email: string;
// nickname: string;
// profileImageUrl: string;
// introduction: string;
// createdAt: string;
// updatedAt: string;
// followerCount: number;
// followeeCount: number;
// }

export interface Body {
userId: number;
email: string;
nickname: string;
profileImageUrl: string;
introduction: string;
createdAt: string;
updatedAt: string;
postCount: number;
followerCount: number;
followeeCount: number;
isFollowing: boolean;
posts: Post[];
}

export interface Post {
postId: number;
voteId: number;
title: string;
commentCount: number;
likeCount: number;
voterCount: number;
author: string;
profileImageUrl: string;
postImageUrl: string;
createdAt: string;
startDate: string;
endDate: string;
voteOptions: string[];
terminated: boolean;
}

// export const getProfile = async (userId: string) => {
Expand All @@ -23,7 +52,7 @@ interface ProfileResponse {
// };

const getProfile = (userId: string) => {
return api.get<ProfileResponse>({
return api.get<Body>({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Body보다 더 구체적인 변수명이면 좋을 거 같은데 어떠신가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네네 그렇게 할게요 ! 병합하는과정에서 꼬인게 있나봅니다..

url: `/user/${userId}`,
});
};
Expand Down
7 changes: 5 additions & 2 deletions src/app/_components/PostItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { isValidImageUrl } from '@/src/utils/isValidImageUrl';

interface PostItemProps {
post: PostListContent;
isNickname?: boolean;
}

const PostItem = ({ post }: PostItemProps) => {
const PostItem = ({ post, isNickname = true }: PostItemProps) => {
const {
title,
voterCount: votedCount,
Expand All @@ -33,7 +34,9 @@ const PostItem = ({ post }: PostItemProps) => {
</div>
<div className='flex items-center gap-4'>
<span className='font-text-3-rg flex items-center gap-2'>
<span>{author}</span>
{isNickname ? (
<span className='font-text-3-rg'>{author}</span>
) : null}
<span className='text-gray-accent3'>{createdAt}</span>
</span>
<span className='flex items-center gap-2 text-gray-accent4'>
Expand Down
2 changes: 1 addition & 1 deletion src/app/notification/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const Notification = () => {
<TopBar.Container>
<p className='font-h2-sm'>알림</p>
</TopBar.Container>
<main className='h-full grow overflow-y-scroll'>
<main className='grow overflow-y-scroll'>
{ALARM_DUMMY.length === 0 ? (
<div className='flex h-full flex-col items-center justify-center gap-2 text-white'>
<Icon id='warning' aria-label='알림이 없습니다.' size={64} />
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const Main = () => {
</Link>
))
) : (
<EmptyPage />
<EmptyPage text='작성된 투표 글이 없습니다.' />
)}
</main>
<GNB />
Expand Down
60 changes: 0 additions & 60 deletions src/app/profile/[userId]/_components/ActiveGrass.tsx

This file was deleted.

Loading
Loading