Skip to content

Commit

Permalink
refactor: refactored use likes method
Browse files Browse the repository at this point in the history
  • Loading branch information
harundogdu committed Oct 9, 2023
1 parent 52f5ae4 commit ef4a853
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions hooks/useLikes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { useCallback, useMemo } from "react";

import axios from "axios";
import toast from "react-hot-toast";

import useCurrentUser from "./useCurrentUser";
import usePost from "./usePost";
import useLoginModal from "./useLoginModal";
import axios from "axios";
import usePost from "./usePost";
import usePosts from "./usePosts";
import toast from "react-hot-toast";

const useLikes = ({ postId, userId }: { postId: string; userId: string }) => {
const { data: currentUser } = useCurrentUser();
const { data: currentUser, mutate: mutateUser } = useCurrentUser();
const { data: fetchedPost, mutate: mutatePost } = usePost(postId);
const { mutate: mutatePosts } = usePosts();
const loginModal = useLoginModal();
Expand Down Expand Up @@ -35,13 +37,22 @@ const useLikes = ({ postId, userId }: { postId: string; userId: string }) => {
await request();
mutatePost();
mutatePosts();
mutateUser();

toast.success("Success");
} catch (error: any) {
console.log(error);
toast.error("Failed");
}
}, [currentUser, hasLiked, loginModal, mutatePost, mutatePosts, postId]);
}, [
currentUser,
hasLiked,
loginModal,
mutatePost,
mutatePosts,
postId,
mutateUser,
]);

return {
hasLiked,
Expand Down

1 comment on commit ef4a853

@vercel
Copy link

@vercel vercel bot commented on ef4a853 Oct 9, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.