249 lines
5.6 KiB
React
249 lines
5.6 KiB
React
/** @format */
|
|
import PropTypes from "prop-types";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import Stack from "@mui/material/Stack";
|
|
import MuiCard from "@mui/material/Card";
|
|
import CardActionArea from "@mui/material/CardActionArea";
|
|
import Typography from "@mui/material/Typography";
|
|
import LinearProgress from "@mui/material/LinearProgress";
|
|
|
|
import { Blurhash } from "react-blurhash";
|
|
|
|
import { TypeIconCollectionCard } from "../utils/iconsCollection";
|
|
import "./card.module.scss";
|
|
import { MdiCheck } from "../icons/mdiCheck";
|
|
|
|
import LikeButton from "../buttons/likeButton";
|
|
import MarkPlayedButton from "../buttons/markPlayedButton";
|
|
import PlayButton from "../buttons/playButton";
|
|
|
|
const cardImageAspectRatios = {
|
|
thumb: 1.777,
|
|
portrait: 0.666,
|
|
square: 1,
|
|
};
|
|
|
|
export const Card = ({
|
|
item,
|
|
cardTitle,
|
|
cardCaption,
|
|
imageType = "Primary",
|
|
imageBlurhash,
|
|
cardType,
|
|
queryKey,
|
|
userId,
|
|
seriesId,
|
|
hideText,
|
|
onClick,
|
|
disableOverlay = false,
|
|
disablePadding,
|
|
overrideIcon,
|
|
}) => {
|
|
const navigate = useNavigate();
|
|
const defaultOnClick = () => navigate(`/item/${item.Id}`);
|
|
return (
|
|
<CardActionArea
|
|
sx={{ padding: disablePadding ? 0 : 1, borderRadius: "10px" }}
|
|
className="card-container"
|
|
onClick={!!onClick ? onClick : defaultOnClick}
|
|
>
|
|
<MuiCard
|
|
sx={{
|
|
height: "100%",
|
|
overflow: "visible",
|
|
alignItems: "flex-start",
|
|
background: "transparent",
|
|
}}
|
|
elevation={0}
|
|
>
|
|
<Stack
|
|
className="card"
|
|
sx={{
|
|
width: "100%",
|
|
height: "100%",
|
|
position: "relative",
|
|
overflow: "visible",
|
|
}}
|
|
direction="column"
|
|
justifyContent="center"
|
|
mr={1}
|
|
>
|
|
<div
|
|
className="card-image-container"
|
|
style={{
|
|
aspectRatio: cardImageAspectRatios[cardType],
|
|
}}
|
|
>
|
|
{!!item.UserData && (
|
|
<>
|
|
<div
|
|
className="card-indicator check"
|
|
style={{
|
|
opacity: item.UserData?.Played
|
|
? 1
|
|
: 0,
|
|
}}
|
|
>
|
|
<MdiCheck />
|
|
</div>
|
|
<div
|
|
className={`card-indicator text`}
|
|
style={{
|
|
opacity: !!item.UserData
|
|
?.UnplayedItemCount
|
|
? 1
|
|
: 0,
|
|
}}
|
|
>
|
|
<Typography
|
|
variant="subtitle2"
|
|
padding="0.1em 0.4em"
|
|
fontWeight={400}
|
|
>
|
|
{
|
|
item.UserData
|
|
?.UnplayedItemCount
|
|
}
|
|
</Typography>
|
|
</div>
|
|
</>
|
|
)}
|
|
{!!imageBlurhash && (
|
|
<Blurhash
|
|
hash={imageBlurhash}
|
|
width={128}
|
|
height={128}
|
|
resolutionX={24}
|
|
resolutionY={24}
|
|
className="card-image-blurhash"
|
|
/>
|
|
)}
|
|
<div className="card-image-icon-container">
|
|
{!!overrideIcon
|
|
? TypeIconCollectionCard[overrideIcon]
|
|
: TypeIconCollectionCard[item.Type]}
|
|
</div>
|
|
<img
|
|
src={
|
|
overrideIcon == "User"
|
|
? `${window.api.basePath}/Users/${item.Id}/Images/Primary`
|
|
: window.api.getItemImageUrl(
|
|
!!seriesId
|
|
? item.SeriesId
|
|
: item.Id,
|
|
imageType,
|
|
{
|
|
quality: 90,
|
|
fillHeight: 512,
|
|
fillWidth: 512,
|
|
},
|
|
)
|
|
}
|
|
style={{
|
|
height: "100%",
|
|
width: "100%",
|
|
opacity: 0,
|
|
}}
|
|
loading="lazy"
|
|
onLoad={(e) => (e.target.style.opacity = 1)}
|
|
className="card-image"
|
|
/>
|
|
{!disableOverlay && (
|
|
<div className="card-overlay">
|
|
<PlayButton
|
|
itemId={item.Id}
|
|
userId={userId}
|
|
itemType={item.Type}
|
|
currentAudioTrack={0}
|
|
currentSubTrack={0}
|
|
currentVideoTrack={0}
|
|
className="card-play-button"
|
|
iconProps={{
|
|
sx: { fontSize: "2.5em" },
|
|
}}
|
|
iconOnly
|
|
/>
|
|
<LikeButton
|
|
itemId={item.Id}
|
|
itemName={item.Name}
|
|
isFavorite={
|
|
item.UserData?.IsFavorite
|
|
}
|
|
queryKey={queryKey}
|
|
userId={userId}
|
|
/>
|
|
<MarkPlayedButton
|
|
itemId={item.Id}
|
|
itemName={item.Name}
|
|
isPlayed={item.UserData.Played}
|
|
queryKey={queryKey}
|
|
userId={userId}
|
|
/>
|
|
</div>
|
|
)}
|
|
{100 > item.UserData?.PlayedPercentage > 0 && (
|
|
<LinearProgress
|
|
variant="determinate"
|
|
value={item.UserData.PlayedPercentage}
|
|
sx={{
|
|
position: "absolute",
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
zIndex: 2,
|
|
height: "6px",
|
|
background:
|
|
"rgb(5 5 5 / 0.5) !important",
|
|
backdropFilter: "blur(5px)",
|
|
}}
|
|
color="primary"
|
|
/>
|
|
)}
|
|
</div>
|
|
<div
|
|
className="card-text-container"
|
|
style={{ display: hideText ? "none" : "block" }}
|
|
>
|
|
<Typography
|
|
variant="subtitle1"
|
|
fontWeight={500}
|
|
noWrap
|
|
textAlign="center"
|
|
sx={{ opacity: 0.9 }}
|
|
>
|
|
{cardTitle}
|
|
</Typography>
|
|
<Typography
|
|
variant="subtitle2"
|
|
noWrap
|
|
textAlign="center"
|
|
sx={{ opacity: 0.6 }}
|
|
lineHeight="auto"
|
|
>
|
|
{cardCaption}
|
|
</Typography>
|
|
</div>
|
|
</Stack>
|
|
</MuiCard>
|
|
</CardActionArea>
|
|
);
|
|
};
|
|
|
|
Card.propTypes = {
|
|
item: PropTypes.any.isRequired,
|
|
cardTitle: PropTypes.string,
|
|
cardCaption: PropTypes.any,
|
|
imageType: PropTypes.string,
|
|
imageBlurhash: PropTypes.string,
|
|
cardType: PropTypes.string,
|
|
queryKey: PropTypes.any,
|
|
userId: PropTypes.string.isRequired,
|
|
seriesId: PropTypes.string,
|
|
hideText: PropTypes.bool,
|
|
onClick: PropTypes.func,
|
|
disableOverlay: PropTypes.bool,
|
|
disablePadding: PropTypes.bool,
|
|
};
|