fix: playing track from album not updating the queue #182
This commit is contained in:
2 files changed
+34
-14
No files matched your search
@@ -42,12 +42,14 @@ export const ErrorNotice = ({ error }: { error?: Error }) => {
|
|||||||
borderRadius: "8px",
|
borderRadius: "8px",
|
||||||
border: "2px dashed rgb(255 255 255 / 0.5)",
|
border: "2px dashed rgb(255 255 255 / 0.5)",
|
||||||
maxWidth: "40em",
|
maxWidth: "40em",
|
||||||
|
maxHeight: "20em",
|
||||||
|
overflow: "auto",
|
||||||
marginTop: "1em",
|
marginTop: "1em",
|
||||||
// opacity: 0.6,
|
// opacity: 0.6,
|
||||||
}}
|
}}
|
||||||
color="gray"
|
color="gray"
|
||||||
>
|
>
|
||||||
{JSON.stringify(error?.message)}
|
{JSON.stringify(error?.stack)}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -37,8 +37,9 @@ import "./album.scss";
|
|||||||
import TagChip from "@/components/tagChip";
|
import TagChip from "@/components/tagChip";
|
||||||
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
import getImageUrlsApi from "@/utils/methods/getImageUrlsApi";
|
||||||
import { useCentralStore } from "@/utils/store/central";
|
import { useCentralStore } from "@/utils/store/central";
|
||||||
import { playItem } from "@/utils/store/playback";
|
import { setQueue } from "@/utils/store/queue";
|
||||||
import { Link, createFileRoute } from "@tanstack/react-router";
|
import { Link, createFileRoute } from "@tanstack/react-router";
|
||||||
|
import { useSnackbar } from "notistack";
|
||||||
import lyricsIcon from "../../../assets/icons/lyrics.svg";
|
import lyricsIcon from "../../../assets/icons/lyrics.svg";
|
||||||
|
|
||||||
export const Route = createFileRoute("/_api/album/$id")({
|
export const Route = createFileRoute("/_api/album/$id")({
|
||||||
@@ -49,7 +50,15 @@ function MusicAlbumTitlePage() {
|
|||||||
const { id } = Route.useParams();
|
const { id } = Route.useParams();
|
||||||
const api = Route.useRouteContext().api;
|
const api = Route.useRouteContext().api;
|
||||||
|
|
||||||
|
if (!api) {
|
||||||
|
throw new Error("API not found", {
|
||||||
|
cause:
|
||||||
|
"API is not set in the context, maybe it is not initialized before the component is rendered.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const user = useCentralStore((s) => s.currentUser);
|
const user = useCentralStore((s) => s.currentUser);
|
||||||
|
const { enqueueSnackbar } = useSnackbar();
|
||||||
|
|
||||||
const item = useQuery({
|
const item = useQuery({
|
||||||
queryKey: ["item", id],
|
queryKey: ["item", id],
|
||||||
@@ -89,7 +98,7 @@ function MusicAlbumTitlePage() {
|
|||||||
userId: user?.Id,
|
userId: user?.Id,
|
||||||
parentId: item.data?.Id,
|
parentId: item.data?.Id,
|
||||||
sortOrder: [SortOrder.Ascending],
|
sortOrder: [SortOrder.Ascending],
|
||||||
sortBy: ["IndexNumber"],
|
sortBy: ["IndexNumber", "ParentIndexNumber"],
|
||||||
fields: ["MediaSources"],
|
fields: ["MediaSources"],
|
||||||
});
|
});
|
||||||
return result.data;
|
return result.data;
|
||||||
@@ -118,7 +127,7 @@ function MusicAlbumTitlePage() {
|
|||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (item.isSuccess) {
|
if (item.isSuccess) {
|
||||||
setAppBackdrop(
|
setAppBackdrop(
|
||||||
`${api.basePath}/Items/${item.data.ParentBackdropItemId}/Images/Backdrop`,
|
`${api?.basePath}/Items/${item.data.ParentBackdropItemId}/Images/Backdrop`,
|
||||||
item.data.Id,
|
item.data.Id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -131,15 +140,23 @@ function MusicAlbumTitlePage() {
|
|||||||
item: BaseItemDto,
|
item: BaseItemDto,
|
||||||
queue: BaseItemDto[],
|
queue: BaseItemDto[],
|
||||||
) => {
|
) => {
|
||||||
if (item.Id && user?.Id) {
|
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(
|
const url = generateAudioStreamUrl(
|
||||||
item.Id,
|
item.Id,
|
||||||
user?.Id,
|
user.Id,
|
||||||
api.deviceInfo.id,
|
api.deviceInfo.id,
|
||||||
api.basePath,
|
api.basePath,
|
||||||
api.accessToken,
|
api.accessToken,
|
||||||
);
|
);
|
||||||
playAudio(url, item, undefined);
|
playAudio(url, item, undefined);
|
||||||
|
setQueue(queue, index);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -244,14 +261,15 @@ function MusicAlbumTitlePage() {
|
|||||||
: "item-info-track"
|
: "item-info-track"
|
||||||
}
|
}
|
||||||
key={track.Id}
|
key={track.Id}
|
||||||
onClick={() =>
|
onClick={() => {
|
||||||
musicTracks.data.Items &&
|
if (musicTracks.data.Items) {
|
||||||
handlePlayback(
|
handlePlayback(
|
||||||
index,
|
index,
|
||||||
track,
|
track,
|
||||||
musicTracks.data.Items,
|
musicTracks.data.Items,
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="index-container">
|
<div className="index-container">
|
||||||
<span className="material-symbols-rounded fill ">
|
<span className="material-symbols-rounded fill ">
|
||||||
|
|||||||
Reference in new issue
Block a user