Skip to content

Commit c24abed

Browse files
committed
Improve task addition interactivity with row-level hover effects and restrict auto-focus to empty new tasks
1 parent 5905418 commit c24abed

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎packages/ui/src/components/editor/panel/Tasks/Tasks.module.scss‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@
157157
}
158158
}
159159

160+
.add-row {
161+
position: relative;
162+
display: flex;
163+
164+
&:hover {
165+
background-color: var(--vscode-list-hoverBackground);
166+
167+
.add-button::before {
168+
opacity: 1;
169+
}
170+
}
171+
}
172+
160173
.empty {
161174
padding: 8px 12px;
162175
font-size: 11px;

‎packages/ui/src/components/editor/panel/Tasks/components/TaskGroup.tsx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
7070
})}
7171
</ReactSortable>
7272
{props.on_add && (
73-
<div style={{ position: 'relative', display: 'flex' }}>
73+
<div className={styles['add-row']} onClick={props.on_add}>
7474
{[...Array(depth)].map((_, i) => (
7575
<div
7676
key={i}
@@ -80,7 +80,6 @@ export const TaskGroup: React.FC<TaskGroupProps> = (props) => {
8080
))}
8181
<button
8282
className={cn(styles['add-button'], styles['add-button--add'])}
83-
onClick={props.on_add}
8483
style={{ marginLeft: `${13 + depth * 20}px` }}
8584
title="Add task"
8685
/>

‎packages/ui/src/components/editor/panel/Tasks/hooks/use-auto-focus-new-task.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export const use_auto_focus_new_task = (
1010

1111
useEffect(() => {
1212
const current_ids = new Set<number>()
13+
const id_to_task = new Map<number, Task>()
14+
1315
const collect_ids = (t: Task[]) => {
1416
t.forEach((task) => {
1517
current_ids.add(task.created_at)
18+
id_to_task.set(task.created_at, task)
1619
if (task.children) collect_ids(task.children)
1720
})
1821
}
@@ -29,7 +32,10 @@ export const use_auto_focus_new_task = (
2932
)
3033

3134
if (added_ids.length === 1) {
32-
set_editing_timestamp(added_ids[0])
35+
const new_task = id_to_task.get(added_ids[0])
36+
if (new_task && new_task.text === '') {
37+
set_editing_timestamp(added_ids[0])
38+
}
3339
}
3440

3541
prev_ids_ref.current = current_ids

0 commit comments

Comments
 (0)