refactor: move more components to ts
This commit is contained in:
12 files changed
+180
-267
No files matched your search
@@ -1,5 +1,5 @@
|
||||
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 { 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 { 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";
|
||||
|
||||
|
||||
|
||||
@@ -19,84 +16,13 @@ type Props = {
|
||||
};
|
||||
const QueueTrack = (props: Props) => {
|
||||
const { track, index } = props;
|
||||
const [queue, currentItemIndex] = useQueue((s) => [
|
||||
s.tracks,
|
||||
s.currentItemIndex,
|
||||
]);
|
||||
const [currentItemIndex] = useQueue((s) => [s.currentItemIndex]);
|
||||
|
||||
const { attributes, listeners, setNodeRef, transform, transition } =
|
||||
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 = {
|
||||
// opacity: isDragging ? 0.5 : 1,
|
||||
transform: CSS.Transform.toString(transform),
|
||||
|
||||
Reference in new issue
Block a user