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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
import { useState } from "react";
import type { Task } from "../lib/commands";
import TaskItem from "./TaskItem";
interface TaskListProps {
tasks: Task[];
onAdd: (title: string) => void;
onEdit: (index: number, title: string) => void;
onDelete: (index: number) => void;
onToggle: (index: number) => void;
onReorder: (index: number, direction: "up" | "down") => void;
onMove: (from: number, to: number) => void;
}
export default function TaskList({
tasks,
onAdd,
onEdit,
onDelete,
onToggle,
onReorder,
onMove,
}: TaskListProps) {
const [newTaskTitle, setNewTaskTitle] = useState("");
const [draggedIndex, setDraggedIndex] = useState<number | null>(null);
const [dragOverIndex, setDragOverIndex] = useState<number | null>(null);
function handleSubmit(e: React.FormEvent) {
e.preventDefault();
if (newTaskTitle.trim()) {
onAdd(newTaskTitle.trim());
setNewTaskTitle("");
}
}
function handleDragStart(e: React.DragEvent, index: number) {
setDraggedIndex(index);
if (e.dataTransfer) {
e.dataTransfer.effectAllowed = "move";
e.dataTransfer.setData("text/plain", index.toString());
// Generate a small, clean drag ghost without relying on the browser's
// unpredictable DOM snapshotting on High DPI displays.
const task = tasks[index];
const ghost = document.createElement("div");
ghost.textContent = task.title;
ghost.style.position = "absolute";
ghost.style.top = "-1000px";
ghost.style.left = "-1000px";
ghost.style.backgroundColor = "var(--surface)";
ghost.style.color = "var(--text)";
ghost.style.padding = "4px 8px";
ghost.style.borderRadius = "var(--radius-sm)";
// WebKit scaling fix: Make it 12px natively so it stays small even if scaled 2x
ghost.style.fontSize = "12px";
ghost.style.fontFamily = "inherit";
ghost.style.whiteSpace = "nowrap";
ghost.style.boxShadow = "0 4px 12px rgba(0,0,0,0.5)";
ghost.style.zIndex = "9999";
document.body.appendChild(ghost);
e.dataTransfer.setDragImage(ghost, 10, 10);
setTimeout(() => {
if (document.body.contains(ghost)) {
document.body.removeChild(ghost);
}
}, 0);
}
}
function handleDragOver(e: React.DragEvent, index: number) {
e.preventDefault();
if (e.dataTransfer) {
e.dataTransfer.dropEffect = "move";
}
if (draggedIndex !== null && draggedIndex !== index) {
setDragOverIndex(index);
}
}
function handleDrop(e: React.DragEvent, dropIndex: number) {
e.preventDefault();
if (draggedIndex !== null && draggedIndex !== dropIndex) {
onMove(draggedIndex, dropIndex);
}
setDraggedIndex(null);
setDragOverIndex(null);
}
function handleDragEnd() {
setDraggedIndex(null);
setDragOverIndex(null);
}
return (
<div className="task-list-container">
<div className="task-list-header">
<h2 className="task-list-title">Focus Priorities</h2>
<span className="task-count">
{tasks.filter((t) => !t.is_done).length}/{tasks.length}
</span>
</div>
<form className="task-input-row" onSubmit={handleSubmit}>
<input
type="text"
className="task-input"
placeholder="Add a new task..."
value={newTaskTitle}
onChange={(e) => setNewTaskTitle(e.target.value)}
/>
<button
type="submit"
className="task-add-btn"
disabled={!newTaskTitle.trim()}
aria-label="Add task"
>
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round">
<line x1="12" y1="5" x2="12" y2="19" />
<line x1="5" y1="12" x2="19" y2="12" />
</svg>
</button>
</form>
<div className="task-items">
{tasks.map((task, index) => {
let transform = "none";
if (draggedIndex !== null && dragOverIndex !== null) {
if (draggedIndex < dragOverIndex && index > draggedIndex && index <= dragOverIndex) {
transform = "translateY(-44px)";
} else if (draggedIndex > dragOverIndex && index >= dragOverIndex && index < draggedIndex) {
transform = "translateY(44px)";
}
}
return (
<div
key={`${task.title}-${index}`}
draggable
onDragStart={(e) => handleDragStart(e, index)}
onDragOver={(e) => handleDragOver(e, index)}
onDrop={(e) => handleDrop(e, index)}
onDragEnd={handleDragEnd}
className={`task-drag-wrapper ${draggedIndex === index ? "dragging" : ""}`}
style={{
transform,
transition: draggedIndex !== null ? "transform 0.2s cubic-bezier(0.2, 0, 0, 1)" : "none",
}}
>
<TaskItem
task={task}
index={index}
total={tasks.length}
onEdit={onEdit}
onDelete={onDelete}
onToggle={onToggle}
onReorder={onReorder}
/>
</div>
);
})}
{tasks.length === 0 && (
<div className="task-empty">
<p>No tasks yet</p>
<span className="task-empty-hint">Time to focus!</span>
</div>
)}
</div>
</div>
);
}
|