Add blurhash to cards

This commit is contained in:
prayag17 committed 2023-04-05 21:41:37 +05:30
1 parent 50f8e1c0f1
commit 2bbe846184
7 files changed
+215 -55

No files matched your search

+1 -1
View File
@@ -37,7 +37,7 @@ export const AppBar = () => {
const location = useLocation(); const location = useLocation();
const user = useQuery({ const user = useQuery({
queryKey: ["appBar", "user"], queryKey: ["user"],
queryFn: async () => { queryFn: async () => {
let usr = await getUserApi(window.api).getCurrentUser(); let usr = await getUserApi(window.api).getCurrentUser();
return usr.data; return usr.data;
+81 -49
View File
@@ -1,5 +1,5 @@
/** @format */ /** @format */
import React from "react"; import React, { useState } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import Box from "@mui/material/Box"; import Box from "@mui/material/Box";
@@ -10,6 +10,7 @@ import CardActionArea from "@mui/material/CardActionArea";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import LinearProgress from "@mui/material/LinearProgress"; import LinearProgress from "@mui/material/LinearProgress";
import Chip from "@mui/material/Chip"; import Chip from "@mui/material/Chip";
import { Blurhash } from "react-blurhash";
import { import {
MediaCollectionTypeIconCollectionCard, MediaCollectionTypeIconCollectionCard,
@@ -33,7 +34,9 @@ export const Card = ({
onClickEvent, onClickEvent,
watchedStatus, watchedStatus,
watchedCount, watchedCount,
blurhash,
}) => { }) => {
const [imgLoading, setImgLoading] = useState(true);
return ( return (
<MuiCard <MuiCard
className={"card " + cardOrientation} className={"card " + cardOrientation}
@@ -73,54 +76,82 @@ export const Card = ({
label={watchedCount} label={watchedCount}
></Chip> ></Chip>
)} )}
{imageTags && <div
(cardType == "thumb" ? ( class="card-media-image-container"
<CardMedia style={{ opacity: imgLoading ? 0 : 1 }}
component="div" >
image={ {imageTags &&
window.api.basePath + (cardType == "thumb" ? (
"/Items/" + <CardMedia
itemId + component="img"
"/Images/Backdrop?fillHeight=300&fillWidth=532&quality=96" image={
} window.api.basePath +
alt={itemName} "/Items/" +
sx={{ itemId +
width: "100%", "/Images/Backdrop?fillHeight=300&fillWidth=532&quality=96"
aspectRatio: }
cardOrientation == "landscape" alt={itemName}
? "1.777" sx={{
: cardOrientation == width: "100%",
"portait" aspectRatio:
? "0.666" cardOrientation ==
: "1", "landscape"
borderRadius: borderRadiusDefault, ? "1.777"
overflow: "hidden", : cardOrientation ==
}} "portait"
className="card-image" ? "0.666"
></CardMedia> : "1",
) : ( borderRadius:
<CardMedia borderRadiusDefault,
component="div" overflow: "hidden",
image={ }}
window.api.basePath + onLoad={() => setImgLoading(false)}
"/Items/" + className="card-image"
itemId + ></CardMedia>
"/Images/Primary" ) : (
} <CardMedia
alt={itemName} component="img"
sx={{ image={
width: "100%", window.api.basePath +
aspectRatio: "/Items/" +
cardOrientation == "landscape" itemId +
? "1.777" "/Images/Primary"
: cardOrientation == }
"portait" alt={itemName}
? "0.666" sx={{
: "1", width: "100%",
}} aspectRatio:
className="card-image" cardOrientation ==
></CardMedia> "landscape"
))} ? "1.777"
: cardOrientation ==
"portait"
? "0.666"
: "1",
}}
className="card-image"
onLoad={() => setImgLoading(false)}
></CardMedia>
))}
</div>
{!!blurhash && (
<Blurhash
hash={blurhash}
width="100%"
height="100%"
resolutionX={64}
resolutionY={64}
style={{
aspectRatio:
cardOrientation == "landscape"
? "1.777"
: cardOrientation == "portait"
? "0.666"
: "1",
}}
className="card-image-blurhash"
/>
)}
<div className="card-image-icon-container"> <div className="card-image-icon-container">
{cardType == "lib" {cardType == "lib"
? MediaCollectionTypeIconCollectionCard[ ? MediaCollectionTypeIconCollectionCard[
@@ -196,4 +227,5 @@ Card.propTypes = {
onClickEvent: PropTypes.func, onClickEvent: PropTypes.func,
watchedStatus: PropTypes.bool, watchedStatus: PropTypes.bool,
watchedCount: PropTypes.number, watchedCount: PropTypes.number,
blurhash: PropTypes.string,
}; };
+16 -1
View File
@@ -2,6 +2,9 @@
.card { .card {
border-radius: $border-radius-default; border-radius: $border-radius-default;
&-media-image-container {
transition: opacity $transition-time-default;
}
&-image { &-image {
position: relative; position: relative;
border-radius: $border-radius-default; border-radius: $border-radius-default;
@@ -9,6 +12,8 @@
background-position: center; background-position: center;
&-container { &-container {
position: relative; position: relative;
border-radius: $border-radius-default;
overflow: hidden;
} }
&-icon { &-icon {
font-size: 4.5em !important; font-size: 4.5em !important;
@@ -27,9 +32,19 @@
top: 0; top: 0;
bottom: 0; bottom: 0;
height: 100%; height: 100%;
z-index: -1; z-index: -2;
} }
} }
&-blurhash {
position: absolute !important;
width: 100%;
height: 100%;
top: 0;
left: 0;
border-radius: $border-radius-default;
overflow: hidden;
z-index: -1;
}
} }
&-text-container { &-text-container {
display: flex; display: flex;
@@ -65,6 +65,19 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
? "sqaure" ? "sqaure"
: "portait" : "portait"
} }
blurhash={
item.ImageBlurHashes == {}
? ""
: !!item.ImageTags.Primary
? !!item.ImageBlurHashes.Primary
? item.ImageBlurHashes
.Primary[
item.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
); );
})} })}
+2 -2
View File
@@ -61,7 +61,7 @@ export const SideMenu = ({}) => {
const visible = useSelector((state) => state.sidebar.visible); const visible = useSelector((state) => state.sidebar.visible);
const navigate = useNavigate(); const navigate = useNavigate();
const user = useQuery({ const user = useQuery({
queryKey: ["home", "user"], queryKey: ["user"],
queryFn: async () => { queryFn: async () => {
let usr = await getUserApi(window.api).getCurrentUser(); let usr = await getUserApi(window.api).getCurrentUser();
return usr.data; return usr.data;
@@ -69,7 +69,7 @@ export const SideMenu = ({}) => {
enabled: visible, enabled: visible,
}); });
let libraries = useQuery({ let libraries = useQuery({
queryKey: ["sidemenu", "libraries"], queryKey: ["libraries"],
queryFn: async () => { queryFn: async () => {
let libs = await getUserViewsApi(window.api).getUserViews({ let libs = await getUserViewsApi(window.api).getUserViews({
userId: user.data.Id, userId: user.data.Id,
+82 -2
View File
@@ -75,7 +75,7 @@ const Home = () => {
}); });
const user = useQuery({ const user = useQuery({
queryKey: ["home", "user"], queryKey: ["user"],
queryFn: async () => { queryFn: async () => {
let usr = await getUserApi(window.api).getCurrentUser(); let usr = await getUserApi(window.api).getCurrentUser();
return usr.data; return usr.data;
@@ -83,7 +83,7 @@ const Home = () => {
}); });
const libraries = useQuery({ const libraries = useQuery({
queryKey: ["home", "libraries"], queryKey: ["libraries"],
queryFn: async () => { queryFn: async () => {
let libs = await getUserViewsApi(window.api).getUserViews({ let libs = await getUserViewsApi(window.api).getUserViews({
userId: user.data.Id, userId: user.data.Id,
@@ -525,6 +525,26 @@ const Home = () => {
`/library/${item.Id}`, `/library/${item.Id}`,
); );
}} }}
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
); );
}, },
@@ -571,6 +591,26 @@ const Home = () => {
: item.ProductionYear : item.ProductionYear
} }
cardOrientation="landscape" cardOrientation="landscape"
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
); );
}, },
@@ -630,6 +670,26 @@ const Home = () => {
.PlayedPercentage .PlayedPercentage
} }
cardOrientation="landscape" cardOrientation="landscape"
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
); );
}, },
@@ -674,6 +734,26 @@ const Home = () => {
.PlayedPercentage .PlayedPercentage
} }
cardOrientation="sqaure" cardOrientation="sqaure"
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
); );
}, },
+20
View File
@@ -367,6 +367,26 @@ const LibraryView = () => {
item.UserData item.UserData
.UnplayedItemCount .UnplayedItemCount
} }
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
></Card> ></Card>
</Grid2> </Grid2>
); );