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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
import { useState, useCallback } from "react";
export interface ParsedTask {
name: string;
description?: string;
group?: string;
order: number;
completed: boolean;
dependencies: string[];
}
interface TaskDerivationPreviewProps {
tasks: ParsedTask[];
groups: string[];
fileName: string;
onCreateTasks: (selectedTasks: ParsedTask[]) => void;
onCancel: () => void;
loading?: boolean;
}
export function TaskDerivationPreview({
tasks,
groups,
fileName,
onCreateTasks,
onCancel,
loading = false,
}: TaskDerivationPreviewProps) {
const [selectedIndices, setSelectedIndices] = useState<Set<number>>(
new Set(tasks.map((_, i) => i)) // Select all by default
);
const toggleTask = useCallback((index: number) => {
setSelectedIndices((prev) => {
const newSet = new Set(prev);
if (newSet.has(index)) {
newSet.delete(index);
} else {
newSet.add(index);
}
return newSet;
});
}, []);
const selectAll = useCallback(() => {
setSelectedIndices(new Set(tasks.map((_, i) => i)));
}, [tasks]);
const selectNone = useCallback(() => {
setSelectedIndices(new Set());
}, []);
const handleCreate = useCallback(() => {
const selectedTasks = tasks.filter((_, i) => selectedIndices.has(i));
onCreateTasks(selectedTasks);
}, [tasks, selectedIndices, onCreateTasks]);
// Group tasks by their group property
const tasksByGroup = tasks.reduce((acc, task, index) => {
const groupKey = task.group || "Ungrouped";
if (!acc[groupKey]) {
acc[groupKey] = [];
}
acc[groupKey].push({ task, index });
return acc;
}, {} as Record<string, { task: ParsedTask; index: number }[]>);
const selectedCount = selectedIndices.size;
const totalCount = tasks.length;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
<div className="w-full max-w-2xl p-6 bg-[#0a1628] border border-[rgba(117,170,252,0.3)] max-h-[80vh] flex flex-col">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<div>
<h3 className="font-mono text-sm text-[#75aafc] uppercase">
Create Tasks from Document
</h3>
<p className="font-mono text-xs text-[#555] mt-1">
Source: {fileName}
</p>
</div>
<div className="flex items-center gap-2">
<button
onClick={selectAll}
className="font-mono text-[10px] text-[#75aafc] hover:text-[#9bc3ff] transition-colors"
>
Select All
</button>
<span className="text-[#555]">|</span>
<button
onClick={selectNone}
className="font-mono text-[10px] text-[#75aafc] hover:text-[#9bc3ff] transition-colors"
>
Select None
</button>
</div>
</div>
{/* Task List */}
<div className="flex-1 overflow-y-auto space-y-4 mb-4">
{groups.length > 0 ? (
// Grouped view
Object.entries(tasksByGroup).map(([groupName, groupTasks]) => (
<div key={groupName} className="space-y-2">
<h4 className="font-mono text-xs text-[#9bc3ff] uppercase border-b border-[rgba(117,170,252,0.2)] pb-1">
{groupName}
</h4>
{groupTasks.map(({ task, index }) => (
<TaskItem
key={index}
task={task}
index={index}
selected={selectedIndices.has(index)}
onToggle={() => toggleTask(index)}
/>
))}
</div>
))
) : (
// Flat view
tasks.map((task, index) => (
<TaskItem
key={index}
task={task}
index={index}
selected={selectedIndices.has(index)}
onToggle={() => toggleTask(index)}
/>
))
)}
</div>
{/* Footer */}
<div className="flex items-center justify-between pt-4 border-t border-[rgba(117,170,252,0.2)]">
<span className="font-mono text-xs text-[#555]">
{selectedCount} of {totalCount} tasks selected
</span>
<div className="flex gap-2">
<button
onClick={onCancel}
disabled={loading}
className="px-4 py-2 font-mono text-xs text-[#9bc3ff] hover:text-[#dbe7ff] transition-colors disabled:opacity-50"
>
Cancel
</button>
<button
onClick={handleCreate}
disabled={loading || selectedCount === 0}
className="px-4 py-2 font-mono text-xs text-[#dbe7ff] bg-[#0f3c78] border border-[#3f6fb3] hover:bg-[#153667] transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? "Creating..." : `Create ${selectedCount} Task${selectedCount !== 1 ? "s" : ""}`}
</button>
</div>
</div>
{/* Chaining info */}
{selectedCount > 1 && (
<p className="font-mono text-[10px] text-[#555] mt-2 text-center">
Tasks will be chained: each task continues from the previous one's work
</p>
)}
</div>
</div>
);
}
function TaskItem({
task,
index,
selected,
onToggle,
}: {
task: ParsedTask;
index: number;
selected: boolean;
onToggle: () => void;
}) {
return (
<button
onClick={onToggle}
className={`w-full text-left p-3 border transition-colors ${
selected
? "border-[#75aafc] bg-[rgba(117,170,252,0.1)]"
: "border-[rgba(117,170,252,0.15)] hover:border-[rgba(117,170,252,0.3)]"
}`}
>
<div className="flex items-start gap-2">
<span
className={`font-mono text-xs mt-0.5 ${
selected ? "text-[#75aafc]" : "text-[#555]"
}`}
>
{selected ? "[x]" : "[ ]"}
</span>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2">
<span className="font-mono text-[10px] text-[#555]">#{index + 1}</span>
<span className="font-mono text-sm text-[#dbe7ff]">{task.name}</span>
{task.completed && (
<span className="font-mono text-[9px] text-green-400 uppercase">
done in source
</span>
)}
</div>
{task.description && (
<p className="font-mono text-xs text-[#555] mt-1 truncate">
{task.description}
</p>
)}
{task.dependencies.length > 0 && (
<p className="font-mono text-[10px] text-[#75aafc] mt-1">
Depends on: {task.dependencies.join(", ")}
</p>
)}
</div>
</div>
</button>
);
}
|