feat: added new music player and fix some UI issues
This commit is contained in:
26 files changed
+1862
-1491
No files matched your search
@@ -32,15 +32,16 @@
|
||||
|
||||
.MuiTabs-root {
|
||||
min-height: 40px;
|
||||
margin-left: -12px;
|
||||
margin-top: 1em;
|
||||
// Negative margins cancel the scroller padding below, so the layout is unchanged
|
||||
margin: calc(1em - 8px) 0 -16px -12px;
|
||||
|
||||
.MuiTabs-indicator {
|
||||
display: none; // Hide default indicator
|
||||
}
|
||||
|
||||
// Tabs clip their content; pad the scroller so the selected pill's shadow fits
|
||||
.MuiTabs-scroller {
|
||||
overflow: visible !important; // Allow shadows/glows to show
|
||||
padding: 8px 0 16px;
|
||||
}
|
||||
|
||||
.MuiTab-root {
|
||||
|
||||
@@ -11,7 +11,7 @@ import Tab from "@mui/material/Tab";
|
||||
import Tabs from "@mui/material/Tabs";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { AnimatePresence, motion, useScroll } from "motion/react";
|
||||
import { AnimatePresence, motion } from "motion/react";
|
||||
import React, {
|
||||
type ReactNode,
|
||||
useEffect,
|
||||
@@ -21,19 +21,40 @@ import React, {
|
||||
} from "react";
|
||||
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import PlayButton from "@/components/buttons/playButton";
|
||||
import { Card } from "@/components/card/card";
|
||||
import ItemHeader from "@/components/itemHeader";
|
||||
import { ArtistAlbum } from "@/components/layouts/artist/artistAlbum";
|
||||
import MusicTrack from "@/components/musicTrack";
|
||||
import { ErrorNotice } from "@/components/notices/errorNotice/errorNotice";
|
||||
import ShowMoreText from "@/components/showMoreText";
|
||||
import useParallax from "@/utils/hooks/useParallax";
|
||||
import { useBackdropStore } from "@/utils/store/backdrop";
|
||||
import "./artist.scss";
|
||||
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import IconButton from "@mui/material/IconButton";
|
||||
import Tooltip from "@mui/material/Tooltip";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import IconLink from "@/components/iconLink";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import { playItemFromQueue } from "@/utils/store/playback";
|
||||
import { setQueue } from "@/utils/store/queue";
|
||||
|
||||
/** Queues the given tracks in random order and starts playing. */
|
||||
const shuffleAndPlay = (
|
||||
tracks: BaseItemDto[],
|
||||
userId: string | undefined,
|
||||
api: Api | undefined,
|
||||
) => {
|
||||
const shuffled = [...tracks];
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||
}
|
||||
setQueue(shuffled, 0);
|
||||
playItemFromQueue(0, userId, api);
|
||||
};
|
||||
|
||||
type TabPanelProp = {
|
||||
children: ReactNode;
|
||||
@@ -167,15 +188,29 @@ function ArtistTitlePage() {
|
||||
|
||||
const [animationDirection, setAnimationDirection] = useState("forward");
|
||||
|
||||
const { setBackdrop } = useBackdropStore();
|
||||
const setBackdrop = useBackdropStore((s) => s.setBackdrop);
|
||||
const backdropTag = item.data?.BackdropImageTags?.[0];
|
||||
const backdropHash =
|
||||
(backdropTag && item.data?.ImageBlurHashes?.Backdrop?.[backdropTag]) || "";
|
||||
useEffect(() => {
|
||||
if (item.isSuccess && item.data) {
|
||||
setBackdrop(`${api?.basePath}/Items/${item.data.Id}/Images/Backdrop`);
|
||||
}
|
||||
}, [item.isSuccess]);
|
||||
setBackdrop(backdropHash);
|
||||
}, [backdropHash, setBackdrop]);
|
||||
|
||||
const scrollTargetRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const pluralize = (count: number, word: string) =>
|
||||
`${count} ${count === 1 ? word : `${word}s`}`;
|
||||
const catalogueSummary = [
|
||||
artistDiscography.data?.TotalRecordCount
|
||||
? pluralize(artistDiscography.data.TotalRecordCount, "album")
|
||||
: null,
|
||||
artistSongs.data?.TotalRecordCount
|
||||
? pluralize(artistSongs.data.TotalRecordCount, "song")
|
||||
: null,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
|
||||
if (item.isPending) {
|
||||
return (
|
||||
<Box
|
||||
@@ -214,17 +249,50 @@ function ArtistTitlePage() {
|
||||
scrollTargetRef={scrollTargetRef}
|
||||
>
|
||||
<div className="item-hero-buttons-container">
|
||||
<LikeButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
<div className="flex flex-row" style={{ width: "100%" }}>
|
||||
<PlayButton
|
||||
item={item.data}
|
||||
itemType={BaseItemKind.MusicArtist}
|
||||
userId={user?.Id}
|
||||
audio
|
||||
buttonProps={{ fullWidth: true }}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-row" style={{ gap: "1em" }}>
|
||||
<Tooltip title="Shuffle">
|
||||
<span>
|
||||
<IconButton
|
||||
aria-label="Shuffle"
|
||||
disabled={!artistSongs.data?.Items?.length}
|
||||
onClick={() =>
|
||||
shuffleAndPlay(
|
||||
artistSongs.data?.Items ?? [],
|
||||
user?.Id,
|
||||
api,
|
||||
)
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">shuffle</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<LikeButton
|
||||
itemName={item.data.Name}
|
||||
itemId={item.data.Id}
|
||||
queryKey={["item", id]}
|
||||
isFavorite={item.data.UserData?.IsFavorite}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ItemHeader>
|
||||
<div className="item-detail">
|
||||
<div style={{ width: "100%", overflow: "hidden" }}>
|
||||
{catalogueSummary && (
|
||||
<Typography sx={{ opacity: 0.8, mb: 1.5 }}>
|
||||
{catalogueSummary}
|
||||
</Typography>
|
||||
)}
|
||||
<ShowMoreText
|
||||
content={item.data.Overview ?? ""}
|
||||
collapsedLines={4}
|
||||
|
||||
@@ -6,7 +6,7 @@ $cardWidth: 22%;
|
||||
.item-detail {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 35%;
|
||||
justify-items: center;
|
||||
justify-items: start;
|
||||
align-items: start;
|
||||
gap: 3em;
|
||||
|
||||
|
||||
+238
-169
@@ -29,163 +29,195 @@
|
||||
}
|
||||
|
||||
&-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
// Art size drives the whole left column so everything fits the viewport.
|
||||
--np-size: min(420px, 44vh, 80vw);
|
||||
|
||||
display: grid;
|
||||
grid-template-columns: var(--np-size) minmax(0, 560px);
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
gap: clamp(2rem, 6vw, 6rem);
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
gap: 1rem;
|
||||
padding: 5rem 3rem 2.5rem;
|
||||
box-sizing: border-box;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: white;
|
||||
overflow: hidden;
|
||||
|
||||
@media (min-width: 900px) {
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 4rem;
|
||||
gap: 3rem;
|
||||
max-width: 1600px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
&-left-column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1.5rem;
|
||||
width: 100%;
|
||||
max-width: 500px;
|
||||
margin: 0 auto;
|
||||
min-height: 0; // Allow shrinking
|
||||
|
||||
@media (min-width: 900px) {
|
||||
gap: 2rem;
|
||||
}
|
||||
}
|
||||
|
||||
&-right-column {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
overflow: hidden;
|
||||
@include glass-effect($blur: 20px, $bg-color: rgba(255, 255, 255, 0.05));
|
||||
border-radius: 1.5rem;
|
||||
padding: 0;
|
||||
min-height: 0; // Allow shrinking
|
||||
}
|
||||
|
||||
&-right-content {
|
||||
flex: 1;
|
||||
padding: 1.5rem;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
&::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 3px;
|
||||
}
|
||||
&::-webkit-scrollbar-thumb:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
}
|
||||
}
|
||||
|
||||
&-info {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start; // Left align text
|
||||
text-align: left;
|
||||
gap: 0.5em;
|
||||
|
||||
|
||||
@media (max-width: 900px) {
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&-image {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
border-radius: 1.5rem;
|
||||
box-shadow: 0 20px 50px rgba(0,0,0,0.5);
|
||||
transition: transform 0.3s ease;
|
||||
|
||||
&-container {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
position: relative;
|
||||
border-radius: 1.5rem;
|
||||
overflow: hidden;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
max-width: 70vw;
|
||||
max-height: 35vh;
|
||||
margin: 0 auto 1rem auto;
|
||||
}
|
||||
}
|
||||
|
||||
&-icon {
|
||||
font-size: 8em;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 1.5rem;
|
||||
}
|
||||
}
|
||||
&-controls {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 1.5em;
|
||||
margin-top: 1rem;
|
||||
grid-template-columns: minmax(0, var(--np-size));
|
||||
grid-template-rows: auto minmax(0, 1fr);
|
||||
align-items: start;
|
||||
padding: 4.5rem 1rem 1rem;
|
||||
gap: 1.5rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
}
|
||||
|
||||
&-queue {
|
||||
&-now-playing {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
align-items: stretch; // Ensure items take full width
|
||||
|
||||
// Remove old track styles as we now use QueueListItem
|
||||
gap: 1.25rem;
|
||||
width: var(--np-size);
|
||||
min-width: 0;
|
||||
|
||||
&-art {
|
||||
width: 100%;
|
||||
aspect-ratio: 1;
|
||||
border-radius: 1.25rem;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 24px 60px rgb(0 0 0 / 0.55);
|
||||
background: rgb(255 255 255 / 0.08);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
}
|
||||
.material-symbols-rounded {
|
||||
font-size: 6rem;
|
||||
opacity: 0.6;
|
||||
}
|
||||
}
|
||||
|
||||
&-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
&-text {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
&-subtitle {
|
||||
opacity: 0.7;
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-transport {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
// Spread prev / play / next evenly with shuffle and repeat
|
||||
.player-controls {
|
||||
display: contents !important;
|
||||
}
|
||||
|
||||
// Toggle-style buttons read as "off" until enabled
|
||||
> .MuiIconButton-root,
|
||||
> span > .MuiIconButton-root {
|
||||
color: rgb(255 255 255 / 0.55);
|
||||
}
|
||||
> .MuiIconButton-root.is-active {
|
||||
color: $clr-accent-default;
|
||||
}
|
||||
}
|
||||
|
||||
&-utility {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
&-volume {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
max-width: 14rem;
|
||||
opacity: 0.85;
|
||||
|
||||
// Secondary control: neutral instead of the accent colour
|
||||
.MuiSlider-root {
|
||||
color: rgb(255 255 255 / 0.85);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&-side {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1.5rem;
|
||||
height: min(80vh, 760px);
|
||||
min-height: 0;
|
||||
|
||||
@media (max-width: 900px) {
|
||||
height: 70vh;
|
||||
}
|
||||
|
||||
&-lyrics {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
scrollbar-width: none;
|
||||
// Fade lines in and out at the edges
|
||||
mask-image: linear-gradient(transparent, black 15%, black 85%, transparent);
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
// "Up next" sits on a quiet card; no blur so the artwork backdrop stays clean
|
||||
&-queue {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
// The queue view scrolls its own list so the header stays put
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
padding: 1rem 1.25rem 0;
|
||||
|
||||
.queue {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
background: rgb(0 0 0 / 0.22);
|
||||
border: 1px solid rgb(255 255 255 / 0.06);
|
||||
border-radius: 1.25rem;
|
||||
|
||||
&::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
&::-webkit-scrollbar-thumb {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
&.has-lyrics .audio-side-queue {
|
||||
flex: 0 1 auto;
|
||||
max-height: 40%;
|
||||
}
|
||||
}
|
||||
|
||||
&-lyrics {
|
||||
padding: 1rem;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-height: 100%;
|
||||
|
||||
|
||||
&-container {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding-bottom: 4rem; // Space for unsynced notice
|
||||
align-items: flex-start;
|
||||
// Room above and below so the active line can scroll to the middle
|
||||
padding: 35% 0.5rem;
|
||||
}
|
||||
|
||||
&-status {
|
||||
@@ -193,54 +225,91 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
opacity: 0.7;
|
||||
min-height: 200px;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
&-line {
|
||||
margin-bottom: 1.5rem;
|
||||
opacity: 0.5;
|
||||
transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
||||
border-radius: 1rem;
|
||||
padding: 0.75rem 1.5rem;
|
||||
cursor: pointer;
|
||||
font-size: 1.5rem !important;
|
||||
line-height: 1.6 !important;
|
||||
font-weight: 600 !important;
|
||||
max-width: 90%;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.8;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
}
|
||||
&-line {
|
||||
margin: 0 0 0.6rem !important;
|
||||
padding: 0.35rem 0.75rem;
|
||||
border-radius: 0.75rem;
|
||||
font-size: clamp(1.25rem, 2vw, 1.85rem) !important;
|
||||
line-height: 1.35 !important;
|
||||
font-weight: 700 !important;
|
||||
text-align: left;
|
||||
opacity: 0.35;
|
||||
transition: opacity 0.35s ease, filter 0.35s ease;
|
||||
filter: blur(0.4px);
|
||||
|
||||
&[data-active-lyric="true"] {
|
||||
opacity: 1;
|
||||
font-weight: 800 !important;
|
||||
transform: scale(1.05);
|
||||
text-shadow: 0 0 30px rgba(255,255,255,0.3);
|
||||
color: var(--primary-color, #90caf9);
|
||||
filter: none;
|
||||
}
|
||||
|
||||
&[data-seekable="true"] {
|
||||
cursor: pointer;
|
||||
transition: opacity 0.35s ease, filter 0.35s ease, background-color 0.2s ease;
|
||||
|
||||
&:hover,
|
||||
&:focus-visible {
|
||||
opacity: 0.8;
|
||||
filter: none;
|
||||
background: rgb(255 255 255 / 0.08);
|
||||
outline: none;
|
||||
}
|
||||
&[data-active-lyric="true"]:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Unsynced lyrics: plain readable text, no highlight
|
||||
&[data-has-synced-lyrics="false"] {
|
||||
.audio-lyrics-container {
|
||||
padding: 1rem 0.5rem 4rem;
|
||||
}
|
||||
.audio-lyrics-line {
|
||||
font-size: 1.15rem !important;
|
||||
font-weight: 500 !important;
|
||||
opacity: 0.85;
|
||||
filter: none;
|
||||
margin-bottom: 0.25rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
&-unsynced-notice {
|
||||
position: sticky;
|
||||
bottom: 1rem;
|
||||
display: flex;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: rgba(0, 0, 0, 0.4);
|
||||
backdrop-filter: blur(10px);
|
||||
padding: 0.4rem 0.9rem;
|
||||
margin-left: 0.5rem;
|
||||
background: rgb(0 0 0 / 0.35);
|
||||
border-radius: 2rem;
|
||||
margin-top: auto;
|
||||
opacity: 0.8;
|
||||
|
||||
opacity: 0.85;
|
||||
|
||||
.material-symbols-rounded {
|
||||
font-size: 1.2rem;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.player-progress-stacked {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
|
||||
.MuiSlider-root {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
&-times {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
font-size: 0.8rem;
|
||||
opacity: 0.7;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
}
|
||||
|
||||
+258
-157
@@ -1,90 +1,103 @@
|
||||
import { Box, Tab, Tabs, Typography } from "@mui/material";
|
||||
import { createFileRoute } from "@tanstack/react-router";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogTitle,
|
||||
IconButton,
|
||||
ListItemIcon,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
|
||||
import React, { useEffect, useMemo, useState } from "react";
|
||||
import LikeButton from "@/components/buttons/likeButton";
|
||||
import LyricsPanel, {
|
||||
getLyricsQueryOptions,
|
||||
} from "@/components/playback/audioPlayer/components/LyricsPanel";
|
||||
import PlayerControls from "@/components/playback/audioPlayer/components/PlayerControls";
|
||||
import PlayerProgress from "@/components/playback/audioPlayer/components/PlayerProgress";
|
||||
import PlayerVolume from "@/components/playback/audioPlayer/components/PlayerVolume";
|
||||
import StatsPanel from "@/components/playback/audioPlayer/components/StatsPanel";
|
||||
import QueueView from "@/components/queue/queueView";
|
||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
import { getItemQueryOptions } from "@/utils/queries/items";
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
import {
|
||||
setIsMuted,
|
||||
setVolume,
|
||||
useAudioPlayback,
|
||||
} from "@/utils/store/audioPlayback";
|
||||
import useQueue from "@/utils/store/queue";
|
||||
import { useCentralStore } from "@/utils/store/central";
|
||||
import useQueue, {
|
||||
cycleRepeatMode,
|
||||
type RepeatMode,
|
||||
shuffleUpcoming,
|
||||
} from "@/utils/store/queue";
|
||||
|
||||
import "./audio.scss";
|
||||
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client";
|
||||
import LyricsPanel from "@/components/playback/audioPlayer/components/LyricsPanel";
|
||||
import PlayerControls from "@/components/playback/audioPlayer/components/PlayerControls";
|
||||
import PlayerProgress from "@/components/playback/audioPlayer/components/PlayerProgress";
|
||||
import PlayerVolume from "@/components/playback/audioPlayer/components/PlayerVolume";
|
||||
import QueuePanel from "@/components/playback/audioPlayer/components/QueuePanel";
|
||||
import StatsPanel from "@/components/playback/audioPlayer/components/StatsPanel";
|
||||
import { secToTicks, ticksToSec } from "@/utils/date/time";
|
||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||
|
||||
export const Route = createFileRoute("/_api/player/audio")({
|
||||
component: AudioPlayerRoute,
|
||||
});
|
||||
|
||||
const SEEK_AMOUNT = 10;
|
||||
const repeatLabels: Record<RepeatMode, string> = {
|
||||
off: "Repeat off",
|
||||
all: "Repeat all",
|
||||
one: "Repeat one",
|
||||
};
|
||||
|
||||
const AudioInfo = React.memo(
|
||||
({
|
||||
item,
|
||||
imageUrl,
|
||||
}: {
|
||||
item: BaseItemDto | undefined | null;
|
||||
imageUrl: string | undefined;
|
||||
}) => (
|
||||
<>
|
||||
<div className="audio-info-image-container">
|
||||
{imageUrl ? (
|
||||
<img
|
||||
alt={item?.Name ?? "Music"}
|
||||
src={imageUrl}
|
||||
className="audio-info-image"
|
||||
/>
|
||||
) : (
|
||||
<div className="audio-info-image-icon">
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
style={{ fontSize: "inherit" }}
|
||||
>
|
||||
music_note
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="audio-info">
|
||||
<Typography
|
||||
variant="h4"
|
||||
noWrap
|
||||
style={{ width: "100%", marginBottom: "0.2em" }}
|
||||
sx={{
|
||||
fontWeight: 700,
|
||||
}}
|
||||
>
|
||||
{item?.Name}
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h6"
|
||||
className="opacity-07"
|
||||
noWrap
|
||||
style={{ width: "100%" }}
|
||||
sx={{
|
||||
fontWeight: 400,
|
||||
}}
|
||||
>
|
||||
{item?.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
);
|
||||
/** Artists (linked) and album (linked) for the current track. */
|
||||
const TrackSubtitle = ({ item }: { item: BaseItemDto }) => {
|
||||
const artists = item.ArtistItems?.length
|
||||
? item.ArtistItems
|
||||
: (item.AlbumArtists ?? []);
|
||||
return (
|
||||
<Typography
|
||||
variant="subtitle1"
|
||||
className="audio-now-playing-subtitle"
|
||||
noWrap
|
||||
>
|
||||
{artists.map((artist, index) => (
|
||||
<React.Fragment key={artist.Id ?? artist.Name}>
|
||||
{index > 0 && ", "}
|
||||
{artist.Id ? (
|
||||
<Link to="/music/artist/$id" params={{ id: artist.Id }}>
|
||||
{artist.Name}
|
||||
</Link>
|
||||
) : (
|
||||
artist.Name
|
||||
)}
|
||||
</React.Fragment>
|
||||
))}
|
||||
{item.Album && (
|
||||
<>
|
||||
{artists.length > 0 && " · "}
|
||||
{item.AlbumId ? (
|
||||
<Link to="/music/album/$id" params={{ id: item.AlbumId }}>
|
||||
{item.Album}
|
||||
</Link>
|
||||
) : (
|
||||
item.Album
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</Typography>
|
||||
);
|
||||
};
|
||||
|
||||
function AudioPlayerRoute() {
|
||||
const api = useApiInContext((s) => s.api);
|
||||
const [queue, currentTrack] = useQueue((s) => [s.tracks, s.currentItemIndex]);
|
||||
const user = useCentralStore((s) => s.currentUser);
|
||||
const navigate = useNavigate();
|
||||
const [queue, currentTrack, repeatMode] = useQueue((s) => [
|
||||
s.tracks,
|
||||
s.currentItemIndex,
|
||||
s.repeatMode,
|
||||
]);
|
||||
const [item, audioPlayerRef, volume, isMuted] = useAudioPlayback((s) => [
|
||||
s.item,
|
||||
s.player.ref,
|
||||
@@ -94,7 +107,8 @@ function AudioPlayerRoute() {
|
||||
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const [tabValue, setTabValue] = useState(0);
|
||||
const [menuAnchor, setMenuAnchor] = useState<HTMLElement | null>(null);
|
||||
const [statsOpen, setStatsOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const player = audioPlayerRef?.current;
|
||||
@@ -107,7 +121,6 @@ function AudioPlayerRoute() {
|
||||
player.addEventListener("play", updatePlaying);
|
||||
player.addEventListener("pause", updatePlaying);
|
||||
|
||||
// Initial state
|
||||
setProgress(player.currentTime);
|
||||
setPlaying(!player.paused);
|
||||
|
||||
@@ -118,21 +131,24 @@ function AudioPlayerRoute() {
|
||||
};
|
||||
}, [audioPlayerRef?.current, item?.Id]);
|
||||
|
||||
// Fresh user data so the like button reflects changes immediately.
|
||||
const itemDetails = useQuery({
|
||||
...getItemQueryOptions(item?.Id ?? "", api, user?.Id),
|
||||
enabled: Boolean(item?.Id && api && user?.Id),
|
||||
});
|
||||
const lyrics = useQuery(getLyricsQueryOptions(item, api));
|
||||
const hasLyrics = (lyrics.data?.Lyrics?.length ?? 0) > 0;
|
||||
|
||||
const handlePlayPause = () => {
|
||||
const player = audioPlayerRef?.current;
|
||||
if (player) {
|
||||
if (player.paused) {
|
||||
player.play();
|
||||
} else {
|
||||
player.pause();
|
||||
}
|
||||
if (!player) return;
|
||||
if (player.paused) {
|
||||
player.play();
|
||||
} else {
|
||||
player.pause();
|
||||
}
|
||||
};
|
||||
|
||||
const handleSeek = (value: number) => {
|
||||
setProgress(ticksToSec(value));
|
||||
};
|
||||
|
||||
const handleSeekCommit = (value: number) => {
|
||||
const player = audioPlayerRef?.current;
|
||||
if (player) {
|
||||
@@ -141,23 +157,6 @@ function AudioPlayerRoute() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleRewind = () => {
|
||||
const player = audioPlayerRef?.current;
|
||||
if (player) {
|
||||
player.currentTime -= SEEK_AMOUNT;
|
||||
}
|
||||
};
|
||||
|
||||
const handleForward = () => {
|
||||
const player = audioPlayerRef?.current;
|
||||
if (player) {
|
||||
player.currentTime += SEEK_AMOUNT;
|
||||
}
|
||||
};
|
||||
const handleTabChange = (_: React.SyntheticEvent, newValue: number) => {
|
||||
setTabValue(newValue);
|
||||
};
|
||||
|
||||
const imageUrl = useMemo(
|
||||
() =>
|
||||
item?.ImageTags?.Primary
|
||||
@@ -169,6 +168,11 @@ function AudioPlayerRoute() {
|
||||
[item?.Id, item?.ImageTags?.Primary, api],
|
||||
);
|
||||
|
||||
const hasUpcoming = (queue?.length ?? 0) > currentTrack + 1;
|
||||
const isFavorite =
|
||||
itemDetails.data?.UserData?.IsFavorite ?? item?.UserData?.IsFavorite;
|
||||
const artistId = item?.ArtistItems?.[0]?.Id ?? item?.AlbumArtists?.[0]?.Id;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="audio-background">
|
||||
@@ -176,82 +180,179 @@ function AudioPlayerRoute() {
|
||||
<img src={imageUrl} alt="" className="audio-background-image" />
|
||||
)}
|
||||
</div>
|
||||
<div className="audio-container" key={item?.Id}>
|
||||
<div className="audio-left-column">
|
||||
<AudioInfo item={item} imageUrl={imageUrl} />
|
||||
<div className="audio-container">
|
||||
<section className="audio-now-playing" key={item?.Id}>
|
||||
<div className="audio-now-playing-art">
|
||||
{imageUrl ? (
|
||||
<img alt={item?.Name ?? "Album art"} src={imageUrl} />
|
||||
) : (
|
||||
<span className="material-symbols-rounded">music_note</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="audio-now-playing-meta">
|
||||
<div className="audio-now-playing-text">
|
||||
<Typography
|
||||
variant="h5"
|
||||
sx={{
|
||||
fontWeight: 700,
|
||||
lineHeight: 1.2,
|
||||
overflowWrap: "anywhere",
|
||||
}}
|
||||
>
|
||||
{item?.Name}
|
||||
</Typography>
|
||||
{item && <TrackSubtitle item={item} />}
|
||||
</div>
|
||||
<LikeButton
|
||||
itemId={item?.Id ?? undefined}
|
||||
itemName={item?.Name}
|
||||
isFavorite={isFavorite}
|
||||
queryKey={["item", item?.Id ?? ""]}
|
||||
userId={user?.Id}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<PlayerProgress
|
||||
layout="stacked"
|
||||
progress={secToTicks(progress)}
|
||||
duration={item?.RunTimeTicks ?? 1}
|
||||
onSeek={handleSeek}
|
||||
onSeek={(value) => setProgress(ticksToSec(value))}
|
||||
onSeekCommit={handleSeekCommit}
|
||||
/>
|
||||
|
||||
<div className="audio-info-controls">
|
||||
<div className="audio-now-playing-transport">
|
||||
<Tooltip title="Shuffle upcoming">
|
||||
<span>
|
||||
<IconButton
|
||||
onClick={shuffleUpcoming}
|
||||
disabled={!hasUpcoming}
|
||||
aria-label="Shuffle upcoming"
|
||||
>
|
||||
<span className="material-symbols-rounded">shuffle</span>
|
||||
</IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<PlayerControls
|
||||
playing={playing}
|
||||
onPlayPause={handlePlayPause}
|
||||
size="large"
|
||||
onRewind={handleRewind}
|
||||
onForward={handleForward}
|
||||
/>
|
||||
<Tooltip title={repeatLabels[repeatMode]}>
|
||||
<IconButton
|
||||
onClick={cycleRepeatMode}
|
||||
aria-label={repeatLabels[repeatMode]}
|
||||
className={repeatMode !== "off" ? "is-active" : undefined}
|
||||
>
|
||||
<span className="material-symbols-rounded">
|
||||
{repeatMode === "one" ? "repeat_one" : "repeat"}
|
||||
</span>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="audio-info-volume"
|
||||
style={{
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<PlayerVolume
|
||||
volume={volume}
|
||||
isMuted={isMuted}
|
||||
onVolumeChange={setVolume}
|
||||
onMuteToggle={() => setIsMuted(!isMuted)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="audio-right-column">
|
||||
<Box sx={{ borderBottom: 1, borderColor: "rgba(255,255,255,0.1)" }}>
|
||||
<Tabs
|
||||
value={tabValue}
|
||||
onChange={handleTabChange}
|
||||
aria-label="audio player tabs"
|
||||
variant="fullWidth"
|
||||
scrollButtons="auto"
|
||||
allowScrollButtonsMobile
|
||||
textColor="inherit"
|
||||
indicatorColor="primary"
|
||||
sx={{
|
||||
"& .MuiTab-root": {
|
||||
color: "rgba(255,255,255,0.5)",
|
||||
"&.Mui-selected": { color: "white" },
|
||||
},
|
||||
}}
|
||||
<div className="audio-now-playing-utility">
|
||||
<div className="audio-now-playing-volume">
|
||||
<PlayerVolume
|
||||
volume={volume}
|
||||
isMuted={isMuted}
|
||||
onVolumeChange={setVolume}
|
||||
onMuteToggle={() => setIsMuted(!isMuted)}
|
||||
/>
|
||||
</div>
|
||||
<IconButton
|
||||
onClick={(e) => setMenuAnchor(e.currentTarget)}
|
||||
aria-label="More options"
|
||||
>
|
||||
<Tab label="Queue" />
|
||||
<Tab label="Lyrics" />
|
||||
<Tab label="Stats" />
|
||||
</Tabs>
|
||||
</Box>
|
||||
|
||||
<div className="audio-right-content">
|
||||
{tabValue === 0 && queue && (
|
||||
<QueuePanel queue={queue} currentTrackIndex={currentTrack} />
|
||||
)}
|
||||
{tabValue === 1 && (
|
||||
<LyricsPanel item={item} api={api} currentTime={progress} />
|
||||
)}
|
||||
{tabValue === 2 && (
|
||||
<StatsPanel item={item} audioRef={audioPlayerRef} />
|
||||
)}
|
||||
<span className="material-symbols-rounded">more_horiz</span>
|
||||
</IconButton>
|
||||
<Menu
|
||||
anchorEl={menuAnchor}
|
||||
open={Boolean(menuAnchor)}
|
||||
onClose={() => setMenuAnchor(null)}
|
||||
anchorOrigin={{ vertical: "top", horizontal: "right" }}
|
||||
transformOrigin={{ vertical: "bottom", horizontal: "right" }}
|
||||
>
|
||||
<MenuItem
|
||||
disabled={!item?.AlbumId}
|
||||
onClick={() => {
|
||||
setMenuAnchor(null);
|
||||
if (item?.AlbumId) {
|
||||
navigate({
|
||||
to: "/music/album/$id",
|
||||
params: { id: item.AlbumId },
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<span className="material-symbols-rounded">album</span>
|
||||
</ListItemIcon>
|
||||
Go to album
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
disabled={!artistId}
|
||||
onClick={() => {
|
||||
setMenuAnchor(null);
|
||||
if (artistId) {
|
||||
navigate({
|
||||
to: "/music/artist/$id",
|
||||
params: { id: artistId },
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<span className="material-symbols-rounded">person</span>
|
||||
</ListItemIcon>
|
||||
Go to artist
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
onClick={() => {
|
||||
setMenuAnchor(null);
|
||||
setStatsOpen(true);
|
||||
}}
|
||||
>
|
||||
<ListItemIcon>
|
||||
<span className="material-symbols-rounded">query_stats</span>
|
||||
</ListItemIcon>
|
||||
Stats for nerds
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<aside
|
||||
className={`audio-side ${hasLyrics ? "has-lyrics" : ""}`}
|
||||
aria-label="Lyrics and queue"
|
||||
>
|
||||
{hasLyrics && (
|
||||
<div className="audio-side-lyrics">
|
||||
<LyricsPanel
|
||||
item={item}
|
||||
api={api}
|
||||
currentTime={progress}
|
||||
onSeek={handleSeekCommit}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="audio-side-queue">
|
||||
<QueueView variant="panel" />
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<Dialog
|
||||
open={statsOpen}
|
||||
onClose={() => setStatsOpen(false)}
|
||||
maxWidth="sm"
|
||||
fullWidth
|
||||
>
|
||||
<DialogTitle>Stats for nerds</DialogTitle>
|
||||
<DialogContent>
|
||||
<StatsPanel item={item} audioRef={audioPlayerRef} />
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -264,7 +264,7 @@ function SearchAppBar({
|
||||
e.stopPropagation();
|
||||
handleClearCategories();
|
||||
}}
|
||||
sx={{ mr: 2, p: 0.5 }}
|
||||
sx={{ p: 0.5 }}
|
||||
>
|
||||
<span
|
||||
className="material-symbols-rounded"
|
||||
|
||||
@@ -126,6 +126,11 @@
|
||||
transition: all 0.2s ease;
|
||||
|
||||
fieldset { border: none; }
|
||||
|
||||
// Keep the clear button clear of the absolutely positioned dropdown arrow
|
||||
&.MuiInputBase-adornedEnd {
|
||||
padding-right: 32px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background-color: rgba(255, 255, 255, 0.05);
|
||||
|
||||
Reference in new issue
Block a user