Skip to content

Commit

Permalink
FE-54๐Ÿ› ๋Œ“๊ธ€ ๋ถˆ๋Ÿฌ์˜ค์ง€๋ชปํ•˜๋Š” ๋ฌธ์ œ ํ•ด๊ฒฐ (#186)
Browse files Browse the repository at this point in the history
* FE-54๐Ÿ› ๋Œ“๊ธ€ ๋ถˆ๋Ÿฌ์˜ค์ง€๋ชปํ•˜๋Š”  ๋ฌธ์ œ ํ•ด๊ฒฐ

* FE-54๐Ÿ›build error ํ•ด๊ฒฐ

* FE-54๐Ÿ’„ url๋งํฌ๋ฒ„ํŠผ ์Šคํƒ€์ผ ์ˆ˜์ •
  • Loading branch information
jisurk authored Aug 4, 2024
1 parent 3943288 commit 406ebc4
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 32 deletions.
10 changes: 3 additions & 7 deletions src/apis/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,9 @@ const queries = createQueryKeyStore({
}),
},
epigramComment: {
getComments: (request: CommentRequestType) => ({
queryKey: ['epigramComments', request],
queryFn: () => getEpigramComments(request),
}),
getCommentList: (request: CommentRequestType) => ({
queryKey: ['epigramComments', request] as const,
queryFn: ({ pageParam }: { pageParam: number | undefined }) => getEpigramComments({ ...request, cursor: pageParam }),
getComments: (epigramId: number) => ({
queryKey: ['epigramComments', epigramId],
queryFn: ({ pageParam }: { pageParam?: number }) => getEpigramComments({ id: epigramId, limit: 3, cursor: pageParam }),
}),
getMyComments: (request: CommentRequestType) => ({
queryKey: ['myEpigramComments', request],
Expand Down
17 changes: 6 additions & 11 deletions src/hooks/useEpigramCommentsQueryHook.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// hooks/useEpigramCommentHook.ts

import { useInfiniteQuery } from '@tanstack/react-query';
import queries from '@/apis/queries';
import { InfiniteData, useInfiniteQuery } from '@tanstack/react-query';
import { CommentResponseType } from '@/schema/comment';
import queries from '@/apis/queries';

const useEpigramCommentsQuery = (epigramId: number) => {
const query = queries.epigramComment.getCommentList({ id: epigramId, limit: 3 });

return useInfiniteQuery({
...query,
const useEpigramCommentsQuery = (epigramId: number) =>
useInfiniteQuery<CommentResponseType, Error, InfiniteData<CommentResponseType>>({
...queries.epigramComment.getComments(epigramId),
initialPageParam: undefined,
getNextPageParam: (lastPage: CommentResponseType) => lastPage.nextCursor ?? undefined,
getNextPageParam: (lastPage) => lastPage.nextCursor ?? undefined,
});
};

export default useEpigramCommentsQuery;
11 changes: 5 additions & 6 deletions src/hooks/usePatchCommentHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,23 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { patchComment } from '@/apis/epigramComment';
import { PatchCommentRequest } from '@/types/epigram.types';
import { toast } from '@/components/ui/use-toast';
import queries from '@/apis/queries';

const usePatchCommentMutation = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: ({ commentId, ...commentData }: { commentId: number } & PatchCommentRequest) => patchComment(commentId, commentData),
onSuccess: () => {
// ๋Œ“๊ธ€ ๋ชฉ๋ก ์ฟผ๋ฆฌ ๋ฌดํšจํ™”
queryClient.invalidateQueries({ queryKey: ['epigramComments'] });

// ์„ฑ๊ณต ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
onSuccess: (updatedComment) => {
queryClient.invalidateQueries({
queryKey: queries.epigramComment.getComments(updatedComment.epigramId).queryKey,
});
toast({
title: '๋Œ“๊ธ€ ์ˆ˜์ • ์„ฑ๊ณต',
description: '๋Œ“๊ธ€์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜์ •๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
});
},
onError: (error) => {
// ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
toast({
title: '๋Œ“๊ธ€ ์ˆ˜์ • ์‹คํŒจ',
description: `๋Œ“๊ธ€ ์ˆ˜์ • ์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: ${error instanceof Error ? error.message : '์•Œ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜'}`,
Expand Down
11 changes: 5 additions & 6 deletions src/hooks/usePostCommentHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
import { postComment } from '@/apis/epigramComment';
import { PostCommentRequest } from '@/types/epigram.types';
import { toast } from '@/components/ui/use-toast';
import queries from '@/apis/queries';

const usePostCommentMutation = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: (commentData: PostCommentRequest) => postComment(commentData),
onSuccess: () => {
// ๋Œ“๊ธ€ ๋ชฉ๋ก ์ฟผ๋ฆฌ ๋ฌดํšจํ™”
queryClient.invalidateQueries({ queryKey: ['epigramComments'] });

// ์„ฑ๊ณต ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
onSuccess: (variables) => {
queryClient.invalidateQueries({
queryKey: queries.epigramComment.getComments(variables.epigramId).queryKey,
});
toast({
className: 'bg-white',
title: '๋Œ“๊ธ€ ๋“ฑ๋ก ์„ฑ๊ณต',
description: '๋Œ“๊ธ€์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋“ฑ๋ก๋˜์—ˆ์Šต๋‹ˆ๋‹ค.',
});
},
onError: (error) => {
// ์—๋Ÿฌ ๋ฉ”์‹œ์ง€ ํ‘œ์‹œ
toast({
className: 'bg-white',
title: '๋Œ“๊ธ€ ๋“ฑ๋ก ์‹คํŒจ',
Expand Down
4 changes: 2 additions & 2 deletions src/pageLayout/Epigram/EpigramFigure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function EpigramFigure({ epigram, currentUserId }: EpigramFigureProps) {
{epigram.referenceTitle && (
<Button type='button'>
<Link href={`${epigram.referenceUrl}`} target='_blank'>
<div className='p-4 w-32 lg:w-44 h-9 lg:h-11 flex items-center justify-center rounded-full bg-line-100'>
<p className='text-gray-300 text-sm lg:text-xl truncate ...'>{epigram.referenceTitle}</p>
<div className='p-2 lg:p-4 w-32 lg:w-44 h-9 lg:h-11 flex items-center justify-around rounded-full bg-line-100'>
<p className='w-full text-gray-300 text-sm lg:text-xl truncate ...'>{epigram.referenceTitle}</p>
<Image src='/placeLink.svg' alt='๋งํฌ ์ด๋ฏธ์ง€' width={20} height={20} className='lg:w-9 lg:h-9' />
</div>
</Link>
Expand Down

0 comments on commit 406ebc4

Please sign in to comment.