refactor: move more components to ts

This commit is contained in:
Prayag Prajapati committed 2024-12-03 19:01:17 +05:30
1 parent e049ce9ad6
commit 97526e29b4
12 files changed
+180 -267

No files matched your search

+21 -17
View File
@@ -1,5 +1,5 @@
import { useApiInContext } from "@/utils/store/api";
import { playItemFromQueue, usePlaybackStore } from "@/utils/store/playback";
import { playItemFromQueue } from "@/utils/store/playback";
import useQueue from "@/utils/store/queue";
import { Button, Typography } from "@mui/material";
import React from "react";
@@ -7,8 +7,8 @@ import { getTypeIcon } from "../utils/iconsCollection";
import "./outroCard.scss";
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { useMutation, useQuery } from "@tanstack/react-query";
import { useCentralStore } from "@/utils/store/central";
import { useMutation } from "@tanstack/react-query";
const OutroCard = (props: { handleShowCredits: () => void }) => {
const api = useApiInContext((s) => s.api);
@@ -16,19 +16,14 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
s.currentItemIndex,
s.tracks,
]);
const item = queueItems[nextItemIndex + 1];
const user = useQuery({
queryKey: ["user"],
queryFn: async () => {
const result = await getUserApi(api).getCurrentUser();
return result.data;
},
});
const item = queueItems?.[nextItemIndex + 1];
const user = useCentralStore((s) => s.currentUser);
const handlePlayNext = useMutation({
mutationKey: ["playNextButton"],
mutationFn: () => playItemFromQueue("next", user.data?.Id, api),
mutationFn: () => playItemFromQueue("next", user?.Id, api),
onError: (error) => [console.error(error)],
});
if (!item || !item.Type) return null;
return (
<div className="outro-card">
<Typography variant="h4">Up Next</Typography>
@@ -37,14 +32,21 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
<img
className="outro-card-content-image"
alt={item.Name ?? "Cover"}
src={getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", {
tag: item.ImageTags.Primary,
quality: 80,
})}
src={
api &&
getImageUrlsApi(api).getItemImageUrlById(
item.Id ?? "",
"Primary",
{
tag: item.ImageTags.Primary,
quality: 80,
},
)
}
/>
) : (
<div className="outro-card-content-image icon">
{getTypeIcon(item?.Type)}
{getTypeIcon(item.Type)}
</div>
)}
<Typography variant="h5" className="outro-card-content-title">
@@ -56,6 +58,7 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
<div className="outro-card-content-buttons">
<Button
onClick={handlePlayNext.mutate}
//@ts-ignore
color="white"
variant="contained"
startIcon={
@@ -74,6 +77,7 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
</Button>
<Button
onClick={props.handleShowCredits}
//@ts-ignore
color="white"
variant="outlined"
>
+1 -1
View File
@@ -22,7 +22,7 @@
&-image {
grid-area: img;
max-height: 14em;
aspect-ratio: 16/9;
width: 20em;
object-fit: cover;
border-radius: $border-radius-default;
+3 -77
View File
@@ -1,5 +1,5 @@
import { getRuntimeMusic } from "@/utils/date/time";
import useQueue, { setQueue } from "@/utils/store/queue";
import useQueue from "@/utils/store/queue";
import { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";
@@ -7,9 +7,6 @@ import { CSS } from "@dnd-kit/utilities";
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
import { Typography } from "@mui/material";
import React from "react";
import { useCallback, useRef } from "react";
import { type XYCoord, useDrag, useDrop } from "react-dnd";
import type { Identifier } from "typescript";
@@ -19,84 +16,13 @@ type Props = {
};
const QueueTrack = (props: Props) => {
const { track, index } = props;
const [queue, currentItemIndex] = useQueue((s) => [
s.tracks,
s.currentItemIndex,
]);
const [currentItemIndex] = useQueue((s) => [s.currentItemIndex]);
const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({
id: track.Id,
id: track.Id ?? "",
});
// const trackRef = useRef<HTMLDivElement | null>(null);
// const handleQueueUpdate = useCallback(
// (dragIndex: number, dropIndex: number) => {
// const prevState = queue;
// prevState.splice(dropIndex, 0, prevState.splice(dragIndex, 1)[0]);
// setQueue(prevState, dropIndex);
// },
// [queue],
// );
// const [{ handlerId }, drop] = useDrop<
// {
// index: number;
// id: string;
// type: string;
// },
// void,
// { handlerId: Identifier | null }
// >({
// accept: "Row",
// collect(monitor) {
// return {
// handlerId: monitor.getHandlerId(),
// };
// },
// hover(hoverItem, monitor) {
// console.log(hoverItem);
// if (!trackRef.current) return;
// const dragIndex = hoverItem.index;
// const dropIndex = index;
// if (dragIndex === dropIndex) return;
// const hoverBoundingRect = trackRef.current?.getBoundingClientRect();
// const hoverMiddleY =
// (hoverBoundingRect.bottom - hoverBoundingRect.top) / 2;
// const clientOffset = monitor.getClientOffset();
// const hoverClientY = (clientOffset as XYCoord).y - hoverBoundingRect.top;
// if (dragIndex < dropIndex && hoverClientY < hoverMiddleY) {
// return;
// }
// if (dragIndex > dropIndex && hoverClientY > hoverMiddleY) {
// return;
// }
// handleQueueUpdate(dragIndex, dropIndex);
// hoverItem.index = dropIndex;
// },
// });
// const [{ isDragging }, drag] = useDrag({
// type: "Row",
// item: () => {
// const id = track.Id;
// return { id, index };
// },
// collect: (monitor) => ({
// isDragging: monitor.isDragging(),
// }),
// });
// drag(drop(trackRef));
const style = {
// opacity: isDragging ? 0.5 : 1,
transform: CSS.Transform.toString(transform),
+9 -3
View File
@@ -1,15 +1,20 @@
import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography";
import React from "react";
import { useEffect, useRef, useState } from "react";
const ShowMoreText = ({
content,
collapsedLines,
extraProps,
}: { content: string; collapsedLines: number; extraProps?: unknown }) => {
}: {
content: string;
collapsedLines: number;
extraProps?: Record<string, any>;
}) => {
const [displayFull, setDisplayFull] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef(null);
const textRef = useRef<HTMLDivElement>(null);
useEffect(() => {
if (textRef.current) {
@@ -33,7 +38,7 @@ const ShowMoreText = ({
>
<Typography
ref={textRef}
key={displayFull}
key={displayFull ? "full" : "collapsed"}
style={{
display: "-webkit-box",
textOverflow: "ellipsis",
@@ -49,6 +54,7 @@ const ShowMoreText = ({
</Typography>
{content.length > 0 && isOverflowing && (
<Button
//@ts-ignore
color="white"
variant="outlined"
onClick={() => setDisplayFull((state) => !state)}
-26
View File
@@ -1,26 +0,0 @@
import Box from "@mui/material/Box";
import Card from "@mui/material/Card";
import CardActionArea from "@mui/material/CardActionArea";
import CardContent from "@mui/material/CardContent";
import CardMedia from "@mui/material/CardMedia";
import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography";
export const CardsSkeleton = () => {
return (
<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%" }} />
</Skeleton>
</div>
);
};
+34
View File
@@ -0,0 +1,34 @@
import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography";
import React from "react";
export const CardsSkeleton = () => {
return (
<div
style={{
display: "flex",
flexFlow: "column",
marginBottom: "2em",
}}
>
<Typography variant="h3" sx={{ mb: "0.15em" }}>
<Skeleton width="35%" />
</Typography>
<div className="flex flex-align-center" style={{ height: "17em" }}>
{Array.from({ length: 12 }).map((_, index) => (
<Skeleton
height="26em"
sx={{
flex: "1 0 12.45%",
marginRight: "1.5em",
borderRadius: "10px",
animationDelay: `${index * 0.25}s`,
}}
// biome-ignore lint/suspicious/noArrayIndexKey: This is a skeleton component
key={index}
/>
))}
</div>
</div>
);
};
@@ -1,22 +1,15 @@
import Box from "@mui/material/Box";
import Paper from "@mui/material/Paper";
import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography";
import React from "react";
import { theme } from "../../theme";
export const CarouselSkeleton = () => {
return (
<Paper
className="hero-carousel-skeleton"
elevation={0}
sx={{
<div
className="hero-carousel hero-carousel-skeleton"
style={{
height: "70vh",
marginBottom: "3.2em",
position: "relative",
background: "black",
border: "1px solid rgb(255 255 255 / 0.2)",
borderRadius: "10px",
overflow: "hidden",
width: "100vw",
marginLeft: "-4.4em",
}}
>
<div className="hero-carousel-detail">
@@ -29,9 +22,13 @@ export const CarouselSkeleton = () => {
/>
</Typography>
<Typography
variant="p"
variant="body1"
className="hero-carousel-text"
style={{ display: "flex", flexDirection: "column" }}
style={{
display: "flex",
flexDirection: "column",
paddingBottom: "4.4em",
}}
>
<Skeleton
variant="text"
@@ -53,6 +50,6 @@ export const CarouselSkeleton = () => {
/>
</Typography>
</div>
</Paper>
</div>
);
};
+90 -60
View File
@@ -2,66 +2,96 @@ import { Divider, Skeleton, Typography } from "@mui/material";
import React from "react";
const EpisodeSkeleton = () => {
return Array.from(new Array(8)).map((a, index) => {
return <>
<div
key={index}
style={{
width: "100%",
}}
className="item-detail-episode"
>
<Typography variant="h6"><Skeleton variant="circular" sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} /></Typography>
<div className="item-detail-episode-image-container">
<Skeleton className="item-detail-episode-image" variant="rectangular" sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} />
</div>
<div className="item-detail-episode-info">
<Typography variant="h4">
<Skeleton variant="text" width="10em" sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} />
</Typography>
<Skeleton variant="rounded" width="5em" style={{ borderRadius: "100px" }} sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} />
<Typography style={{
width: "100%"
}}>
<Skeleton width="100%" sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} />
<Skeleton width="100%" sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}} />
</Typography>
</div>
</div>
{index !== 7 && <Divider orientation="horizontal" flexItem />}
</>
})
return Array.from(new Array(8)).map((_, index) => {
return (
<div
// biome-ignore lint/suspicious/noArrayIndexKey: this is a skeleton
key={index}
style={{
width: "100%",
}}
>
<div className="item-detail-episode">
<Typography variant="h6">
<Skeleton
variant="circular"
sx={{
animationDelay: `${index * 0.25}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
aspectRatio: 1,
width: "3rem",
height: "3rem",
}}
/>
</Typography>
<div className="item-detail-episode-image-container">
<Skeleton
className="item-detail-episode-image"
variant="rectangular"
sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}}
/>
</div>
<div className="item-detail-episode-info">
<Typography variant="h4">
<Skeleton
variant="text"
width="10em"
sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}}
/>
</Typography>
<Skeleton
variant="rounded"
width="5em"
style={{ borderRadius: "100px" }}
sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}}
/>
<Typography
style={{
width: "100%",
}}
>
<Skeleton
width="100%"
sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}}
/>
<Skeleton
width="100%"
sx={{
animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s",
animationName: "pulse",
opacity: 0.1,
}}
/>
</Typography>
</div>
</div>
{index !== 7 && <Divider orientation="horizontal" flexItem />}
</div>
);
});
}
export default EpisodeSkeleton
-59
View File
@@ -1,59 +0,0 @@
import Card from "@mui/material/Card";
import CardContent from "@mui/material/CardContent";
import CardMedia from "@mui/material/CardMedia";
import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Unstable_Grid2";
export const EpisodeCardsSkeleton = () => {
return (
<Grid
container
columns={{
xs: 2,
sm: 3,
md: 4,
}}
sx={{ width: "100%" }}
>
{Array.from(new Array(4)).map((a) => {
return (
<Grid xs={1} sm={1} md={1} key={a}>
<Card sx={{ background: "transparent" }} elevation={0}>
<CardMedia>
<Skeleton
animation="wave"
variant="rectangular"
sx={{
aspectRatio: "1.777",
height: "auto",
m: 1,
borderRadius: "8px",
}}
/>
</CardMedia>
<CardContent
sx={{
padding: "0 0.5em",
alignItems: "flex-start",
backgroundColor: "transparent",
}}
>
<Typography variant="h6">
<Skeleton variant="text" animation="wave" />
</Typography>
<Typography variant="body2">
<Skeleton variant="text" animation="wave" />
<Skeleton variant="text" animation="wave" />
<Skeleton variant="text" animation="wave" />
</Typography>
</CardContent>
</Card>
</Grid>
);
})}
</Grid>
);
};
@@ -1,12 +1,13 @@
import Divider from "@mui/material/Divider";
import Grid from "@mui/material/Grid2";
import Grid2 from "@mui/material/Grid2";
import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography";
import React from "react";
import EpisodeSkeleton from "./episode";
export const SeasonSelectorSkeleton = () => {
return (
<Grid
<Grid2
container
columns={{
xs: 2,
@@ -44,8 +45,8 @@ export const SeasonSelectorSkeleton = () => {
}}
/>
<div className="item-detail-episode-container">
<EpisodeSkeleton/>
<EpisodeSkeleton />
</div>
</Grid>
</Grid2>
);
};