-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathDraggableTask.tsx
More file actions
109 lines (104 loc) · 2.99 KB
/
Copy pathDraggableTask.tsx
File metadata and controls
109 lines (104 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import classNames from "classnames";
import { useDraggable } from "@dnd-kit/core";
import { CSS } from "@dnd-kit/utilities";
import { autoUpdate, inline, offset, useFloating } from "@floating-ui/react";
import { DotsSixVerticalIcon } from "@phosphor-icons/react";
import { Task as ITask } from "@web/common/types/task.types";
import { Draggable } from "@web/components/DND/Draggable";
import { Task } from "@web/views/Day/components/Task/Task";
import { useTasks } from "@web/views/Day/hooks/tasks/useTasks";
export function DraggableTask({
task,
index,
tasksProps,
}: {
task: ITask;
index: number;
tasksProps: ReturnType<typeof useTasks>;
}) {
const { refs, floatingStyles, update } = useFloating({
open: true,
whileElementsMounted: autoUpdate,
strategy: "fixed",
placement: "left",
transform: false,
middleware: [offset(8), inline({})],
});
const {
tasks,
editingTaskId,
editingTitle,
setSelectedTaskIndex,
onCheckboxKeyDown,
onInputBlur,
focusOnInput,
onInputClick,
onInputKeyDown,
onTitleChange,
onStatusToggle,
migrateTask,
deleteTask,
} = tasksProps;
return (
<Draggable
dndProps={{
id: task.id,
data: {
type: "task",
task,
view: "day",
deleteTask: () => deleteTask(task.id),
},
disabled: tasks.length === 1,
}}
as="div"
id={task.id}
className={`group relative mr-2 select-none`}
ref={(e) => {
refs.setReference(e);
update();
}}
>
{tasks.length > 1 ? (
<button
ref={refs.setFloating}
style={floatingStyles}
aria-label={`Reorder ${task.title}`}
aria-describedby={`description-${task.id}`}
onFocus={() => setSelectedTaskIndex(index)}
className={classNames(
"opacity-0",
"hover:bg-border-primary hover:cursor-grab",
"rounded-xs py-2 transition-colors",
"group-hover:opacity-100 hover:opacity-100 focus:opacity-100",
"max-w-48 text-white",
"focus:bg-white/20 focus:ring-2 focus:ring-white/50",
"focus:outline-none disabled:cursor-default disabled:opacity-0",
{
hidden: tasks.length === 1,
},
)}
>
<DotsSixVerticalIcon size={24} />
</button>
) : null}
<Task
task={task}
index={index}
isEditing={editingTaskId === task.id}
onFocus={setSelectedTaskIndex}
onCheckboxKeyDown={onCheckboxKeyDown}
onInputBlur={onInputBlur}
onInputKeyDown={onInputKeyDown}
onInputClick={onInputClick}
onTitleChange={onTitleChange}
onStatusToggle={onStatusToggle}
onMigrate={migrateTask}
title={editingTaskId === task.id ? editingTitle : task.title}
/>
<div id={`description-${task.id}`} className="hidden">
Press space to start dragging this task.
</div>
</Draggable>
);
}