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
+139 -226

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "blink", "name": "blink",
"private": true, "private": true,
"version": "0.0.6-dev", "version": "0.0.7-dev",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite --force && tsr watch", "dev": "vite --force && tsr watch",
+19 -15
View File
@@ -1,5 +1,5 @@
import { useApiInContext } from "@/utils/store/api"; 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 useQueue from "@/utils/store/queue";
import { Button, Typography } from "@mui/material"; import { Button, Typography } from "@mui/material";
import React from "react"; import React from "react";
@@ -7,8 +7,8 @@ import { getTypeIcon } from "../utils/iconsCollection";
import "./outroCard.scss"; import "./outroCard.scss";
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi"; import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { useCentralStore } from "@/utils/store/central";
import { useMutation, useQuery } from "@tanstack/react-query"; import { useMutation } from "@tanstack/react-query";
const OutroCard = (props: { handleShowCredits: () => void }) => { const OutroCard = (props: { handleShowCredits: () => void }) => {
const api = useApiInContext((s) => s.api); const api = useApiInContext((s) => s.api);
@@ -16,19 +16,14 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
s.currentItemIndex, s.currentItemIndex,
s.tracks, s.tracks,
]); ]);
const item = queueItems[nextItemIndex + 1]; const item = queueItems?.[nextItemIndex + 1];
const user = useQuery({ const user = useCentralStore((s) => s.currentUser);
queryKey: ["user"],
queryFn: async () => {
const result = await getUserApi(api).getCurrentUser();
return result.data;
},
});
const handlePlayNext = useMutation({ const handlePlayNext = useMutation({
mutationKey: ["playNextButton"], mutationKey: ["playNextButton"],
mutationFn: () => playItemFromQueue("next", user.data?.Id, api), mutationFn: () => playItemFromQueue("next", user?.Id, api),
onError: (error) => [console.error(error)], onError: (error) => [console.error(error)],
}); });
if (!item || !item.Type) return null;
return ( return (
<div className="outro-card"> <div className="outro-card">
<Typography variant="h4">Up Next</Typography> <Typography variant="h4">Up Next</Typography>
@@ -37,14 +32,21 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
<img <img
className="outro-card-content-image" className="outro-card-content-image"
alt={item.Name ?? "Cover"} alt={item.Name ?? "Cover"}
src={getImageUrlsApi(api).getItemImageUrlById(item.Id, "Primary", { src={
api &&
getImageUrlsApi(api).getItemImageUrlById(
item.Id ?? "",
"Primary",
{
tag: item.ImageTags.Primary, tag: item.ImageTags.Primary,
quality: 80, quality: 80,
})} },
)
}
/> />
) : ( ) : (
<div className="outro-card-content-image icon"> <div className="outro-card-content-image icon">
{getTypeIcon(item?.Type)} {getTypeIcon(item.Type)}
</div> </div>
)} )}
<Typography variant="h5" className="outro-card-content-title"> <Typography variant="h5" className="outro-card-content-title">
@@ -56,6 +58,7 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
<div className="outro-card-content-buttons"> <div className="outro-card-content-buttons">
<Button <Button
onClick={handlePlayNext.mutate} onClick={handlePlayNext.mutate}
//@ts-ignore
color="white" color="white"
variant="contained" variant="contained"
startIcon={ startIcon={
@@ -74,6 +77,7 @@ const OutroCard = (props: { handleShowCredits: () => void }) => {
</Button> </Button>
<Button <Button
onClick={props.handleShowCredits} onClick={props.handleShowCredits}
//@ts-ignore
color="white" color="white"
variant="outlined" variant="outlined"
> >
+1 -1
View File
@@ -22,7 +22,7 @@
&-image { &-image {
grid-area: img; grid-area: img;
max-height: 14em; aspect-ratio: 16/9;
width: 20em; width: 20em;
object-fit: cover; object-fit: cover;
border-radius: $border-radius-default; border-radius: $border-radius-default;
+3 -77
View File
@@ -1,5 +1,5 @@
import { getRuntimeMusic } from "@/utils/date/time"; 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 { useSortable } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities"; 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 type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import React from "react"; 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 QueueTrack = (props: Props) => {
const { track, index } = props; const { track, index } = props;
const [queue, currentItemIndex] = useQueue((s) => [ const [currentItemIndex] = useQueue((s) => [s.currentItemIndex]);
s.tracks,
s.currentItemIndex,
]);
const { attributes, listeners, setNodeRef, transform, transition } = const { attributes, listeners, setNodeRef, transform, transition } =
useSortable({ 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 = { const style = {
// opacity: isDragging ? 0.5 : 1, // opacity: isDragging ? 0.5 : 1,
transform: CSS.Transform.toString(transform), transform: CSS.Transform.toString(transform),
+9 -3
View File
@@ -1,15 +1,20 @@
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import React from "react";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
const ShowMoreText = ({ const ShowMoreText = ({
content, content,
collapsedLines, collapsedLines,
extraProps, extraProps,
}: { content: string; collapsedLines: number; extraProps?: unknown }) => { }: {
content: string;
collapsedLines: number;
extraProps?: Record<string, any>;
}) => {
const [displayFull, setDisplayFull] = useState(false); const [displayFull, setDisplayFull] = useState(false);
const [isOverflowing, setIsOverflowing] = useState(false); const [isOverflowing, setIsOverflowing] = useState(false);
const textRef = useRef(null); const textRef = useRef<HTMLDivElement>(null);
useEffect(() => { useEffect(() => {
if (textRef.current) { if (textRef.current) {
@@ -33,7 +38,7 @@ const ShowMoreText = ({
> >
<Typography <Typography
ref={textRef} ref={textRef}
key={displayFull} key={displayFull ? "full" : "collapsed"}
style={{ style={{
display: "-webkit-box", display: "-webkit-box",
textOverflow: "ellipsis", textOverflow: "ellipsis",
@@ -49,6 +54,7 @@ const ShowMoreText = ({
</Typography> </Typography>
{content.length > 0 && isOverflowing && ( {content.length > 0 && isOverflowing && (
<Button <Button
//@ts-ignore
color="white" color="white"
variant="outlined" variant="outlined"
onClick={() => setDisplayFull((state) => !state)} 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 Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import React from "react"; import React from "react";
import { theme } from "../../theme";
export const CarouselSkeleton = () => { export const CarouselSkeleton = () => {
return ( return (
<Paper <div
className="hero-carousel-skeleton" className="hero-carousel hero-carousel-skeleton"
elevation={0} style={{
sx={{
height: "70vh", height: "70vh",
marginBottom: "3.2em",
position: "relative", position: "relative",
background: "black", width: "100vw",
border: "1px solid rgb(255 255 255 / 0.2)", marginLeft: "-4.4em",
borderRadius: "10px",
overflow: "hidden",
}} }}
> >
<div className="hero-carousel-detail"> <div className="hero-carousel-detail">
@@ -29,9 +22,13 @@ export const CarouselSkeleton = () => {
/> />
</Typography> </Typography>
<Typography <Typography
variant="p" variant="body1"
className="hero-carousel-text" className="hero-carousel-text"
style={{ display: "flex", flexDirection: "column" }} style={{
display: "flex",
flexDirection: "column",
paddingBottom: "4.4em",
}}
> >
<Skeleton <Skeleton
variant="text" variant="text"
@@ -53,6 +50,6 @@ export const CarouselSkeleton = () => {
/> />
</Typography> </Typography>
</div> </div>
</Paper> </div>
); );
}; };
+52 -22
View File
@@ -2,66 +2,96 @@ import { Divider, Skeleton, Typography } from "@mui/material";
import React from "react"; import React from "react";
const EpisodeSkeleton = () => { const EpisodeSkeleton = () => {
return Array.from(new Array(8)).map((a, index) => { return Array.from(new Array(8)).map((_, index) => {
return <> return (
<div <div
// biome-ignore lint/suspicious/noArrayIndexKey: this is a skeleton
key={index} key={index}
style={{ style={{
width: "100%", width: "100%",
}} }}
className="item-detail-episode"
> >
<Typography variant="h6"><Skeleton variant="circular" sx={{ <div className="item-detail-episode">
animationDelay: `${index * 0.2}s`, <Typography variant="h6">
<Skeleton
variant="circular"
sx={{
animationDelay: `${index * 0.25}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /></Typography> aspectRatio: 1,
width: "3rem",
height: "3rem",
}}
/>
</Typography>
<div className="item-detail-episode-image-container"> <div className="item-detail-episode-image-container">
<Skeleton className="item-detail-episode-image" variant="rectangular" sx={{ <Skeleton
className="item-detail-episode-image"
variant="rectangular"
sx={{
animationDelay: `${index * 0.2}s`, animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /> }}
/>
</div> </div>
<div className="item-detail-episode-info"> <div className="item-detail-episode-info">
<Typography variant="h4"> <Typography variant="h4">
<Skeleton variant="text" width="10em" sx={{ <Skeleton
variant="text"
width="10em"
sx={{
animationDelay: `${index * 0.2}s`, animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /> }}
/>
</Typography> </Typography>
<Skeleton variant="rounded" width="5em" style={{ borderRadius: "100px" }} sx={{ <Skeleton
variant="rounded"
width="5em"
style={{ borderRadius: "100px" }}
sx={{
animationDelay: `${index * 0.2}s`, animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /> }}
<Typography style={{ />
width: "100%" <Typography
}}> style={{
<Skeleton width="100%" sx={{ width: "100%",
}}
>
<Skeleton
width="100%"
sx={{
animationDelay: `${index * 0.2}s`, animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /> }}
<Skeleton width="100%" sx={{ />
<Skeleton
width="100%"
sx={{
animationDelay: `${index * 0.2}s`, animationDelay: `${index * 0.2}s`,
animationDuration: "1.4s", animationDuration: "1.4s",
animationName: "pulse", animationName: "pulse",
opacity: 0.1, opacity: 0.1,
}} /> }}
/>
</Typography> </Typography>
</div> </div>
</div> </div>
{index !== 7 && <Divider orientation="horizontal" flexItem />} {index !== 7 && <Divider orientation="horizontal" flexItem />}
</div>
</> );
}) });
} }
export default EpisodeSkeleton 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 Divider from "@mui/material/Divider";
import Grid from "@mui/material/Grid2"; import Grid2 from "@mui/material/Grid2";
import Skeleton from "@mui/material/Skeleton"; import Skeleton from "@mui/material/Skeleton";
import Typography from "@mui/material/Typography"; import Typography from "@mui/material/Typography";
import React from "react";
import EpisodeSkeleton from "./episode"; import EpisodeSkeleton from "./episode";
export const SeasonSelectorSkeleton = () => { export const SeasonSelectorSkeleton = () => {
return ( return (
<Grid <Grid2
container container
columns={{ columns={{
xs: 2, xs: 2,
@@ -46,6 +47,6 @@ export const SeasonSelectorSkeleton = () => {
<div className="item-detail-episode-container"> <div className="item-detail-episode-container">
<EpisodeSkeleton /> <EpisodeSkeleton />
</div> </div>
</Grid> </Grid2>
); );
}; };
+4 -4
View File
@@ -370,24 +370,24 @@ function AudioPlayerRoute() {
</div> </div>
</SortableContext> </SortableContext>
<DragOverlay modifiers={[restrictToWindowEdges]}> <DragOverlay modifiers={[restrictToWindowEdges]}>
{currentDraggingIndex && currentDraggingIndex >= 0 && ( {(currentDraggingIndex ?? -1) >= 0 && (
<div className="audio-queue-track dragging"> <div className="audio-queue-track dragging">
<span className="material-symbols-rounded">drag_handle</span> <span className="material-symbols-rounded">drag_handle</span>
<div className="audio-queue-track-info"> <div className="audio-queue-track-info">
<Typography className="audio-queue-track-info-name"> <Typography className="audio-queue-track-info-name">
{queue[currentDraggingIndex].Name} {queue[currentDraggingIndex ?? 0].Name}
</Typography> </Typography>
<Typography <Typography
fontWeight={300} fontWeight={300}
className="opacity-07" className="opacity-07"
variant="subtitle2" variant="subtitle2"
> >
{queue[currentDraggingIndex].Artists?.join(", ")} {queue[currentDraggingIndex ?? 0].Artists?.join(", ")}
</Typography> </Typography>
</div> </div>
<Typography className="opacity-07"> <Typography className="opacity-07">
{getRuntimeMusic( {getRuntimeMusic(
queue[currentDraggingIndex].RunTimeTicks ?? 0, queue[currentDraggingIndex ?? 0].RunTimeTicks ?? 0,
)} )}
</Typography> </Typography>
</div> </div>