Skip to content

Commit

Permalink
Add blurhash support to cards #153
Browse files Browse the repository at this point in the history
  • Loading branch information
prayag17 committed Aug 29, 2023
1 parent 8210906 commit 7dd5fd8
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 110 deletions.
196 changes: 98 additions & 98 deletions package-lock.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/components/card/card.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const Card = ({
isFavorite,
isPlayed,
imageType = "Primary",
imageBlurhash,
cardType,
secondaryText,
queryKey,
Expand Down Expand Up @@ -97,6 +98,16 @@ export const Card = ({
width: "100%",
}}
>
{!!imageBlurhash && (
<Blurhash
hash={imageBlurhash}
width={128}
height={128}
resolutionX={24}
resolutionY={24}
className="card-image-blurhash"
/>
)}
<Box className="card-image-icon-container">
{TypeIconCollectionCard[itemType]}
</Box>
Expand Down
10 changes: 9 additions & 1 deletion src/components/card/card.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
object-fit: cover;
transition: opacity $transition-time-fast;
position: absolute;
z-index: 0;
z-index: 1;
top: 0;
left: 0;
&-container {
Expand All @@ -31,6 +31,14 @@
z-index: 0;
}
}
&-blurhash {
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
}
}
&-overlay {
position: absolute;
Expand Down
11 changes: 9 additions & 2 deletions src/components/carousel/carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
}
}
&-indicator {
height: 5px;
height: 2px;
width: 100%;
border-radius: 10px;
transition: background $transition-time-fast;
transition: background $transition-time-fast,
height $transition-time-fast;
&:hover {
cursor: pointer;
height: 5px;
background: rgb(255 255 255 / 0.8) !important;
}
&-container {
Expand All @@ -30,6 +32,11 @@
left: 1em;
right: 1em;
gap: 1em;
align-items: center;
justify-content: center;
}
&.active {
height: 5px;
}
}
}
29 changes: 21 additions & 8 deletions src/components/carousel/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MdiChevronRight } from "../icons/mdiChevronRight";
import "./carousel.scss";
import { useCarouselStore } from "../../utils/store/carousel";

const swipeConfidenceThreshold = 10000;
const swipeConfidenceThreshold = 8000;
const swipePower = (offset, velocity) => {
return Math.abs(offset) * velocity;
};
Expand Down Expand Up @@ -50,18 +50,23 @@ const Carousel = ({ content, onChange }) => {
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{
duration: 0.5,
duration: 0.3,
}}
drag="x"
drag={"x"}
dragConstraints={{ left: 0, right: 0 }}
dragElastic={1}
onDragEnd={(e, { offset, velocity }) => {
const swipe = swipePower(offset.x, velocity.x);

if (swipe < -swipeConfidenceThreshold) {
if (
currentSlide != content.length - 1 &&
swipe < -swipeConfidenceThreshold
) {
setDirection("right");
setCurrentSlide((init) => init + 1);
} else if (swipe > swipeConfidenceThreshold) {
} else if (
currentSlide != 0 &&
swipe > swipeConfidenceThreshold
) {
setDirection("left");
setCurrentSlide((init) => init - 1);
}
Expand Down Expand Up @@ -92,7 +97,11 @@ const Carousel = ({ content, onChange }) => {
</IconButton>
<Box className="carousel-indicator-container">
<Box
className="carousel-indicator"
className={
currentSlide == 0
? "carousel-indicator active"
: "carousel-indicator"
}
sx={{
background:
currentSlide == 0
Expand All @@ -106,7 +115,11 @@ const Carousel = ({ content, onChange }) => {
/>
{content.map((item, index) => (
<Box
className="carousel-indicator"
className={
currentSlide == index + 1
? "carousel-indicator active"
: "carousel-indicator"
}
key={index}
sx={{
background:
Expand Down
2 changes: 1 addition & 1 deletion src/components/carouselSlide/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const CarouselSlide = ({ item }) => {
opacity: 0,
}}
transition={{
duration: 0.25,
duration: 0.15,
}}
className="hero-carousel-detail"
>
Expand Down
7 changes: 7 additions & 0 deletions src/components/homeSection/latestMediaSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
queryKey={["home", "resume", "video"]}
isPlayed={item.UserData.Played}
userId={user.data.Id}
imageBlurhash={
item.ImageBlurHashes?.Primary[
Object.keys(
item.ImageBlurHashes.Primary,
)[0]
]
}
></Card>
);
})}
Expand Down
41 changes: 41 additions & 0 deletions src/routes/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ const Home = () => {
`/library/${item.Id}`,
)
}
imageBlurhash={
item
.ImageBlurHashes
?.Primary[
Object.keys(
item
.ImageBlurHashes
.Primary,
)[0]
]
}
></Card>
);
},
Expand Down Expand Up @@ -298,6 +309,16 @@ const Home = () => {
item.UserData.Played
}
userId={user.data.Id}
imageBlurhash={
item.ImageBlurHashes
?.Primary[
Object.keys(
item
.ImageBlurHashes
.Primary,
)[0]
]
}
></Card>
);
},
Expand Down Expand Up @@ -352,6 +373,16 @@ const Home = () => {
item.UserData.Played
}
userId={user.data.Id}
imageBlurhash={
item.ImageBlurHashes
?.Primary[
Object.keys(
item
.ImageBlurHashes
.Primary,
)[0]
]
}
></Card>
);
},
Expand Down Expand Up @@ -398,6 +429,16 @@ const Home = () => {
item.UserData.Played
}
userId={user.data.Id}
imageBlurhash={
item.ImageBlurHashes
?.Primary[
Object.keys(
item
.ImageBlurHashes
.Primary,
)[0]
]
}
></Card>
);
},
Expand Down

0 comments on commit 7dd5fd8

Please sign in to comment.