refactore: move more components to typescript
This commit is contained in:
14 files changed
+544
-682
No files matched your search
+102
-225
@@ -4,11 +4,7 @@ import Box from "@mui/material/Box";
|
||||
import CircularProgress from "@mui/material/CircularProgress";
|
||||
import Typography from "@mui/material/Typography";
|
||||
|
||||
import {
|
||||
type BaseItemDto,
|
||||
BaseItemKind,
|
||||
SortOrder,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { BaseItemKind, SortOrder } from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api/items-api";
|
||||
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
|
||||
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
|
||||
@@ -16,7 +12,7 @@ import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api"
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
|
||||
import { getRuntimeCompact, getRuntimeMusic } from "@/utils/date/time";
|
||||
import { getRuntimeCompact } from "@/utils/date/time";
|
||||
|
||||
import { Card } from "@/components/card/card";
|
||||
import CardScroller from "@/components/cardScroller/cardScroller";
|
||||
@@ -26,21 +22,16 @@ import PlayButton from "@/components/buttons/playButton";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
|
||||
import { getTypeIcon } from "@/components/utils/iconsCollection";
|
||||
import {
|
||||
generateAudioStreamUrl,
|
||||
playAudio,
|
||||
useAudioPlayback,
|
||||
} from "@/utils/store/audioPlayback";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import "./album.scss";
|
||||
|
||||
import AlbumMusicTrack from "@/components/albumMusicTrack";
|
||||
import TagChip from "@/components/tagChip";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
import { Chip } from "@mui/material";
|
||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||
import { useSnackbar } from "notistack";
|
||||
import lyricsIcon from "../../../assets/icons/lyrics.svg";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
export const Route = createFileRoute("/_api/album/$id")({
|
||||
component: MusicAlbumTitlePage,
|
||||
@@ -58,7 +49,6 @@ function MusicAlbumTitlePage() {
|
||||
}
|
||||
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const { enqueueSnackbar } = useSnackbar();
|
||||
|
||||
const item = useQuery({
|
||||
queryKey: ["item", id],
|
||||
@@ -135,33 +125,6 @@ function MusicAlbumTitlePage() {
|
||||
|
||||
const pageRef = useRef(null);
|
||||
|
||||
const handlePlayback = (
|
||||
index: number,
|
||||
item: BaseItemDto,
|
||||
queue: BaseItemDto[],
|
||||
) => {
|
||||
if (!user?.Id || !api) {
|
||||
console.error("User not logged in");
|
||||
enqueueSnackbar("You need to be logged in to play music", {
|
||||
variant: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (item.Id) {
|
||||
const url = generateAudioStreamUrl(
|
||||
item.Id,
|
||||
user.Id,
|
||||
api.deviceInfo.id,
|
||||
api.basePath,
|
||||
api.accessToken,
|
||||
);
|
||||
playAudio(url, item, undefined);
|
||||
setQueue(queue, index);
|
||||
}
|
||||
};
|
||||
|
||||
const currentPlayingItem = useAudioPlayback((s) => s.item);
|
||||
|
||||
if (item.isPending || similarItems.isPending) {
|
||||
return (
|
||||
<Box
|
||||
@@ -184,13 +147,22 @@ function MusicAlbumTitlePage() {
|
||||
className="scrollY padded-top item item-album"
|
||||
ref={pageRef}
|
||||
>
|
||||
<div className="item-info-container">
|
||||
<div className="item-info">
|
||||
<Typography className="item-info-name" variant="h3">
|
||||
{item.data.Name}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center item-info-album-info">
|
||||
<div className="flex flex-align-center">
|
||||
<div className="item-info">
|
||||
<Typography className="item-info-name" variant="h3">
|
||||
{item.data.Name}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center item-info-album-info">
|
||||
{/* @ts-ignore - Using Link as component */}
|
||||
<Chip
|
||||
component={Link}
|
||||
to="/artist/$id"
|
||||
params={{ id: item.data.AlbumArtists?.[0].Id ?? "" }}
|
||||
className="flex flex-align-center"
|
||||
style={{
|
||||
color: "white",
|
||||
textDecoration: "none",
|
||||
}}
|
||||
icon={
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{
|
||||
@@ -199,186 +171,90 @@ function MusicAlbumTitlePage() {
|
||||
>
|
||||
artist
|
||||
</span>
|
||||
<Typography ml={1}>{item.data.AlbumArtist}</Typography>
|
||||
</div>
|
||||
<Typography className="opacity-07">
|
||||
{item.data.ProductionYear}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{(musicTracks.data?.TotalRecordCount ?? 0) > 1
|
||||
? `${musicTracks.data?.TotalRecordCount} songs`
|
||||
: "1 song"}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-buttons">
|
||||
<PlayButton
|
||||
item={item.data}
|
||||
audio
|
||||
itemType={item.data.Type ?? "Audio"}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<LikeButton
|
||||
itemId={item.data.Id}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={item.data.Name}
|
||||
/>
|
||||
</div>
|
||||
<div className="item-info-track-container ">
|
||||
{allDiscs.length > 1 ? (
|
||||
allDiscs.map((disc) => (
|
||||
<div className="item-info-disc-container" key={disc}>
|
||||
<div className="item-info-disc-header flex flex-row flex-align-center">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "2em" }}
|
||||
>
|
||||
album
|
||||
</span>
|
||||
<Typography variant="h5">Disc {disc}</Typography>
|
||||
</div>
|
||||
<div className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">
|
||||
tag
|
||||
</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
{musicTracks.data?.Items?.map(
|
||||
(track, index) =>
|
||||
track.ParentIndexNumber === disc && (
|
||||
<div
|
||||
className={
|
||||
currentPlayingItem?.Id === track.Id
|
||||
? "item-info-track playing"
|
||||
: "item-info-track"
|
||||
}
|
||||
key={track.Id}
|
||||
onClick={() => {
|
||||
if (musicTracks.data.Items) {
|
||||
handlePlayback(
|
||||
index,
|
||||
track,
|
||||
musicTracks.data.Items,
|
||||
);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="index-container">
|
||||
<span className="material-symbols-rounded fill ">
|
||||
play_arrow
|
||||
</span>
|
||||
<Typography className="index">
|
||||
{track.IndexNumber ?? "-"}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-track-info">
|
||||
<Typography className="item-info-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.6,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6em",
|
||||
}}
|
||||
fontWeight={300}
|
||||
>
|
||||
{track.HasLyrics && (
|
||||
<img src={lyricsIcon} alt="lyrics" />
|
||||
)}
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography>
|
||||
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center">
|
||||
<LikeButton
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
}
|
||||
label={item.data.AlbumArtist}
|
||||
/>
|
||||
<Typography className="opacity-07">
|
||||
{item.data.ProductionYear}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{(musicTracks.data?.TotalRecordCount ?? 0) > 1
|
||||
? `${musicTracks.data?.TotalRecordCount} songs`
|
||||
: "1 song"}
|
||||
</Typography>
|
||||
<Typography className="opacity-07">
|
||||
{getRuntimeCompact(item.data.CumulativeRunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-buttons">
|
||||
<PlayButton
|
||||
item={item.data}
|
||||
audio
|
||||
itemType={item.data.Type ?? "Audio"}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<LikeButton
|
||||
itemId={item.data.Id}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={item.data.Name}
|
||||
/>
|
||||
</div>
|
||||
<div className="item-info-track-container ">
|
||||
{allDiscs.length > 1 ? (
|
||||
allDiscs.map((disc) => (
|
||||
<div className="item-info-disc-container" key={disc}>
|
||||
<div
|
||||
className="item-info-disc-header flex flex-row flex-align-center"
|
||||
style={{ marginBottom: "1em" }}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "2em" }}
|
||||
>
|
||||
album
|
||||
</span>
|
||||
<Typography variant="h5">Disc {disc}</Typography>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<>
|
||||
<div className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">tag</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
{musicTracks.data?.Items?.map((track, index) => (
|
||||
<div
|
||||
className={
|
||||
currentPlayingItem?.Id === track.Id
|
||||
? "item-info-track playing"
|
||||
: "item-info-track"
|
||||
}
|
||||
key={track.Id}
|
||||
onClick={() =>
|
||||
musicTracks.data.Items &&
|
||||
handlePlayback(index, track, musicTracks.data.Items)
|
||||
}
|
||||
>
|
||||
<div className="index-container">
|
||||
<span className="material-symbols-rounded fill ">
|
||||
play_arrow
|
||||
</span>
|
||||
<Typography className="index">
|
||||
{track.IndexNumber ?? "-"}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="item-info-track-info">
|
||||
<Typography className="item-info-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="subtitle2"
|
||||
style={{
|
||||
opacity: 0.6,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
gap: "0.6em",
|
||||
}}
|
||||
fontWeight={300}
|
||||
>
|
||||
{track.HasLyrics && (
|
||||
<img src={lyricsIcon} alt="lyrics" />
|
||||
)}
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography>
|
||||
{getRuntimeMusic(track.RunTimeTicks ?? 0)}
|
||||
</Typography>
|
||||
<div className="flex flex-align-center">
|
||||
<LikeButton
|
||||
itemId={track.Id}
|
||||
isFavorite={track.UserData?.IsFavorite}
|
||||
queryKey={["item", "musicTracks"]}
|
||||
userId={user?.Id}
|
||||
itemName={track.Name}
|
||||
{musicTracks.data?.Items?.map(
|
||||
(track, index) =>
|
||||
track.ParentIndexNumber === disc && (
|
||||
<AlbumMusicTrack
|
||||
key={track.Id}
|
||||
track={track}
|
||||
trackIndex={index}
|
||||
musicTracks={musicTracks.data}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
),
|
||||
)}
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<div>
|
||||
<div className="item-info-track header">
|
||||
<span className="material-symbols-rounded index">tag</span>
|
||||
<Typography variant="subtitle1">Title</Typography>
|
||||
<Typography variant="subtitle1">Duration</Typography>
|
||||
</div>
|
||||
{musicTracks.data?.Items?.map((track, index) => (
|
||||
<AlbumMusicTrack
|
||||
key={track.Id}
|
||||
track={track}
|
||||
trackIndex={index}
|
||||
musicTracks={musicTracks.data}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{createPortal(
|
||||
<div className="item-info-sidebar">
|
||||
<div className="item-info-sidebar-image-container">
|
||||
{item.data.ImageTags?.Primary ? (
|
||||
@@ -440,12 +316,13 @@ function MusicAlbumTitlePage() {
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(similarItems.data?.TotalRecordCount ?? -1) > 0 && (
|
||||
</div>,
|
||||
document.body,
|
||||
)}
|
||||
{(similarItems.data?.TotalRecordCount ?? 0) > 0 && (
|
||||
<CardScroller
|
||||
title="You might also like"
|
||||
displayCards={7}
|
||||
displayCards={5}
|
||||
disableDecoration
|
||||
>
|
||||
{similarItems.data?.Items?.map((similar) => {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
$border-radius: 20px;
|
||||
.item-album {
|
||||
width: 70vw;
|
||||
padding-right: 2.2em;
|
||||
.item-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@@ -9,123 +11,7 @@ $border-radius: 20px;
|
||||
display: grid;
|
||||
gap: 3em;
|
||||
}
|
||||
&-sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1em;
|
||||
position: sticky;
|
||||
max-height: 100vh;
|
||||
top: 0;
|
||||
&-image {
|
||||
width: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: $border-radius-default;
|
||||
}
|
||||
&-artist {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
align-items: center;
|
||||
padding: 1em 0;
|
||||
color: rgb(255 255 255 / 0.7);
|
||||
transition: $transition-time-default;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
color: rgb(255 255 255)
|
||||
}
|
||||
&-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
&-container {
|
||||
width: 3em;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
.material-symbols-rounded {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgb(255 255 255 / 0.1);
|
||||
z-index: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
&-container {
|
||||
// max-height: 20em;/
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
&-track {
|
||||
display: grid;
|
||||
grid-template-columns: 3em 60% 6em 1fr;
|
||||
gap: 1em;
|
||||
padding: 1em;
|
||||
align-items: center;
|
||||
cursor: pointer;
|
||||
border-radius: $border-radius-default;
|
||||
transition: background $transition-time-fast;
|
||||
&.header {
|
||||
border-bottom: 1px solid rgb(255 255 255 / 0.2);
|
||||
color: rgb(255 255 255 / 0.7);
|
||||
border-radius: 0 !important;
|
||||
}
|
||||
.index-container {
|
||||
justify-self: center;
|
||||
position: relative;
|
||||
.material-symbols-rounded {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
font-size: 2em !important;
|
||||
opacity: 0;
|
||||
transition: none !important;
|
||||
color: $clr-accent-default;
|
||||
}
|
||||
}
|
||||
&-info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.1em
|
||||
}
|
||||
&:hover {
|
||||
background: rgb(255 255 255 / 0.1) !important;
|
||||
.index-container {
|
||||
// font-size: 0em;
|
||||
.index {
|
||||
opacity: 0;
|
||||
transition: opacity 0;
|
||||
}
|
||||
.material-symbols-rounded {
|
||||
opacity: 1;
|
||||
font-size: 2.2em !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
&.playing {
|
||||
background: rgb(0 0 0 / 0.4) !important;
|
||||
.item-info-track-info-name, .index {
|
||||
color: $clr-accent-default;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
&-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.4em
|
||||
}
|
||||
}
|
||||
|
||||
&-album-info {
|
||||
gap: 1.2em;
|
||||
}
|
||||
@@ -142,6 +28,69 @@ $border-radius: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item-info-sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1em;
|
||||
position: fixed;
|
||||
max-height: 100vh;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 30vw;
|
||||
padding: 4.4em;
|
||||
padding-left: 2.2em;
|
||||
&-image {
|
||||
width: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: $border-radius-default;
|
||||
}
|
||||
&-artist {
|
||||
display: flex;
|
||||
gap: 1em;
|
||||
align-items: center;
|
||||
padding: 1em 0;
|
||||
color: rgb(255 255 255 / 0.7);
|
||||
transition: $transition-time-default;
|
||||
cursor: pointer;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
color: rgb(255 255 255)
|
||||
}
|
||||
&-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
z-index: 1;
|
||||
position: relative;
|
||||
&-container {
|
||||
width: 3em;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 100%;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
.material-symbols-rounded {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgb(255 255 255 / 0.1);
|
||||
z-index: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
&-container {
|
||||
// max-height: 20em;/
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item-detail-album {
|
||||
&-track {
|
||||
display: grid;
|
||||
|
||||
Reference in new issue
Block a user