2024-05-09 10:21:49 +00:00
|
|
|
import React, { useEffect, useRef, useState } from "react";
|
|
|
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
|
|
import { draggable } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
2024-03-18 07:21:19 +00:00
|
|
|
// components
|
2024-04-30 13:29:07 +00:00
|
|
|
import { TIssueMap } from "@plane/types";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { CalendarIssueBlock } from "@/components/issues";
|
2024-05-09 10:21:49 +00:00
|
|
|
import useOutsideClickDetector from "@/hooks/use-outside-click-detector";
|
2024-04-30 13:29:07 +00:00
|
|
|
import { TRenderQuickActions } from "../list/list-view-types";
|
2024-05-09 10:21:49 +00:00
|
|
|
import { HIGHLIGHT_CLASS } from "../utils";
|
2024-03-19 14:38:35 +00:00
|
|
|
// types
|
2024-03-18 07:21:19 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issues: TIssueMap | undefined;
|
|
|
|
issueId: string;
|
2024-04-30 13:29:07 +00:00
|
|
|
quickActions: TRenderQuickActions;
|
2024-05-09 10:21:49 +00:00
|
|
|
isDragDisabled: boolean;
|
2024-03-18 07:21:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const CalendarIssueBlockRoot: React.FC<Props> = (props) => {
|
2024-05-09 10:21:49 +00:00
|
|
|
const { issues, issueId, quickActions, isDragDisabled } = props;
|
2024-03-18 07:21:19 +00:00
|
|
|
|
2024-05-09 10:21:49 +00:00
|
|
|
const issueRef = useRef<HTMLAnchorElement | null>(null);
|
|
|
|
const [isDragging, setIsDragging] = useState(false);
|
2024-03-18 07:21:19 +00:00
|
|
|
|
|
|
|
const issue = issues?.[issueId];
|
|
|
|
|
2024-05-09 10:21:49 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const element = issueRef.current;
|
|
|
|
|
|
|
|
if (!element) return;
|
|
|
|
|
|
|
|
return combine(
|
|
|
|
draggable({
|
|
|
|
element,
|
|
|
|
canDrag: () => !isDragDisabled,
|
|
|
|
getInitialData: () => ({ id: issue?.id, date: issue?.target_date }),
|
|
|
|
onDragStart: () => {
|
|
|
|
setIsDragging(true);
|
|
|
|
},
|
|
|
|
onDrop: () => {
|
|
|
|
setIsDragging(false);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}, [issueRef?.current, issue]);
|
|
|
|
|
|
|
|
useOutsideClickDetector(issueRef, () => {
|
|
|
|
issueRef?.current?.classList?.remove(HIGHLIGHT_CLASS);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!issue) return null;
|
|
|
|
|
|
|
|
return <CalendarIssueBlock isDragging={isDragging} issue={issue} quickActions={quickActions} ref={issueRef} />;
|
2024-03-18 07:21:19 +00:00
|
|
|
};
|