feat: add new audioPlayer route and allow reordering queue
This commit is contained in:
17 files changed
+629
-219
No files matched your search
@@ -19,8 +19,6 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { delUser } from "@/utils/storage/user";
|
||||
import "./appBar.scss";
|
||||
|
||||
import { EventEmitter as event } from "@/eventEmitter";
|
||||
|
||||
import { getTypeIcon } from "../utils/iconsCollection";
|
||||
|
||||
import { useApiInContext } from "@/utils/store/api";
|
||||
@@ -121,7 +119,6 @@ export const AppBar = () => {
|
||||
await api.logout();
|
||||
delUser();
|
||||
sessionStorage.removeItem("accessToken");
|
||||
event.emit("create-jellyfin-api", api.basePath);
|
||||
queryClient.clear();
|
||||
setAnchorEl(null);
|
||||
navigate({ to: "/login" });
|
||||
|
||||
@@ -86,7 +86,7 @@ const QueueButton = () => {
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
{item.Type === "Audio"
|
||||
? item.IndexNumber ?? 0
|
||||
? index + 1
|
||||
: item.IndexNumberEnd
|
||||
? `S${item.ParentIndexNumber}:E${item.IndexNumber} / ${item.IndexNumberEnd}`
|
||||
: `S${item.ParentIndexNumber}:E${item.IndexNumber}`}
|
||||
|
||||
@@ -93,7 +93,7 @@ const AudioPlayer = () => {
|
||||
});
|
||||
setAudioRef(audioRef);
|
||||
}
|
||||
}, [url, currentTrack]);
|
||||
}, [url, tracks[currentTrack]?.Id]);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -288,6 +288,7 @@ const AudioPlayer = () => {
|
||||
onTimeUpdate={(e) =>
|
||||
setProgress(secToTicks(e.currentTarget.currentTime))
|
||||
}
|
||||
id="audio-player"
|
||||
/>
|
||||
<div className="audio-player-controls">
|
||||
{controls}
|
||||
@@ -317,7 +318,6 @@ const AudioPlayer = () => {
|
||||
onChange={(e, value) => {
|
||||
setIsScrubbing(true);
|
||||
setSliderProgress(value);
|
||||
console.log(value);
|
||||
}}
|
||||
onChangeCommitted={(e, value) => {
|
||||
setIsScrubbing(false);
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
import { getRuntimeMusic } from "@/utils/date/time";
|
||||
import useQueue, { setQueue } from "@/utils/store/queue";
|
||||
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";
|
||||
|
||||
type Props = {
|
||||
track: BaseItemDto;
|
||||
index: number;
|
||||
};
|
||||
const QueueTrack = (props: Props) => {
|
||||
const { track, index } = props;
|
||||
const [queue, currentItemIndex] = useQueue((s) => [
|
||||
s.tracks,
|
||||
s.currentItemIndex,
|
||||
]);
|
||||
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));
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={trackRef}
|
||||
style={{ opacity: isDragging ? 0.5 : 1 }}
|
||||
className={
|
||||
currentItemIndex === index
|
||||
? "audio-queue-track active"
|
||||
: "audio-queue-track"
|
||||
}
|
||||
>
|
||||
<span className="material-symbols-rounded">drag_handle</span>
|
||||
<div className="audio-queue-track-info">
|
||||
<Typography className="audio-queue-track-info-name">
|
||||
{track.Name}
|
||||
</Typography>
|
||||
<Typography fontWeight={300} className="opacity-07" variant="subtitle2">
|
||||
{track.Artists?.join(", ")}
|
||||
</Typography>
|
||||
</div>
|
||||
<Typography className="opacity-07">
|
||||
{getRuntimeMusic(track.RunTimeTicks)}
|
||||
</Typography>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QueueTrack;
|
||||
Reference in new issue
Block a user