Skip to content

Commit

Permalink
refactor(home/profile): improve mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
olexh committed May 6, 2024
1 parent 93b9a4b commit 4c709a6
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions app/(pages)/(root)/components/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import MaterialSymbolsSettingsOutline from '~icons/material-symbols/settings-out

import Link from 'next/link';

import { useMutation, useQueryClient } from '@tanstack/react-query';

import ContentCard from '@/components/content-card/content-card';
import WatchEditModal from '@/components/modals/watch-edit-modal';
import H5 from '@/components/typography/h5';
Expand All @@ -26,15 +24,14 @@ import {
TooltipContent,
TooltipTrigger,
} from '@/components/ui/tooltip';
import addWatch from '@/services/api/watch/addWatch';
import useSession from '@/services/hooks/auth/useSession';
import useAddWatch from '@/services/hooks/watch/useAddWatch';
import useWatchList from '@/services/hooks/watch/useWatchList';
import { useModalContext } from '@/services/providers/modal-provider';
import { cn } from '@/utils/utils';


const Profile = () => {
const queryClient = useQueryClient();
const { openModal } = useModalContext();
const [selectedSlug, setSelectedSlug] = useState<string>();
const { user: loggedUser } = useSession();
Expand All @@ -47,16 +44,7 @@ const Profile = () => {
const selectedWatch =
list?.find((item) => item.anime.slug === selectedSlug) || list?.[0];

const {
mutate: mutateAddWatch,
variables,
isPending,
} = useMutation({
mutationFn: addWatch,
onSettled: async () => {
return await queryClient.invalidateQueries({ queryKey: queryKey });
},
});
const { mutate: mutateAddWatch, variables, isPending } = useAddWatch();

const openWatchEditModal = () => {
if (selectedWatch) {
Expand Down

0 comments on commit 4c709a6

Please sign in to comment.