Remove a lot of Box components, replace sx with style, move from npm to pnpm, etc...

This commit is contained in:
Prayag Prajapati committed 2023-09-11 15:16:54 +05:30
1 parent 5c425b65c6
commit 5caa9b084f
20 files changed
+2472 -3468

No files matched your search

+6 -6
View File
@@ -113,10 +113,10 @@ export const AppBar = () => {
paddingLeft: "12px !important",
}}
>
<Box
sx={{
<div
style={{
display: "flex",
gap: 1,
gap: "1em",
alignItems: "center",
}}
>
@@ -149,8 +149,8 @@ export const AppBar = () => {
<IconButton>
<MdiMagnify />
</IconButton>
</Box>
<Box sx={{ display: "flex", gap: 2 }}>
</div>
<div style={{ display: "flex", gap: "2em" }}>
<IconButton disabled>
<MdiHeartOutline />
</IconButton>
@@ -215,7 +215,7 @@ export const AppBar = () => {
Remove Server
</MenuItem>
</Menu>
</Box>
</div>
</Toolbar>
</MuiAppBar>
);
+4 -2
View File
@@ -142,7 +142,7 @@ const PlayButton = ({
<LinearProgress
variant="determinate"
value={
!!itemUserData.PlayedPercentage
100 > itemUserData.PlayedPercentage > 0
? itemUserData.PlayedPercentage
: 0
}
@@ -159,7 +159,9 @@ const PlayButton = ({
}}
color="white"
/>
{itemUserData.PlayedPercentage > 0 ? "Resume" : "Play"}
{100 > itemUserData.PlayedPercentage > 0
? "Resume"
: "Play"}
</Button>
);
}
+19 -53
View File
@@ -3,7 +3,6 @@ import PropTypes from "prop-types";
import { useNavigate } from "react-router-dom";
import Box from "@mui/material/Box";
import Stack from "@mui/material/Stack";
import MuiCard from "@mui/material/Card";
import CardActionArea from "@mui/material/CardActionArea";
@@ -71,63 +70,31 @@ export const Card = ({
justifyContent="center"
mr={1}
>
<Box
<div
className="card-image-container"
sx={{
style={{
aspectRatio: cardImageAspectRatios[cardType],
overflow: "hidden",
height: "auto",
width: "100%",
zIndex: 0,
}}
>
{!!item.UserData && (
<>
<Box
sx={{
position: "absolute",
top: "0.4em",
right: "0.4em",
zIndex: 2,
background:
"rgb(20 20 20 / 0.5)",
padding: "0.2em 0.75em",
display: "flex",
alignItems: "center",
justifyContent: "center",
borderRadius: "100px",
backdropFilter: "blur(5px)",
transition: "opacity 250ms",
<div
className="card-indicator check"
style={{
opacity: item.UserData?.Played
? 1
: 0,
boxShadow:
"0 0 5px rgb(0 0 0 / 0.2)",
}}
>
<MdiCheck />
</Box>
<Box
sx={{
position: "absolute",
top: "0.4em",
right: "0.4em",
zIndex: 2,
background:
"rgb(20 20 20 / 0.5)",
padding: "0.2em 0.75em",
display: "flex",
alignItems: "center",
justifyContent: "center",
borderRadius: "100px",
backdropFilter: "blur(5px)",
transition: "opacity 250ms",
opacity: item.UserData
</div>
<div
className={`card-indicator text`}
style={{
opacity: !!item.UserData
?.UnplayedItemCount
? 1
: 0,
boxShadow:
"0 0 5px rgb(0 0 0 / 0.2)",
}}
>
<Typography
@@ -140,7 +107,7 @@ export const Card = ({
?.UnplayedItemCount
}
</Typography>
</Box>
</div>
</>
)}
{!!imageBlurhash && (
@@ -153,11 +120,11 @@ export const Card = ({
className="card-image-blurhash"
/>
)}
<Box className="card-image-icon-container">
<div className="card-image-icon-container">
{!!overrideIcon
? TypeIconCollectionCard[overrideIcon]
: TypeIconCollectionCard[item.Type]}
</Box>
</div>
<img
src={
overrideIcon == "User"
@@ -184,7 +151,7 @@ export const Card = ({
className="card-image"
/>
{!disableOverlay && (
<Box className="card-overlay">
<div className="card-overlay">
<PlayButton
itemId={item.Id}
userId={userId}
@@ -214,9 +181,9 @@ export const Card = ({
queryKey={queryKey}
userId={userId}
/>
</Box>
</div>
)}
{Boolean(item.UserData?.PlayedPercentage) && (
{100 > item.UserData?.PlayedPercentage > 0 && (
<LinearProgress
variant="determinate"
value={item.UserData.PlayedPercentage}
@@ -234,10 +201,9 @@ export const Card = ({
color="primary"
/>
)}
</Box>
<Box
</div>
<div
className="card-text-container"
height="15%"
style={{ display: hideText ? "none" : "block" }}
>
<Typography
@@ -258,7 +224,7 @@ export const Card = ({
>
{cardCaption}
</Typography>
</Box>
</div>
</Stack>
</MuiCard>
</CardActionArea>
+23
View File
@@ -14,6 +14,9 @@
width: 100%;
border-radius: $border-radius-default;
box-shadow: 0 4px 8px rgb(0 0 0 / 0.2);
overflow: hidden;
height: auto;
z-index: 0;
}
&-icon {
position: absolute;
@@ -71,4 +74,24 @@
transform: translate(-50%, -50%);
z-index: 1;
}
&-indicator {
position: absolute;
top: 0.4em;
right: 0.4em;
z-index: 2;
padding: 0.2em 0.75em;
background: rgb(20 20 20 / 0.5);
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(5px);
transition: opacity 250ms;
border-radius: 100px;
box-shadow: 0 0 5px rgb(0 0 0 / 0.2);
}
&-text {
&-container {
height: 15%;
}
}
}
+2
View File
@@ -1,6 +1,8 @@
/** @format */
.carousel {
position: relative;
height: 100vh;
&-button {
position: absolute !important;
top: 50%;
+8 -9
View File
@@ -2,7 +2,6 @@
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";
@@ -27,7 +26,7 @@ const Carousel = ({ content, onChange }) => {
}, [currentSlide]);
return (
<Box className="carousel" position="relative" height="100vh">
<div className="carousel">
<IconButton
className="carousel-button left"
onClick={() => {
@@ -96,14 +95,14 @@ const Carousel = ({ content, onChange }) => {
>
<MdiChevronRight />
</IconButton>
<Box className="carousel-indicator-container">
<Box
<div className="carousel-indicator-container">
<div
className={
currentSlide == 0
? "carousel-indicator active"
: "carousel-indicator"
}
sx={{
style={{
background:
currentSlide == 0
? "white"
@@ -115,14 +114,14 @@ const Carousel = ({ content, onChange }) => {
}}
/>
{content.map((item, index) => (
<Box
<div
className={
currentSlide == index + 1
? "carousel-indicator active"
: "carousel-indicator"
}
key={index}
sx={{
style={{
background:
currentSlide == index + 1
? "white"
@@ -138,8 +137,8 @@ const Carousel = ({ content, onChange }) => {
}}
/>
))}
</Box>
</Box>
</div>
</div>
);
};
+20 -19
View File
@@ -1,11 +1,10 @@
/** @format */
import { memo } from "react";
import React, { memo } from "react";
import { Blurhash } from "react-blurhash";
import { motion } from "framer-motion";
import Paper from "@mui/material/Paper";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import Stack from "@mui/material/Stack";
import Chip from "@mui/material/Chip";
@@ -20,21 +19,25 @@ import { MdiStar } from "../icons/mdiStar";
import { endsAt, getRuntime } from "../../utils/date/time";
import { useNavigate } from "react-router-dom";
import { MediaTypeIconCollection } from "../utils/iconsCollection";
import { MdiPlayOutline } from "../icons/mdiPlayOutline";
import { MdiChevronRight } from "../icons/mdiChevronRight";
import { MdiHeart } from "../icons/mdiHeart";
import { MdiHeartOutline } from "../icons/mdiHeartOutline";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useQuery } from "@tanstack/react-query";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { useSnackbar } from "notistack";
import LikeButton from "../buttons/likeButton";
import MarkPlayedButton from "../buttons/markPlayedButton";
import { theme } from "../../theme";
import { useCarouselStore } from "../../utils/store/carousel";
import PlayButton from "../buttons/playButton";
/**
* @typedef {Object} Props
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item
*/
/**
* @description Carousel slide component
* @param {Props}
* @returns {React.Component}
*/
const CarouselSlide = ({ item }) => {
const navigate = useNavigate();
@@ -105,9 +108,7 @@ const CarouselSlide = ({ item }) => {
{MediaTypeIconCollection[item.Type]}
</div>
</div>
<Box
component={motion.div}
// variants={slideAnim}
<motion.div
initial={{
transform:
animationDirection == "right"
@@ -168,8 +169,8 @@ const CarouselSlide = ({ item }) => {
direction="row"
gap={1}
divider={
<Box
sx={{
<div
style={{
width: "4px",
height: "4px",
background: "white",
@@ -177,7 +178,7 @@ const CarouselSlide = ({ item }) => {
aspectRatio: 1,
borderRadius: "10px",
}}
></Box>
></div>
}
className="hero-carousel-info"
>
@@ -190,8 +191,8 @@ const CarouselSlide = ({ item }) => {
variant="filled"
label={item.OfficialRating ?? "Not Rated"}
/>
<Box
sx={{
<div
style={{
display: "flex",
gap: "0.25em",
alignItems: "center",
@@ -217,7 +218,7 @@ const CarouselSlide = ({ item }) => {
No Community Rating
</Typography>
)}
</Box>
</div>
{!!item.RunTimeTicks && (
<Typography variant="subtitle1">
{getRuntime(item.RunTimeTicks)}
@@ -293,7 +294,7 @@ const CarouselSlide = ({ item }) => {
/>
</Stack>
</Stack>
</Box>
</motion.div>
</Paper>
</ErrorBoundary>
);
+181 -116
View File
@@ -1,5 +1,7 @@
/** @format */
import { useEffect, useState } from "react";
import PropTypes from "prop-types";
import React, { useEffect, useState } from "react";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import Chip from "@mui/material/Chip";
@@ -7,7 +9,11 @@ import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import LinearProgress from "@mui/material/LinearProgress";
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client";
// import { BaseItemDto } from "";
// import { BaseItemPerson } from "@jellyfin/sdk/lib/generated-client/models/base-item-person";
import { BaseItemKind } from "@jellyfin/sdk/lib/generated-client/models/base-item-kind";
import { MediaStreamType } from "@jellyfin/sdk/lib/generated-client/models/media-stream-type";
import { Card } from "../../card/card";
import { MdiStar } from "../../icons/mdiStar";
import { yellow } from "@mui/material/colors";
@@ -20,6 +26,22 @@ import "./hero.module.scss";
import { Blurhash } from "react-blurhash";
import { MediaTypeIconCollection } from "../../utils/iconsCollection";
/**
* @typedef {Object} Props
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemDto} item
* @property {Array} queryKey
* @property {string} userId
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemPerson[]} writers
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemPerson[]} directors
* @property {import("@jellyfin/sdk/lib/generated-client/models").BaseItemPerson[]} artists
*
*/
/**
* @description Hero section for item pages
* @param {Props}
* @returns {React.Component}
*/
const Hero = ({
item,
queryKey,
@@ -27,19 +49,48 @@ const Hero = ({
writers = [],
directors = [],
artists = [],
videoTracks = [],
audioTracks = [],
subtitleTracks = [],
}) => {
const filterMediaStreamVideo = (source) => {
if (source.Type == MediaStreamType.Video) {
return true;
}
return false;
};
const filterMediaStreamAudio = (source) => {
if (source.Type == MediaStreamType.Audio) {
return true;
}
return false;
};
const filterMediaStreamSubtitle = (source) => {
if (source.Type == MediaStreamType.Subtitle) {
return true;
}
return false;
};
const videoTracks = item.MediaStreams?.filter(filterMediaStreamVideo);
const audioTracks = item.MediaStreams?.filter(filterMediaStreamAudio);
const subtitleTracks = item.MediaStreams?.filter(
filterMediaStreamSubtitle,
);
const [currentVideoIndex, setCurrentVideoIndex] = useState("");
const [currentAudioIndex, setCurrentAudioIndex] = useState("");
const [currentSubtitleIndex, setCurrentSubtitleIndex] = useState("");
useEffect(() => {
setCurrentVideoIndex(videoTracks[0]?.Index);
setCurrentAudioIndex(audioTracks[0]?.Index);
setCurrentSubtitleIndex(subtitleTracks[0]?.Index);
console.error(
JSON.stringify([videoTracks, audioTracks, subtitleTracks]) +
`${new Date()}`,
);
if (!!videoTracks && !!audioTracks & !!subtitleTracks) {
setCurrentVideoIndex(videoTracks[0]?.Index);
setCurrentAudioIndex(audioTracks[0]?.Index);
setCurrentSubtitleIndex(subtitleTracks[0]?.Index);
}
}, [videoTracks, audioTracks, subtitleTracks]);
return (
<div
className="item-detail-hero"
@@ -220,7 +271,7 @@ const Hero = ({
{item.Genres.join(", ")}
</Typography>
</div>
{item.UserData?.PlayedPercentage > 0 && (
{100 > item.UserData?.PlayedPercentage > 0 && (
<div
style={{
display: "flex",
@@ -293,112 +344,123 @@ const Hero = ({
maxWidth: "60%",
}}
>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Video
</Typography>
<TextField
size="small"
value={currentVideoIndex}
select
onChange={(e) =>
setCurrentVideoIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{videoTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Audio
</Typography>
<TextField
size="small"
value={currentAudioIndex}
select
onChange={(e) =>
setCurrentAudioIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{audioTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Subtitle
</Typography>
<TextField
size="small"
value={currentSubtitleIndex}
select
onChange={(e) =>
setCurrentSubtitleIndex(e.target.value)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{subtitleTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
{Boolean(videoTracks?.length) && (
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Video
</Typography>
<TextField
size="small"
value={currentVideoIndex}
select
onChange={(e) =>
setCurrentVideoIndex(
e.target.value,
)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{videoTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
)}
{Boolean(audioTracks?.length) && (
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Audio
</Typography>
<TextField
size="small"
value={currentAudioIndex}
select
onChange={(e) =>
setCurrentAudioIndex(
e.target.value,
)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{audioTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
)}
{Boolean(subtitleTracks?.length) && (
<div className="hero-grid">
<Typography
variant="subtitle1"
style={{
opacity: 0.6,
}}
noWrap
>
Subtitle
</Typography>
<TextField
size="small"
value={currentSubtitleIndex}
select
onChange={(e) =>
setCurrentSubtitleIndex(
e.target.value,
)
}
SelectProps={{
MenuProps: {
disableScrollLock: true,
},
}}
>
{subtitleTracks.map((track, index) => {
return (
<MenuItem
key={track.Index}
value={track.Index}
>
{track.DisplayTitle}
</MenuItem>
);
})}
</TextField>
</div>
)}
</div>
<div
style={{
@@ -432,7 +494,10 @@ const Hero = ({
</Typography>
<Typography variant="subtitle1">
{writers
.map((writer) => writer.Name)
.map(
(writer, index) =>
writer.Name,
)
.join(", ")}
</Typography>
</div>
+8 -2
View File
@@ -10,13 +10,19 @@ import Box from "@mui/material/Box";
export const CardsSkeleton = () => {
return (
<Box sx={{ display: "flex", flexFlow: "column", mb: 4 }}>
<div
style={{
display: "flex",
flexFlow: "column",
marginBottom: "2em",
}}
>
<Typography variant="h4" sx={{ mb: "0.15em" }}>
<Skeleton width="35%" animation="wave" />
</Typography>
<Skeleton width="100%" variant="rounded" animation="wave">
<div style={{ paddingTop: "20%" }}></div>
</Skeleton>
</Box>
</div>
);
};
+2 -2
View File
@@ -29,7 +29,7 @@ export const CarouselSkeleton = () => {
}}
></Skeleton>
</div>
<Box className="hero-carousel-detail">
<div className="hero-carousel-detail">
<Typography variant="h3" className="hero-carousel-text">
<Skeleton
variant="text"
@@ -46,7 +46,7 @@ export const CarouselSkeleton = () => {
animation="wave"
></Skeleton>
</Typography>
</Box>
</div>
</Paper>
);
};