Skip to content

Commit

Permalink
✨ useGettPostLikeQuery로 이름 수정, currtUser 전달받아 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
khj0426 committed Oct 5, 2023
1 parent e570446 commit ec9a38a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CommentListContainer from '@/components/organisms/CommentList/CommentList
import { LikeDisLikeContainer } from '@/components/organisms/LikeDisLikeContainer'
import APP_PATH from '@/config/paths'
import { useAuth } from '@/lib/contexts/authProvider'
import { useLikeQuery, useLikeMutate } from '@/queries/likes'
import { useGetPostLikesQuery, useLikeMutate } from '@/queries/likes'
import { postNewComment } from '@/services/comment'
import Post from '@/types/post'
import './index.scss'
Expand All @@ -35,18 +35,15 @@ export function PostDetailTemplate({
const cachedCurrentUser = useMemo(() => currentUser, [currentUser])
const isEqualUser = cachedCurrentUser?._id === author._id

const { data: postLike, isFetching: isLikePostFetching } = useLikeQuery(
initPost._id,
initPost,
)
const { data: postDisLike, isFetching: isDisLikePostFetching } = useLikeQuery(
initDisLikeChannelPost._id,
initDisLikeChannelPost,
)
const { data: postLike, isFetching: isLikePostFetching } =
useGetPostLikesQuery(initPost._id, initPost)
const { data: postDisLike, isFetching: isDisLikePostFetching } =
useGetPostLikesQuery(initDisLikeChannelPost._id, initDisLikeChannelPost)

const { likeMutation, disLikeMutation } = useLikeMutate({
initPost: initPost,
initDisLikePost: initDisLikeChannelPost,
currentUser,
})

const initLikeState = postLike?.likes.some(
Expand Down
144 changes: 0 additions & 144 deletions src/hooks/useLike.ts

This file was deleted.

12 changes: 8 additions & 4 deletions src/queries/likes/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query'
import { useCurrentUser } from '@/hooks/useCurrentUser'
import { getPostDetail } from '@/services/post'
import { postLikeAction, postLikeCancelAction } from '@/services/post/like'
import type Post from '@/types/post'
import User from '@/types/user'

type useLikeProps = {
initPost: Post
initDisLikePost: Post
currentUser?: User
}

export function useLikeQuery(postId: string, initPost: Post) {
export function useGetPostLikesQuery(postId: string, initPost: Post) {
return useQuery({
queryKey: ['post', postId],
queryFn: async () => {
Expand All @@ -21,9 +22,12 @@ export function useLikeQuery(postId: string, initPost: Post) {
})
}

export function useLikeMutate({ initPost, initDisLikePost }: useLikeProps) {
export function useLikeMutate({
initPost,
initDisLikePost,
currentUser,
}: useLikeProps) {
const queryClient = useQueryClient()
const { currentUser } = useCurrentUser()

const likeMutation = useMutation(
async () => {
Expand Down

0 comments on commit ec9a38a

Please sign in to comment.