Skip to content

Commit

Permalink
쿼리키 활용, 토스트 팝업 기능 추가 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Namyunha authored Jul 24, 2024
2 parents 807ef23 + fb9ad8d commit 632341d
Show file tree
Hide file tree
Showing 77 changed files with 678 additions and 143 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"react-dom": "^18.2.0",
"react-kakao-maps-sdk": "^1.1.27",
"react-responsive": "^10.0.0",
"react-toastify": "^10.0.5",
"tailwind-merge": "^2.3.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions public/icon/error.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/icon/more.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/icon/send.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 3 additions & 5 deletions public/icon/share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/icon/success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions public/icon/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export { default as checkbox_circle } from 'public/icon/checkbox_circle.svg';
export { default as circle_x } from 'public/icon/circle_x.svg';
export { default as close } from 'public/icon/close.svg';
export { default as comment } from 'public/icon/comment.svg';
export { default as error } from 'public/icon/error.svg';
export { default as filter } from 'public/icon/filter.svg';
export { default as heart } from 'public/icon/heart.svg';
export { default as heart_full } from 'public/icon/heart_full.svg';
Expand All @@ -21,17 +22,19 @@ export { default as internet } from 'public/icon/internet.svg';
export { default as logo } from 'public/icon/logo.svg';
export { default as logo_secondary } from 'public/icon/logo_secondary.svg';
export { default as menu } from 'public/icon/menu.svg';
export { default as more } from 'public/icon/more.svg';
export { default as phone } from 'public/icon/phone.svg';
export { default as refresh } from 'public/icon/refresh.svg';
export { default as store } from 'public/icon/refresh.svg';
export { default as register_logo } from 'public/icon/register_logo.svg';
export { default as send } from 'public/icon/send.svg';
export { default as setting } from 'public/icon/setting.svg';
export { default as share } from 'public/icon/share.svg';
export { default as star } from 'public/icon/star.svg';
export { default as star_empty } from 'public/icon/star_empty.svg';
export { default as star_half } from 'public/icon/star_half.svg';
export { default as store } from 'public/icon/store.svg';
export { default as success } from 'public/icon/success.svg';
export { default as time } from 'public/icon/time.svg';
export { default as upload } from 'public/icon/upload.svg';
export { default as user0 } from 'public/icon/user0.svg';
export { default as user1 } from 'public/icon/user1.svg';
export { default as user2 } from 'public/icon/user2.svg';
Expand Down
5 changes: 0 additions & 5 deletions public/icon/upload.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/api/cafe/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const postCafeList = async ({
location,
pagingData,
}: CafeListReqType) => {
// Todo: 쿼리키에 필터 추가
const { data } = await fetcher.post<CafeListResType>(END_POINT.CAFE.LIST, {
tags,
location,
Expand Down
26 changes: 20 additions & 6 deletions src/api/cafe/queries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';
import {
useInfiniteQuery,
useMutation,
useQuery,
useQueryClient,
} from '@tanstack/react-query';
import { toast } from 'react-toastify';
import ToastIcon from '@/components/Icon/ToastIcon';
import { DEFAULT_CURSOR, DEFAULT_SIZE } from '@/constants/api';
import { CafeLikeReqType, CafeListReqType } from '@/types/cafe';
import { cafeKeys } from './../queryKeys';
Expand All @@ -11,24 +18,32 @@ export function useRecommendedCafeListQuery() {
});
}

// Todo: 쿼리키 추가하기
export function useCafeLikeMutation({
cafeId,
isLike,
setLikeState,
}: CafeLikeReqType & {
setLikeState: React.Dispatch<React.SetStateAction<boolean>>;
}) {
const queryClient = useQueryClient();

return useMutation({
mutationFn: () => patchCafeLike({ cafeId, isLike }),
onSuccess: (data) => {
// Todo: 성공할 경우 토스트 팝업 띄우기
toast(data.message, {
icon: ToastIcon({ type: 'success' }),
className: 'border border-stroke_focused',
});

const newLikeState = data.data.isLike;
setLikeState(newLikeState);

queryClient.invalidateQueries(cafeKeys.cafeList);
},
onError: (error) => {
// Todo: 실패할 경우 토스트 팝업 띄우기
console.log(error.message);
toast(error.message, {
icon: ToastIcon({ type: 'error' }),
});
},
});
}
Expand All @@ -42,7 +57,6 @@ export function useCafeListInfiniteQuery({
location,
pageSize = DEFAULT_SIZE,
}: CafeListQueryType) {
// Todo: 쿼리키에 필터 추가
return useInfiniteQuery({
...cafeKeys.cafeList,
initialPageParam: DEFAULT_CURSOR,
Expand Down
6 changes: 4 additions & 2 deletions src/api/queryKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { createQueryKeys } from '@lukemorales/query-key-factory';

export const reviewKeys = createQueryKeys('review', {
reviewList: { queryKey: ['getReviewList'] },
reviewCommentList: { queryKey: ['getReviewList'] },
myReviewList: { queryKey: ['getReviewList'] },
myReviewList: { queryKey: ['getMyReviewList'] },
reviewCommentList: (reviewId: string) => ({
queryKey: ['getCommentList', reviewId],
}),
});

export const cafeKeys = createQueryKeys('cafe', {
Expand Down
57 changes: 55 additions & 2 deletions src/api/review/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { END_POINT } from '@/constants/api';
import {
ReviewCommentDeleteReqType,
ReviewCommentDeleteResType,
ReviewCommentReqType,
ReviewCommentResType,
ReviewCommentUpdateReqType,
ReviewCommentUpdateResType,
ReviewCommentWriteReqType,
ReviewCommentWriteResType,
ReviewLikeReqType,
ReviewLikeResType,
ReviewListReqType,
Expand All @@ -15,7 +21,6 @@ export const postReviewList = async ({
location,
pagingData,
}: ReviewListReqType) => {
// Todo: 쿼리키에 필터 추가
const { data } = await fetcher.post<ReviewListResType>(
END_POINT.REVIEW.LIST,
{
Expand All @@ -33,7 +38,6 @@ export const postMyReviewList = async ({
pagingData,
userId,
}: Pick<ReviewListReqType, 'pagingData'> & { userId: number }) => {
// Todo: 쿼리키에 필터 추가
const { data } = await fetcher.post<ReviewListResType>(
END_POINT.REVIEW.MYLIST,
{
Expand Down Expand Up @@ -66,3 +70,52 @@ export const getReviewCommentList = async ({

return data;
};

export const postReviewComment = async ({
reviewId,
comment,
}: ReviewCommentWriteReqType) => {
const { data } = await fetcher.post<ReviewCommentWriteResType>(
END_POINT.REVIEW.COMMENT_WRITE,
{
reviewId,
comment,
}
);

return data;
};

export const patchReviewComment = async ({
reviewId,
commentId,
comment,
}: ReviewCommentUpdateReqType) => {
const { data } = await fetcher.patch<ReviewCommentUpdateResType>(
END_POINT.REVIEW.COMMENT_UPDATE,
{
reviewId,
commentId,
comment,
}
);

return data;
};

export const deleteReviewComment = async ({
reviewId,
commentId,
}: ReviewCommentDeleteReqType) => {
const { data } = await fetcher.delete<ReviewCommentDeleteResType>(
END_POINT.REVIEW.COMMENT_DELETE,
{
data: {
reviewId,
commentId,
},
}
);

return data;
};
Loading

0 comments on commit 632341d

Please sign in to comment.