diff --git a/src/components/buttons/likeButton.jsx b/src/components/buttons/likeButton.jsx index 53193bc..60aebd7 100644 --- a/src/components/buttons/likeButton.jsx +++ b/src/components/buttons/likeButton.jsx @@ -1,6 +1,6 @@ import PropTypes from "prop-types"; -import React from "react"; +import React, { useEffect } from "react"; import IconButton from "@mui/material/IconButton"; @@ -18,19 +18,28 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => { const { enqueueSnackbar } = useSnackbar(); const handleLiking = async () => { + let result = null; if (isFavorite) { - await getUserLibraryApi(api).unmarkFavoriteItem({ + result = await getUserLibraryApi(api).unmarkFavoriteItem({ userId: userId, itemId: itemId, }); } else if (!isFavorite) { - await getUserLibraryApi(api).markFavoriteItem({ + result = await getUserLibraryApi(api).markFavoriteItem({ userId: userId, itemId: itemId, }); } + return result.data; }; const mutation = useMutation({ + // mutationFn: async () => { + // new Promise((resolve, reject) => { + // setTimeout(() => { + // resolve("foo"); + // }, 4000); + // }); + // }, mutationFn: handleLiking, onError: (error) => { enqueueSnackbar(`${error}`, { @@ -43,66 +52,42 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => { }, onSettled: async () => { return await queryClient.invalidateQueries({ - queryKey: queryKey, + queryKey, }); }, mutationKey: ["likeButton", itemId], }); return ( -
{ + if (!mutation.isPending) { + mutation.mutate(); + e.stopPropagation(); + } + }} style={{ + opacity: mutation.isPending ? 0.5 : 1, transition: "opacity 250ms", - position: "relative", - display: "inline-flex", }} > - - { - if (!mutation.isPending) { - e.stopPropagation(); - mutation.mutate(); - } - }} - style={{ - position: "absolute", - top: 0, - left: 0, - right: 0, - bottom: 0, - display: "flex", - alignItems: "center", - justifyContent: "center", - opacity: mutation.isPending ? 0.5 : 1, - }} +
-
- favorite -
- -
+ favorite +
+ ); }; diff --git a/src/components/buttons/markPlayedButton.jsx b/src/components/buttons/markPlayedButton.jsx index 6ef3274..ef897d0 100644 --- a/src/components/buttons/markPlayedButton.jsx +++ b/src/components/buttons/markPlayedButton.jsx @@ -20,12 +20,12 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => { const handleMarking = async () => { if (!isPlayed) { - await getPlaystateApi(api).markPlayedItem({ + return await getPlaystateApi(api).markPlayedItem({ userId: userId, itemId: itemId, }); } else if (isPlayed) { - await getPlaystateApi(api).markUnplayedItem({ + return await getPlaystateApi(api).markUnplayedItem({ userId: userId, itemId: itemId, }); @@ -50,49 +50,33 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => { mutationKey: ["markPlayedButton", itemId], }); return ( -
{ + if (!mutation.isPending) { + mutation.mutate(); + e.stopPropagation(); + } + }} style={{ + opacity: mutation.isPending ? 0.5 : 1, transition: "opacity 250ms", - position: "relative", - display: "inline-flex", }} > - - { - if (!mutation.isPending) { - e.stopPropagation(); - mutation.mutate(); - } - }} - style={{ - position: "absolute", - top: 0, - left: 0, - right: 0, - bottom: 0, - display: "flex", - alignItems: "center", - justifyContent: "center", - opacity: mutation.isPending ? 0.5 : 1, + color: isPlayed + ? mutation.isPending + ? "white" + : green.A700 + : mutation.isPending + ? green.A700 + : "white", }} > -
- done -
-
-
+ done + + ); }; diff --git a/src/components/card/card.tsx b/src/components/card/card.tsx index 44727fc..b89a6b1 100644 --- a/src/components/card/card.tsx +++ b/src/components/card/card.tsx @@ -184,6 +184,7 @@ export const Card = ({ )} + {/* {item.UserData?.PlaybackPositionTicks > 0 && ( - )} + )} */}