Add new hero carousel and start working on cards #153

This commit is contained in:
Prayag Prajapati committed 2023-08-24 17:25:07 +05:30
1 parent 7f8ec6fc98
commit e11056c2ce
13 files changed
+355 -916

No files matched your search

-115
View File
@@ -28,7 +28,6 @@
"react-blurhash": "^0.3.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.10",
"react-material-ui-carousel": "^3.4.2",
"react-multi-carousel": "^2.8.3",
"react-player": "^2.12.0",
"react-router-dom": "^6.14.0",
@@ -945,31 +944,6 @@
"url": "https://opencollective.com/mui"
}
},
"node_modules/@mui/icons-material": {
"version": "5.14.3",
"resolved": "https://registry.npmjs.org/@mui/icons-material/-/icons-material-5.14.3.tgz",
"integrity": "sha512-XkxWPhageu1OPUm2LWjo5XqeQ0t2xfGe8EiLkRW9oz2LHMMZmijvCxulhgquUVTF1DnoSh+3KoDLSsoAFtVNVw==",
"dependencies": {
"@babel/runtime": "^7.22.6"
},
"engines": {
"node": ">=12.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/mui"
},
"peerDependencies": {
"@mui/material": "^5.0.0",
"@types/react": "^17.0.0 || ^18.0.0",
"react": "^17.0.0 || ^18.0.0"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@mui/lab": {
"version": "5.0.0-alpha.140",
"resolved": "https://registry.npmjs.org/@mui/lab/-/lab-5.0.0-alpha.140.tgz",
@@ -2279,14 +2253,6 @@
"integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==",
"optional": true
},
"node_modules/framesync": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/framesync/-/framesync-5.3.0.tgz",
"integrity": "sha512-oc5m68HDO/tuK2blj7ZcdEBRx3p1PjrgHazL8GYEpvULhrtGIFbQArN6cQS2QhW8mitffaB+VYzMjDqBxxQeoA==",
"dependencies": {
"tslib": "^2.1.0"
}
},
"node_modules/fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
@@ -2360,11 +2326,6 @@
"node": ">=4"
}
},
"node_modules/hey-listen": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/hey-listen/-/hey-listen-1.0.8.tgz",
"integrity": "sha512-COpmrF2NOg4TBWUJ5UVyaCU2A88wEMkUPK4hNqyCkqHbxT92BbvfjoSozkAIIm6XhicGlJHhFdullInrdhwU8Q=="
},
"node_modules/hoist-non-react-statics": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
@@ -2694,17 +2655,6 @@
"url": "https://github.com/sponsors/jonschlinkert"
}
},
"node_modules/popmotion": {
"version": "9.3.6",
"resolved": "https://registry.npmjs.org/popmotion/-/popmotion-9.3.6.tgz",
"integrity": "sha512-ZTbXiu6zIggXzIliMi8LGxXBF5ST+wkpXGEjeTUDUOCdSQ356hij/xjeUdv0F8zCQNeqB1+PR5/BB+gC+QLAPw==",
"dependencies": {
"framesync": "5.3.0",
"hey-listen": "^1.0.8",
"style-value-types": "4.1.4",
"tslib": "^2.1.0"
}
},
"node_modules/postcss": {
"version": "8.4.27",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.27.tgz",
@@ -2805,62 +2755,6 @@
"resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz",
"integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w=="
},
"node_modules/react-material-ui-carousel": {
"version": "3.4.2",
"resolved": "https://registry.npmjs.org/react-material-ui-carousel/-/react-material-ui-carousel-3.4.2.tgz",
"integrity": "sha512-jUbC5aBWqbbbUOOdUe3zTVf4kMiZFwKJqwhxzHgBfklaXQbSopis4iWAHvEOLcZtSIJk4JAGxKE0CmxDoxvUuw==",
"dependencies": {
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.6.0",
"@mui/icons-material": "^5.4.1",
"@mui/material": "^5.4.1",
"@mui/system": "^5.4.1",
"framer-motion": "^4.1.17"
},
"peerDependencies": {
"@emotion/react": "^11.4.1",
"@emotion/styled": "^11.3.0",
"@mui/icons-material": "^5.0.0",
"@mui/material": "^5.0.0",
"@mui/system": "^5.0.0",
"react": "^17.0.1 || ^18.0.0",
"react-dom": "^17.0.2 || ^18.0.0"
}
},
"node_modules/react-material-ui-carousel/node_modules/@emotion/is-prop-valid": {
"version": "0.8.8",
"resolved": "https://registry.npmjs.org/@emotion/is-prop-valid/-/is-prop-valid-0.8.8.tgz",
"integrity": "sha512-u5WtneEAr5IDG2Wv65yhunPSMLIpuKsbuOktRojfrEiEvRyC85LgPMZI63cr7NUqT8ZIGdSVg8ZKGxIug4lXcA==",
"optional": true,
"dependencies": {
"@emotion/memoize": "0.7.4"
}
},
"node_modules/react-material-ui-carousel/node_modules/@emotion/memoize": {
"version": "0.7.4",
"resolved": "https://registry.npmjs.org/@emotion/memoize/-/memoize-0.7.4.tgz",
"integrity": "sha512-Ja/Vfqe3HpuzRsG1oBtWTHk2PGZ7GR+2Vz5iYGelAw8dx32K0y7PjVuxK6z1nMpZOqAFsRUPCkK1YjJ56qJlgw==",
"optional": true
},
"node_modules/react-material-ui-carousel/node_modules/framer-motion": {
"version": "4.1.17",
"resolved": "https://registry.npmjs.org/framer-motion/-/framer-motion-4.1.17.tgz",
"integrity": "sha512-thx1wvKzblzbs0XaK2X0G1JuwIdARcoNOW7VVwjO8BUltzXPyONGAElLu6CiCScsOQRI7FIk/45YTFtJw5Yozw==",
"dependencies": {
"framesync": "5.3.0",
"hey-listen": "^1.0.8",
"popmotion": "9.3.6",
"style-value-types": "4.1.4",
"tslib": "^2.1.0"
},
"optionalDependencies": {
"@emotion/is-prop-valid": "^0.8.2"
},
"peerDependencies": {
"react": ">=16.8 || ^17.0.0",
"react-dom": ">=16.8 || ^17.0.0"
}
},
"node_modules/react-multi-carousel": {
"version": "2.8.4",
"resolved": "https://registry.npmjs.org/react-multi-carousel/-/react-multi-carousel-2.8.4.tgz",
@@ -3057,15 +2951,6 @@
"node": ">=0.10.0"
}
},
"node_modules/style-value-types": {
"version": "4.1.4",
"resolved": "https://registry.npmjs.org/style-value-types/-/style-value-types-4.1.4.tgz",
"integrity": "sha512-LCJL6tB+vPSUoxgUBt9juXIlNJHtBMy8jkXzUJSBzeHWdBu6lhzHqCvLVkXFGsFIlNa2ln1sQHya/gzaFmB2Lg==",
"dependencies": {
"hey-listen": "^1.0.8",
"tslib": "^2.1.0"
}
},
"node_modules/stylis": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/stylis/-/stylis-4.2.0.tgz",
-1
View File
@@ -29,7 +29,6 @@
"react-blurhash": "^0.3.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.10",
"react-material-ui-carousel": "^3.4.2",
"react-multi-carousel": "^2.8.3",
"react-player": "^2.12.0",
"react-router-dom": "^6.14.0",
+1 -1
View File
@@ -380,7 +380,7 @@ function App() {
opacity: 0,
}}
transition={{
duration: 1.5,
duration: 0.5,
}}
onLoad={() => setBackdropLoading(false)}
loading="eager"
+48 -351
View File
@@ -1,11 +1,11 @@
/** @format */
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";
import Box from "@mui/material/Box";
import MuiCard from "@mui/material/Card";
import Stack from "@mui/material/Stack";
import CardContent from "@mui/material/CardContent";
import CardMedia from "@mui/material/CardMedia";
import CardActionArea from "@mui/material/CardActionArea";
@@ -31,373 +31,70 @@ import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { MdiHeartOutline } from "../icons/mdiHeartOutline";
import { MdiHeart } from "../icons/mdiHeart";
import useIntersecting from "../../utils/hooks/useIntersecting";
export const Card = ({
itemName,
itemId,
itemParentId,
itemName,
imageTags,
iconType,
cardType = "",
subText = "",
playedPercent,
cardOrientation,
cardProps,
onClickEvent,
watchedStatus,
watchedCount,
blurhash,
currentUser,
favourite,
disableOverlay,
imageType = "Primary",
parentImageType,
imageAspectRatio,
}) => {
const navigate = useNavigate();
const [imgLoading, setImgLoading] = useState(true);
const [isWatched, setIsWatched] = useState(watchedStatus);
const [isFavorite, setisFavorite] = useState(favourite);
const [watchedCountState, setWatchedCountState] = useState(watchedCount);
const handleMarkAsPlayOrUnMarkAsPlay = async () => {
let result;
if (!isWatched) {
result = await getPlaystateApi(window.api).markPlayedItem({
userId: currentUser.Id,
itemId: itemId,
});
} else if (isWatched) {
result = await getPlaystateApi(window.api).markUnplayedItem({
userId: currentUser.Id,
itemId: itemId,
});
}
setIsWatched(result.data.Played);
setWatchedCountState(result.data.UnplayedItemCount);
};
const handleLiking = async () => {
let result;
if (isFavorite) {
result = await getUserLibraryApi(window.api).unmarkFavoriteItem({
userId: currentUser.Id,
itemId: itemId,
});
} else if (!isFavorite) {
result = await getUserLibraryApi(window.api).markFavoriteItem({
userId: currentUser.Id,
itemId: itemId,
});
}
setisFavorite(result.data.IsFavorite);
};
const availableMarkButtonTypes = [
"Audio",
"AudioBook",
"Book",
"BoxSet",
"CollectionFolder",
"Movie",
"Season",
"Series",
"Video",
"Episode",
];
const allowedLikeButton = [
"Audio",
"AudioBook",
"Book",
"BoxSet",
"CollectionFolder",
"Movie",
"MusicAlbum",
"MusicVideo",
"Season",
"Series",
"Video",
"Channel",
"MusicAlbum",
"MusicArtist",
"Person",
"Photo",
"Playlist",
"Studio",
"Episode",
];
const ref = useRef();
const isVisible = useIntersecting(ref);
return (
<MuiCard
className={"card " + cardOrientation}
sx={{
background: "transparent",
borderRadius: borderRadiusDefault,
mr: 1,
}}
elevation={0}
{...cardProps}
>
<CardActionArea
sx={{ p: "1px" }}
component={Box}
onClick={
!!onClickEvent
? onClickEvent
: () => {
navigate(`/item/${itemId}`);
}
}
className="cardBox"
<Box mr={2} ref={ref} sx={{ height: "100%", overflow: "visible" }}>
<Stack
className={isVisible ? "card isVisible" : "card"}
sx={{
width: "100%",
height: "100%",
position: "relative",
overflow: "visible",
}}
direction="column"
justifyContent="center"
mr={1}
>
<Box
className="card-media-container"
className="card-image-container"
sx={{
position: "relative",
m: 1,
aspectRatio:
cardOrientation == "landscape"
? "1.777"
: cardOrientation == "portait"
? "0.666"
: "1",
aspectRatio: imageAspectRatio,
overflow: "hidden",
}}
height="85%"
>
<>
<Chip
className="card-indicator"
label={<MdiCheck />}
sx={{
transition: "opacity 150ms",
opacity: isWatched ? 1 : 0,
}}
/>
{!!watchedCountState && (
<Chip
className="card-indicator card-indicator-text"
label={watchedCountState}
></Chip>
<img
src={window.api.getItemImageUrl(
itemId,
imageType,
{
quality: 90,
fillHeight: 512,
fillWidth: 512,
},
)}
<div
className="card-media-image-container"
style={{ opacity: imgLoading ? 0 : 1 }}
// style={{ opacity: 1 }}
>
{imageTags &&
(cardType == "thumb" ? (
<CardMedia
component="img"
image={
window.api.basePath +
"/Items/" +
itemId +
"/Images/Backdrop?fillHeight=300&fillWidth=532&quality=96"
}
alt={itemName}
sx={{
width: "100%",
aspectRatio:
cardOrientation ==
"landscape"
? "1.777"
: cardOrientation ==
"portait"
? "0.666"
: "1",
borderRadius:
borderRadiusDefault,
overflow: "hidden",
}}
onLoad={() =>
setImgLoading(false)
}
className="card-image"
></CardMedia>
) : (
<CardMedia
component="img"
image={
iconType == "User"
? window.api
.basePath +
"/Users/" +
itemId +
"/Images/Primary?fillHeight=532&fillWidth=300&quality=96"
: window.api
.basePath +
"/Items/" +
itemId +
"/Images/Primary?fillHeight=532&fillWidth=300&quality=96"
}
alt={itemName}
sx={{
width: "100%",
aspectRatio:
cardOrientation ==
"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={24}
resolutionY={24}
style={{
aspectRatio:
cardOrientation == "landscape"
? "1.777"
: cardOrientation ==
"portait"
? "0.666"
: "1",
}}
className="card-image-blurhash"
/>
)}
<div className="card-image-icon-container">
{cardType == "lib"
? MediaCollectionTypeIconCollectionCard[
iconType
]
: TypeIconCollectionCard[iconType]}
</div>
{!!playedPercent && (
<LinearProgress
variant="determinate"
value={playedPercent}
sx={{
width: "90%",
position: "absolute",
left: "5%",
bottom: "5%",
borderRadius: "100px",
height: "5px",
}}
/>
)}
</>
{!disableOverlay && (
<Box
className="card-media-overlay"
sx={{
display: "flex",
alignItems: "flex-end",
justifyContent: "flex-end",
p: 1,
}}
>
<ButtonGroup>
{availableMarkButtonTypes.includes(
iconType,
) && (
<IconButton
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleMarkAsPlayOrUnMarkAsPlay();
}}
onFocus={(e) =>
e.stopPropagation
}
>
<MdiCheck
sx={{
color: isWatched
? green[400]
: "white",
}}
/>
</IconButton>
)}
{allowedLikeButton.includes(
iconType,
) && (
<IconButton
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleLiking();
}}
onFocus={(e) =>
e.stopPropagation
}
>
{isFavorite ? (
<MdiHeart
sx={{
color: pink[700],
}}
/>
) : (
<MdiHeartOutline />
)}
</IconButton>
)}
</ButtonGroup>
</Box>
)}
style={{
height: "100%",
}}
className="card-image"
/>
</Box>
<CardContent
className="card-text-container"
sx={{
padding: "0 0.5em",
backgroundColor: "transparent",
}}
>
<Box className="card-text-container" height="15%">
<Typography
gutterBottom={false}
variant="h6"
component="div"
color="white"
fontWeight={500}
textAlign="left"
variant="h5"
fontWeight={300}
noWrap
width="fit-content"
maxWidth="100%"
textAlign="center"
>
{itemName}
</Typography>
<Typography
gutterBottom
variant="subtitle1"
component="div"
textAlign="left"
width="fit-content"
maxWidth="100%"
noWrap
sx={{ opacity: 0.5 }}
>
{subText}
</Typography>
</CardContent>
</CardActionArea>
</MuiCard>
</Box>
</Stack>
</Box>
);
};
Card.propTypes = {
itemName: PropTypes.string.isRequired,
itemId: PropTypes.string.isRequired,
imageTags: PropTypes.bool,
iconType: PropTypes.string.isRequired,
cardType: PropTypes.string,
subText: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
playedPercent: PropTypes.number,
cardOrientation: PropTypes.string.isRequired,
onClickEvent: PropTypes.func,
watchedStatus: PropTypes.bool,
watchedCount: PropTypes.number,
blurhash: PropTypes.string,
currentUser: PropTypes.object,
favourite: PropTypes.bool,
};
Card.propTypes = {};
+4 -82
View File
@@ -1,92 +1,14 @@
/** @format */
.card {
border-radius: $border-radius-default;
&-media {
&-container {
position: relative;
border-radius: $border-radius-default;
overflow: hidden;
box-shadow: 0 0 7px rgb(0 0 0 / 0.2);
}
&-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgb(0 0 0 / 0.6);
opacity: 0;
transition: opacity $transition-time-default;
z-index: 10;
}
&-image-container {
transition: opacity $transition-time-default;
}
}
&Box:hover .card-media-overlay,
&Box:focus-within .card-media-overlay,
&Box:focus .card-media-overlay {
opacity: 1;
}
&-image {
position: relative;
border-radius: $border-radius-default;
background-size: cover;
background-position: center;
width: 100%;
height: 100%;
object-fit: cover;
&-container {
position: relative;
border-radius: $border-radius-default;
overflow: hidden;
}
&-icon {
font-size: 4.5em !important;
fill: url(#clr-gradient-default) !important;
&-container {
display: flex !important;
aspect-ratio: 1.777;
justify-content: center;
align-items: center;
width: 100% !important;
color: transparent;
background: $clr-gradient-dark;
border-radius: 10px;
position: absolute;
top: 0;
bottom: 0;
height: 100%;
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 {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
&-indicator {
position: absolute;
right: 5px;
top: 5px;
z-index: 10;
// border-radius: 100px;
background: $clr-gradient-default;
box-shadow: 0 0 5px rgb(0 0 0 / 0.4);
&-text {
aspect-ratio: 1;
padding: 5px !important;
box-shadow: 0 4px 8px rgb(0 0 0 / 0.2);
}
}
}
+35
View File
@@ -0,0 +1,35 @@
/** @format */
.carousel {
&-button {
position: absolute !important;
top: 50%;
transform: translateY(-50%);
z-index: 100;
&.right {
right: 0.5em;
}
&.left {
left: 0;
}
}
&-indicator {
height: 5px;
width: 100%;
border-radius: 10px;
transition: background $transition-time-fast;
&:hover {
cursor: pointer;
background: rgb(255 255 255 / 0.8) !important;
}
&-container {
display: flex;
position: absolute;
bottom: 1em;
width: calc(100vw - 2em);
left: 1em;
right: 1em;
gap: 1em;
}
}
}
+122
View File
@@ -0,0 +1,122 @@
/** @format */
import { useEffect, useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import Box from "@mui/material/Box";
import IconButton from "@mui/material/IconButton";
import { MdiChevronLeft } from "../icons/mdiChevronLeft";
import { MdiChevronRight } from "../icons/mdiChevronRight";
import "./carousel.scss";
import { useCarouselStore } from "../../utils/store/carousel";
const swipeConfidenceThreshold = 10000;
const swipePower = (offset, velocity) => {
return Math.abs(offset) * velocity;
};
const Carousel = ({ content, onChange }) => {
const [currentSlide, setCurrentSlide] = useState(0);
const [setDirection, dir] = useCarouselStore((state) => [
state.setDirection,
state.direction,
]);
useEffect(() => {
onChange(currentSlide);
}, [currentSlide]);
return (
<Box className="carousel" position="relative" height="100vh">
<IconButton
className="carousel-button left"
onClick={() => {
if (currentSlide > 0) {
setDirection("left");
setCurrentSlide((init) => init - 1);
}
}}
sx={{
background: " rgb(200 200 200 / 0.05)",
}}
disabled={currentSlide == 0}
>
<MdiChevronLeft />
</IconButton>
<AnimatePresence>
<motion.div
key={currentSlide}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{
duration: 0.5,
}}
drag="x"
dragConstraints={{ left: 0, right: 0 }}
dragElastic={1}
onDragEnd={(e, { offset, velocity }) => {
const swipe = swipePower(offset.x, velocity.x);
if (swipe < -swipeConfidenceThreshold) {
setDirection("right");
setCurrentSlide((init) => init + 1);
} else if (swipe > swipeConfidenceThreshold) {
setDirection("left");
setCurrentSlide((init) => init - 1);
}
}}
style={{
height: "100vh",
width: "100vw",
position: "absolute",
}}
>
{content[currentSlide]}
</motion.div>
</AnimatePresence>
<IconButton
className="carousel-button right"
onClick={() => {
if (currentSlide < content.length - 1) {
setDirection("right");
setCurrentSlide((init) => init + 1);
}
}}
disabled={currentSlide == content.length - 1}
sx={{
background: " rgb(200 200 200 / 0.05)",
}}
>
<MdiChevronRight />
</IconButton>
<Box className="carousel-indicator-container">
<Box
className="carousel-indicator"
sx={{
background:
currentSlide == 0
? "white"
: "rgb(255 255 255 / 0.5)",
}}
onClick={() => setCurrentSlide(0)}
/>
{content.map((item, index) => (
<Box
className="carousel-indicator"
key={index}
sx={{
background:
currentSlide == index + 1
? "white"
: "rgb(255 255 255 / 0.5)",
}}
onClick={() => setCurrentSlide(index + 1)}
/>
))}
</Box>
</Box>
);
};
export default Carousel;
+74 -99
View File
@@ -32,6 +32,7 @@ import { useSnackbar } from "notistack";
import LikeButton from "../buttons/likeButton";
import MarkPlayedButton from "../buttons/markPlayedButton";
import { theme } from "../../theme";
import { useCarouselStore } from "../../utils/store/carousel";
const CarouselSlide = ({ item }) => {
const navigate = useNavigate();
@@ -45,9 +46,9 @@ const CarouselSlide = ({ item }) => {
networkMode: "always",
});
// consoe;
// const favouriteButtonMutation =
const [animationDirection] = useCarouselStore((state) => [
state.direction,
]);
return (
<ErrorBoundary fallback={<CarouselSlideError itemName={item.Name} />}>
@@ -56,66 +57,84 @@ const CarouselSlide = ({ item }) => {
sx={{
background: "transparent",
px: 3,
boxShadow: "none !important",
}}
>
<div className="hero-carousel-background-container">
{!!item.ImageBlurHashes.Backdrop &&
Object.keys(item.ImageBlurHashes.Backdrop)
.length != 0 && (
<Blurhash
hash={
item.ImageBlurHashes.Backdrop[
Object.keys(
item.ImageBlurHashes
.Backdrop,
)[0]
]
{!!item.ImageBlurHashes.Backdrop && (
<>
{Object.keys(item.ImageBlurHashes.Backdrop)
.length != 0 && (
<Blurhash
hash={
item.ImageBlurHashes.Backdrop[
Object.keys(
item.ImageBlurHashes
.Backdrop,
)[0]
]
}
// hash="LEHV6nWB2yk8pyo0adR*.7kCMdnj"
width="1080"
height="720"
resolutionX={64}
resolutionY={96}
className="hero-carousel-background-blurhash"
punch={1}
/>
)}
<img
className="hero-carousel-background-image"
src={
!!item.ParentBackdropItemId
? `${window.api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
: `${window.api.basePath}/Items/${item.Id}/Images/Backdrop`
}
// hash="LEHV6nWB2yk8pyo0adR*.7kCMdnj"
width="1080"
height="720"
resolutionX={64}
resolutionY={96}
className="hero-carousel-background-blurhash"
punch={1}
onLoad={(e) =>
(e.target.style.opacity = 1)
}
loading="eager"
/>
)}
<div
className="hero-carousel-background-image"
style={{
backgroundImage: !!item.ParentBackdropItemId
? `url('${window.api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop')`
: `url('${window.api.basePath}/Items/${item.Id}/Images/Backdrop')`,
}}
></div>
</>
)}
<div className="hero-carousel-background-icon-container">
{MediaTypeIconCollection[item.Type]}
</div>
</div>
<Box className="hero-carousel-detail">
<Box
component={motion.div}
// variants={slideAnim}
initial={{
transform:
animationDirection == "right"
? "translateX(50px)"
: "translateX(-50px)",
opacity: 0,
}}
animate={{
transform: "translateX(0px)",
opacity: 1,
}}
exit={{
transform:
animationDirection == "right"
? "translateX(-50px)"
: "translateX(50px)",
opacity: 0,
}}
transition={{
duration: 0.2,
}}
className="hero-carousel-detail"
>
<Typography
component={motion.h2}
key={item.Id}
variant="h2"
className="hero-carousel-text"
sx={{
mb: 2.5,
}}
initial={{
y: 10,
opacity: 0,
}}
exit={{
y: 10,
opacity: 0,
}}
transition={{
duration: 0.35,
}}
whileInView={{
y: 0,
opacity: 1,
}}
overflow="visible"
>
{!item.ImageTags.Logo ? (
@@ -130,29 +149,19 @@ const CarouselSlide = ({ item }) => {
"/Images/Logo?quality=80&tag=" +
item.ImageTags.Logo
}
style={{
opacity: 0,
transition: "opacity 250ms",
}}
onLoad={(e) =>
(e.target.style.opacity = 1)
}
></img>
)}
</Typography>
<Stack
component={motion.div}
direction="row"
gap={1}
initial={{
y: 10,
opacity: 0,
}}
transition={{
duration: 0.25,
delay: 0.1,
}}
exit={{
y: 10,
opacity: 0,
}}
whileInView={{
y: 0,
opacity: 1,
}}
divider={
<Box
sx={{
@@ -216,29 +225,12 @@ const CarouselSlide = ({ item }) => {
)}
</Stack>
<Typography
component={motion.div}
initial={{
y: 10,
opacity: 0,
}}
transition={{
duration: 0.25,
delay: 0.2,
}}
whileInView={{
y: 0,
opacity: 0.7,
}}
exit={{
y: 10,
opacity: 0,
}}
variant="subtitle1"
className="hero-carousel-text"
sx={{
display: "-webkit-box",
maxWidth: "70%",
maxHeight: "30%",
maxHeight: "50%",
textOverflow: "ellipsis",
overflow: "hidden",
WebkitLineClamp: "4",
@@ -250,23 +242,6 @@ const CarouselSlide = ({ item }) => {
{/* TODO Link PLay and More info buttons in carousel */}
<Stack
component={motion.div}
initial={{
y: 10,
opacity: 0,
}}
transition={{
duration: 0.25,
delay: 0.4,
}}
whileInView={{
y: 0,
opacity: 1,
}}
exit={{
y: 10,
opacity: 0,
}}
mt={3}
direction="row"
gap={3}
@@ -44,54 +44,15 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
>
{data.data.map((item, index) => {
return (
<Card
key={index}
itemName={
!!item.SeriesId
? item.SeriesName
: item.Name
}
itemId={
!!item.SeriesId
? item.SeriesId
: item.Id
}
// imageTags={false}
imageTags={!!item.ImageTags.Primary}
iconType={item.Type}
subText={item.ProductionYear}
playedPercent={
item.UserData.PlayedPercentage
}
cardOrientation={
item.PrimaryImageAspectRatio == 1
? "sqaure"
: "portait"
}
watchedStatus={
item.Type == BaseItemKind.Audio
? false
: item.UserData.Played
}
watchedCount={
item.UserData.UnplayedItemCount
}
blurhash={
item.ImageBlurHashes == {}
? ""
: !!item.ImageTags.Primary
? !!item.ImageBlurHashes.Primary
? item.ImageBlurHashes
.Primary[
item.ImageTags
.Primary
]
: ""
: ""
}
currentUser={user.data}
favourite={item.UserData.IsFavorite}
></Card>
<></>
// <Card
// key={index}
// itemName={
// !!item.SeriesId
// ? item.SeriesName
// : item.Name
// }
// ></Card>
);
})}
</CardScroller>
+5 -1
View File
@@ -63,7 +63,11 @@
right: 0;
bottom: 0;
background-position: center;
opacity: 1;
opacity: 0;
object-fit: cover;
width: 100%;
height: 100%;
transition: opacity $transition-time-fast;
}
&-icon {
position: absolute;
+25 -218
View File
@@ -2,28 +2,17 @@
import { useState } from "react";
import { Blurhash } from "react-blurhash";
import { useQuery } from "@tanstack/react-query";
import { EventEmitter as event } from "../../eventEmitter";
import { getServer } from "../../utils/storage/servers";
import { getUser, delUser } from "../../utils/storage/user";
import { theme } from "../../theme";
import "./home.module.scss";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography";
import Chip from "@mui/material/Chip";
import LinearProgress from "@mui/material/LinearProgress";
import Stack from "@mui/material/Stack";
import { yellow } from "@mui/material/colors";
import Carousel from "react-material-ui-carousel";
import Carousel from "../../components/carousel";
// Custom Components
import { Card } from "../../components/card/card";
@@ -46,15 +35,10 @@ import { getTvShowsApi } from "@jellyfin/sdk/lib/utils/api/tv-shows-api";
import { useNavigate } from "react-router-dom";
import { endsAt, getRuntime } from "../../utils/date/time";
import { BaseItemKind, ItemFields } from "@jellyfin/sdk/lib/generated-client";
import CarouselSlideError from "../../components/errors/carousel";
import { motion } from "framer-motion";
import { useBackdropStore } from "../../utils/store/backdrop";
import CarouselSlide from "../../components/carouselSlide";
import { ItemFields } from "@jellyfin/sdk/lib/generated-client";
const Home = () => {
const authUser = useQuery({
queryKey: ["home", "authenticateUser"],
@@ -169,6 +153,10 @@ const Home = () => {
queryFn: async () => {
const upNext = await getTvShowsApi(window.api).getNextUp({
userId: user.data.Id,
fields: [
ItemFields.PrimaryImageAspectRatio,
ItemFields.ParentId,
],
limit: 10,
});
return upNext.data;
@@ -225,40 +213,9 @@ const Home = () => {
<CarouselSkeleton />
) : (
<Carousel
className="hero-carousel"
autoPlay={false}
animation="fade"
height="100vh"
// navButtonsAlwaysVisible
IndicatorIcon={
<div className="hero-carousel-indicator"></div>
}
activeIndicatorIconButtonProps={{
style: {
background: "rgb(255 255 255)",
},
}}
indicatorIconButtonProps={{
style: {
background: "rgb(255 255 255 / 0.3)",
borderRadius: "2px",
width: "100%",
flexShrink: "1",
},
}}
indicatorContainerProps={{
className:
"hero-carousel-indicator-container",
style: {
position: "absolute",
display: "flex",
gap: "1em",
zIndex: 1,
},
}}
sx={{
marginBottom: "1.5em",
}}
content={latestMedia.data?.map((item, index) => (
<CarouselSlide item={item} key={index} />
))}
onChange={(now) => {
if (latestMedia.isSuccess) {
if (
@@ -277,20 +234,7 @@ const Home = () => {
}
}
}}
changeOnFirstRender={true}
duration={400}
interval={10000}
>
{latestMedia.data.length != 0 &&
latestMedia.data.map((item, index) => {
return (
<CarouselSlide
item={item}
key={index}
/>
);
})}
</Carousel>
/>
)}
<Box
className="padded-container"
@@ -310,44 +254,8 @@ const Home = () => {
key={index}
itemName={item.Name}
itemId={item.Id}
// imageTags={false}
imageTags={
!!item
.ImageTags
.Primary
}
cardType="lib"
cardOrientation="landscape"
iconType={
item.CollectionType
}
onClickEvent={() => {
navigate(
`/library/${item.Id}`,
);
}}
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
currentUser={
user.data
imageAspectRatio={
item.PrimaryImageAspectRatio
}
></Card>
);
@@ -367,58 +275,11 @@ const Home = () => {
return (
<Card
key={index}
itemName={
!!item.SeriesId
? item.SeriesName
: item.Name
}
itemId={
!!item.SeriesId
? item.SeriesId
: item.Id
}
// imageTags={false}
imageTags={
!!item.ImageTags
.Primary
}
cardType="thumb"
iconType={item.Type}
subText={
!!item.SeriesId
? "S" +
item.ParentIndexNumber +
":E" +
item.IndexNumber +
" - " +
item.Name
: item.ProductionYear
}
cardOrientation="landscape"
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Primary
? !!item
.ImageBlurHashes
.Primary
? item
.ImageBlurHashes
.Primary[
item
.ImageTags
.Primary
]
: ""
: ""
}
currentUser={user.data}
favourite={
item.UserData
.IsFavorite
itemName={item.Name}
itemId={item.Id}
imageType="Primary"
imageAspectRatio={
item.PrimaryImageAspectRatio
}
></Card>
);
@@ -440,69 +301,15 @@ const Home = () => {
return (
<Card
key={index}
itemName={
!!item.SeriesId
? item.SeriesName
: item.Name
itemName={item.Name}
itemId={item.Id}
imageType={
!!item.SeriesName
? "Primary"
: "Backdrop"
}
itemId={
!!item.SeriesId
? item.SeriesId
: item.Id
}
// imageTags={false}
imageTags={
!!item.SeriesId
? item
.ParentBackdropImageTags
.length !=
0
: item
.BackdropImageTags
.length !=
0
}
cardType="thumb"
iconType={item.Type}
subText={
!!item.SeriesId
? "S" +
item.ParentIndexNumber +
":E" +
item.IndexNumber +
" - " +
item.Name
: item.ProductionYear
}
playedPercent={
item.UserData
.PlayedPercentage
}
cardOrientation="landscape"
blurhash={
item.ImageBlurHashes ==
{}
? ""
: !!item
.ImageTags
.Backdrop
? !!item
.ImageBlurHashes
.Backdrop
? item
.ImageBlurHashes
.Backdrop[
item
.ImageTags
.Backdrop
]
: ""
: ""
}
currentUser={user.data}
favourite={
item.UserData
.IsFavorite
imageAspectRatio={
item.PrimaryImageAspectRatio
}
></Card>
);
+24
View File
@@ -0,0 +1,24 @@
/** @format */
import { useEffect, useMemo, useState } from "react";
const useIntersecting = (ref) => {
const [isIntersecting, setIntersecting] = useState(false);
const observer = useMemo(
() =>
new IntersectionObserver(([entry]) =>
setIntersecting(entry.isIntersecting),
),
[ref],
);
useEffect(() => {
observer.observe(ref.current);
return () => observer.disconnect();
}, []);
return isIntersecting;
};
export default useIntersecting;
+8
View File
@@ -0,0 +1,8 @@
/** @format */
import { create } from "zustand";
export const useCarouselStore = create((set) => ({
direction: "right",
setDirection: (dir) => set(() => ({ direction: dir })),
}));