Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nodak-v2/Nodak-FE into #182/…
Browse files Browse the repository at this point in the history
…feat/mutation-handling/hj
  • Loading branch information
hyeonjinan096 committed Jul 24, 2024
2 parents e8d45fb + f166df0 commit 174f8b8
Show file tree
Hide file tree
Showing 66 changed files with 645 additions and 369 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"lodash": "^4.17.21",
"next": "14.2.1",
"next-pwa": "^5.6.0",
"path-to-regexp": "^7.1.0",
"react": "^18",
"react-dom": "^18",
"react-hook-form": "^7.51.4",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed public/default-image.png
Binary file not shown.
Binary file removed public/picky/user-square.png
Binary file not shown.
Binary file removed public/user-profile.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/apis/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const HTTP_METHODS = {
DELETE: 'delete',
} as const;

const TIME_OUT = 2000;
const TIME_OUT = 5000;

const axiosInstance = axios.create({
baseURL: `${process.env.NEXT_PUBLIC_API_URL}`,
Expand Down
20 changes: 16 additions & 4 deletions src/apis/follow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const deleteFollow = (userId: string) => {
});
};

export const usePostFollowAPI = (userId: string) => {
export const usePostFollowAPI = (userId: string, myId: string) => {
const queryClient = useQueryClient();

const { mutateAsync } = useMutation({
Expand All @@ -75,15 +75,21 @@ export const usePostFollowAPI = (userId: string) => {
queryKey: ['profile', userId],
});
queryClient.invalidateQueries({
queryKey: ['followees', userId],
queryKey: ['profile', myId],
});
queryClient.invalidateQueries({
queryKey: ['followees', myId],
});
queryClient.invalidateQueries({
queryKey: ['followers', myId],
});
},
});

return mutateAsync;
};

export const useDeleteFollowAPI = (userId: string) => {
export const useDeleteFollowAPI = (userId: string, myId: string) => {
const queryClient = useQueryClient();

const { mutateAsync } = useMutation({
Expand All @@ -93,7 +99,13 @@ export const useDeleteFollowAPI = (userId: string) => {
queryKey: ['profile', userId],
});
queryClient.invalidateQueries({
queryKey: ['followees', userId],
queryKey: ['profile', myId],
});
queryClient.invalidateQueries({
queryKey: ['followees', myId],
});
queryClient.invalidateQueries({
queryKey: ['followers', myId],
});
},
});
Expand Down
31 changes: 31 additions & 0 deletions src/apis/notification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useQuery } from '@tanstack/react-query';

import { api } from '@/src/apis/core';

export interface Notification {
type: 'POST' | 'FOLLOW';
followerId?: number;
followerName?: string;
writerId?: number;
writerName?: string;
postId?: number;
timestamp: number;
}

const getNotifications = () => {
return api.get<Notification[]>({
url: '/notifications',
});
};

const INTERVAL_MS = 5000;

export const useGetNotificationsAPI = () => {
const { data } = useQuery({
queryKey: ['notifications'],
queryFn: getNotifications,
refetchInterval: INTERVAL_MS,
});

return data?.body;
};
3 changes: 2 additions & 1 deletion src/apis/postDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

import Toast from '@/src/components/Toast';

import { ChannelTypeOfKorean } from '../app/(post)/result/[postId]/_components/Posting/PostingButton';
import { api } from './core';

interface PostDetailBody {
Expand All @@ -18,7 +19,7 @@ interface PostDetailBody {
content: string;
starCount: number;
checkStar: boolean;
categoryName: string;
categoryName: ChannelTypeOfKorean;
}

const getPostDetail = (postId: string) => {
Expand Down
3 changes: 2 additions & 1 deletion src/app/(auth)/signin/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Image from 'next/image';
import Link from 'next/link';

import { BASE_URL } from '@/src/apis/constants';
import Icon from '@/src/components/Icon';
import TopBar from '@/src/components/Topbar';

Expand All @@ -19,7 +20,7 @@ const Signin = () => {
<span className='font-h3-sm'>{SLOGAN}</span>
</div>
<div className='sticky mb-[60px] h-[44px] min-w-full'>
<Link href='https://api.nodak.link/oauth2/authorization/kakao'>
<Link href={`${BASE_URL}/oauth2/authorization/kakao`}>
<Image
src='/picky/kakao.svg'
alt='kakao'
Expand Down
14 changes: 12 additions & 2 deletions src/app/(post)/createPost/_components/PostForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use client';

import { useRouter } from 'next/navigation';
import { useRouter, useSearchParams } from 'next/navigation';
import { Controller, useForm } from 'react-hook-form';

import { PostRequestBody } from '@/src/apis/createPost';
import VoteForm from '@/src/app/(post)/createPost/_components/VoteForm';
import { ChannelTypeOfKorean } from '@/src/app/_components/ChipContainer';
import {
ChannelType,
ChannelTypeOfKorean,
channelToKoreanMap,
} from '@/src/app/_components/ChipContainer';
import Button from '@/src/components/Button/Button';
import FormField from '@/src/components/FormField';
import Selector from '@/src/components/Selector';
Expand All @@ -26,6 +30,11 @@ const channels: Array<ChannelTypeOfKorean> = [
];

const PostForm = () => {
const searchParams = useSearchParams();
const channel = searchParams.get('channel') as ChannelType;

const koreanChannel = channelToKoreanMap[channel];

const {
register,
handleSubmit,
Expand Down Expand Up @@ -106,6 +115,7 @@ const PostForm = () => {
<Selector
items={channels}
placeholder='채널 선택'
defaultValue={koreanChannel}
onChange={field.onChange}
variant={errors.channel ? 'error' : 'default'}
/>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(post)/createPost/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useRouter } from 'next/navigation';

import { useGetUserStatusAPI } from '@/src/apis/myInfo';
import Toast from '@/src/components/Toast';
import TopBar from '@/src/components/Topbar';

import TopBar from '../../../components/Topbar';
import PostForm from './_components/PostForm';

const CreatePostPage = () => {
Expand All @@ -20,7 +20,7 @@ const CreatePostPage = () => {
return (
<>
<TopBar.Container>
<TopBar.BackButton href='/' />
<TopBar.BackButton />
<TopBar.Title>투표 만들기</TopBar.Title>
</TopBar.Container>
<PostForm />
Expand Down
43 changes: 0 additions & 43 deletions src/app/(post)/result/[postId]/_components/CommentInput/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ interface CommentReplyItemProps {
}

const CommentReplyItem = ({ comment }: CommentReplyItemProps) => {
const { replyId, nickname, content, createdAt, userId: authorId } = comment;
const {
replyId,
nickname,
content,
createdAt,
userId: authorId,
profileImageUrl,
} = comment;
const commentIdFromSearchParams = useSearchParams().get('commentId');

const isSelected = Number(commentIdFromSearchParams) === replyId;
Expand All @@ -39,6 +46,7 @@ const CommentReplyItem = ({ comment }: CommentReplyItemProps) => {
createdAt={createdAt}
isOwnComment={isOwnComment}
authorId={authorId}
profileImageUrl={profileImageUrl}
>
<CommentReplyItemMenu replyId={replyId} isOwnComment={isOwnComment} />
</CommentItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ const CommentRootItem = ({
isFirst = false,
comment,
}: CommentRootItemProps) => {
const { commentId, nickname, content, createdAt, userId: authorId } = comment;
const {
commentId,
nickname,
content,
createdAt,
userId: authorId,
profileImageUrl,
} = comment;
const commentIdFromSearchParams = useSearchParams().get('commentId');

const isSelected = Number(commentIdFromSearchParams) === commentId;
Expand All @@ -38,6 +45,7 @@ const CommentRootItem = ({
createdAt={createdAt}
isOwnComment={isOwnComment}
authorId={authorId}
profileImageUrl={profileImageUrl}
>
<CommentRootItemMenu
commentId={commentId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface CommentItemProps {
createdAt: string;
isOwnComment: boolean;
authorId: number;
profileImageUrl: string | null;
}

const CommentItem = ({
Expand All @@ -22,17 +23,19 @@ const CommentItem = ({
isOwnComment,
children,
authorId,
profileImageUrl,
}: PropsWithChildren<CommentItemProps>) => {
return (
<div className='flex w-full flex-col gap-2'>
<div className='flex items-center justify-between'>
<Link href={`/users/${authorId}`}>
<div className='flex items-center gap-1'>
<div className='flex items-center gap-2'>
<Image
src='/user-square.png'
src={profileImageUrl || '/picky/user-square.svg'}
alt='유저프로필'
width={24}
height={24}
className='h-[24px] w-[24px] rounded-[4px]'
/>
<span className='font-title-1-md'>{nickname}</span>
{isOwnComment && <OwnCommentChip />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const CommentList = () => {
const { commentSize } = useGetPostDetailAPI(postId);

return (
<div>
<div className='font-h3-sm border-t border-gray-accent2 px-4 py-5'>
<>
<div className='font-h3-sm border-t border-gray-accent2 px-4 py-5 pb-0'>
댓글 {commentSize}
</div>
<div className=' flex flex-col divide-y divide-gray-accent2'>
{comments.length === 0 && (
<span className='font-text-2-md self-center whitespace-pre-line p-4 text-center text-gray-accent3'>
<span className='font-text-2-md self-center whitespace-pre-line p-4 pt-5 text-center text-gray-accent3'>
{INITIAL_TEXT}
</span>
)}
Expand All @@ -35,7 +35,7 @@ const CommentList = () => {
</div>
))}
</div>
</div>
</>
);
};

Expand Down
Loading

0 comments on commit 174f8b8

Please sign in to comment.