fix(web): Displaying of markAsPlayed and likeButton on state change. Improve Card performace
This commit is contained in:
5 files changed
+78
-94
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
import React from "react";
|
import React, { useEffect } from "react";
|
||||||
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
|
||||||
@@ -18,19 +18,28 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
|
|||||||
const { enqueueSnackbar } = useSnackbar();
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const handleLiking = async () => {
|
const handleLiking = async () => {
|
||||||
|
let result = null;
|
||||||
if (isFavorite) {
|
if (isFavorite) {
|
||||||
await getUserLibraryApi(api).unmarkFavoriteItem({
|
result = await getUserLibraryApi(api).unmarkFavoriteItem({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
itemId: itemId,
|
itemId: itemId,
|
||||||
});
|
});
|
||||||
} else if (!isFavorite) {
|
} else if (!isFavorite) {
|
||||||
await getUserLibraryApi(api).markFavoriteItem({
|
result = await getUserLibraryApi(api).markFavoriteItem({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
itemId: itemId,
|
itemId: itemId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return result.data;
|
||||||
};
|
};
|
||||||
const mutation = useMutation({
|
const mutation = useMutation({
|
||||||
|
// mutationFn: async () => {
|
||||||
|
// new Promise((resolve, reject) => {
|
||||||
|
// setTimeout(() => {
|
||||||
|
// resolve("foo");
|
||||||
|
// }, 4000);
|
||||||
|
// });
|
||||||
|
// },
|
||||||
mutationFn: handleLiking,
|
mutationFn: handleLiking,
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
enqueueSnackbar(`${error}`, {
|
enqueueSnackbar(`${error}`, {
|
||||||
@@ -43,66 +52,42 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
|
|||||||
},
|
},
|
||||||
onSettled: async () => {
|
onSettled: async () => {
|
||||||
return await queryClient.invalidateQueries({
|
return await queryClient.invalidateQueries({
|
||||||
queryKey: queryKey,
|
queryKey,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
mutationKey: ["likeButton", itemId],
|
mutationKey: ["likeButton", itemId],
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<IconButton
|
||||||
|
onClick={(e) => {
|
||||||
|
if (!mutation.isPending) {
|
||||||
|
mutation.mutate();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
|
opacity: mutation.isPending ? 0.5 : 1,
|
||||||
transition: "opacity 250ms",
|
transition: "opacity 250ms",
|
||||||
position: "relative",
|
|
||||||
display: "inline-flex",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CircularProgress
|
<div
|
||||||
style={{
|
className="material-symbols-rounded"
|
||||||
opacity: mutation.isPending ? 1 : 0,
|
style={
|
||||||
transition: "opacity 200ms",
|
isFavorite
|
||||||
}}
|
? {
|
||||||
thickness={2}
|
"--fill": mutation.isPending ? 0 : 1,
|
||||||
/>
|
color: mutation.isPending ? "white" : pink.A700,
|
||||||
<IconButton
|
}
|
||||||
onClick={(e) => {
|
: {
|
||||||
if (!mutation.isPending) {
|
"--fill": mutation.isPending ? 1 : 0,
|
||||||
e.stopPropagation();
|
color: mutation.isPending ? pink.A700 : "white",
|
||||||
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,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<div
|
favorite
|
||||||
className="material-symbols-rounded"
|
</div>
|
||||||
style={
|
</IconButton>
|
||||||
isFavorite
|
|
||||||
? {
|
|
||||||
fontVariationSettings:
|
|
||||||
'"FILL" 1, "wght" 300, "GRAD" 25, "opsz" 40',
|
|
||||||
color: pink[700],
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
fontVariationSettings:
|
|
||||||
'"FILL" 0, "wght" 300, "GRAD" 25, "opsz" 40',
|
|
||||||
color: "white",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>
|
|
||||||
favorite
|
|
||||||
</div>
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
|||||||
|
|
||||||
const handleMarking = async () => {
|
const handleMarking = async () => {
|
||||||
if (!isPlayed) {
|
if (!isPlayed) {
|
||||||
await getPlaystateApi(api).markPlayedItem({
|
return await getPlaystateApi(api).markPlayedItem({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
itemId: itemId,
|
itemId: itemId,
|
||||||
});
|
});
|
||||||
} else if (isPlayed) {
|
} else if (isPlayed) {
|
||||||
await getPlaystateApi(api).markUnplayedItem({
|
return await getPlaystateApi(api).markUnplayedItem({
|
||||||
userId: userId,
|
userId: userId,
|
||||||
itemId: itemId,
|
itemId: itemId,
|
||||||
});
|
});
|
||||||
@@ -50,49 +50,33 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
|
|||||||
mutationKey: ["markPlayedButton", itemId],
|
mutationKey: ["markPlayedButton", itemId],
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div
|
<IconButton
|
||||||
|
onClick={(e) => {
|
||||||
|
if (!mutation.isPending) {
|
||||||
|
mutation.mutate();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
}}
|
||||||
style={{
|
style={{
|
||||||
|
opacity: mutation.isPending ? 0.5 : 1,
|
||||||
transition: "opacity 250ms",
|
transition: "opacity 250ms",
|
||||||
position: "relative",
|
|
||||||
display: "inline-flex",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CircularProgress
|
<div
|
||||||
|
className="material-symbols-rounded"
|
||||||
style={{
|
style={{
|
||||||
opacity: mutation.isPending ? 1 : 0,
|
color: isPlayed
|
||||||
transition: "opacity 200ms",
|
? mutation.isPending
|
||||||
}}
|
? "white"
|
||||||
thickness={2}
|
: green.A700
|
||||||
/>
|
: mutation.isPending
|
||||||
<IconButton
|
? green.A700
|
||||||
onClick={(e) => {
|
: "white",
|
||||||
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,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
done
|
||||||
className="material-symbols-rounded"
|
</div>
|
||||||
style={{
|
</IconButton>
|
||||||
color: isPlayed ? green[400] : "white",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
done
|
|
||||||
</div>
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ export const Card = ({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
{/*
|
||||||
{item.UserData?.PlaybackPositionTicks > 0 && (
|
{item.UserData?.PlaybackPositionTicks > 0 && (
|
||||||
<LinearProgress
|
<LinearProgress
|
||||||
variant="determinate"
|
variant="determinate"
|
||||||
@@ -200,7 +201,7 @@ export const Card = ({
|
|||||||
}}
|
}}
|
||||||
color="primary"
|
color="primary"
|
||||||
/>
|
/>
|
||||||
)}
|
)} */}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className="card-text-container"
|
className="card-text-container"
|
||||||
|
|||||||
@@ -148,3 +148,13 @@
|
|||||||
transition: filter $transition-time-default;
|
transition: filter $transition-time-default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item {
|
||||||
|
&-hero-image{
|
||||||
|
box-sizing: border-box;
|
||||||
|
&-container{
|
||||||
|
box-sizing: content-box;
|
||||||
|
border: 1.2px solid rgb(255 255 255 / 0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -148,12 +148,16 @@ h1 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.material-symbols-rounded {
|
.material-symbols-rounded {
|
||||||
font-variation-settings: "FILL" 0, "wght" 300, "GRAD" 25, "opsz" 40;
|
--fill: 0;
|
||||||
|
--wght: 300;
|
||||||
|
--grad: 25;
|
||||||
|
--opsz: 40;
|
||||||
|
|
||||||
|
font-variation-settings: "FILL" var(--fill, 0), "wght" var(--wght, 300), "GRAD" var(--grad, 25), "opsz" var(--opsz, 40);
|
||||||
font-size: 1.1em;
|
font-size: 1.1em;
|
||||||
transition: all $transition-time-default;
|
transition: all $transition-time-default;
|
||||||
&.fill{
|
&.fill{
|
||||||
font-variation-settings: "FILL" 1, "wght" 700, "GRAD" 200, "opsz" 48;
|
--fill: 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user