Skip to content

Commit cb13299

Browse files
committed
Implement auto-focus for newly added tasks and adjust task header padding
1 parent 8c74083 commit cb13299

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import cn from 'classnames'
99
import { Task } from '@shared/types/task'
1010
import { IconButton } from '../IconButton'
1111
import { TaskGroup, SortableTask } from './components/TaskGroup'
12+
import { use_auto_focus_new_task } from './hooks/use-auto-focus-new-task'
1213

1314
dayjs.extend(relativeTime)
1415

@@ -59,6 +60,8 @@ export const Tasks: React.FC<Props> = (props) => {
5960
>(null)
6061
const prevent_edit_ref = useRef(false)
6162

63+
use_auto_focus_new_task(props.tasks, set_editing_timestamp)
64+
6265
const structure_signature = useMemo(
6366
() => get_structure_signature(props.tasks),
6467
[props.tasks]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useEffect, useRef } from 'react'
2+
import { Task } from '@shared/types/task'
3+
4+
export const use_auto_focus_new_task = (
5+
tasks: Task[],
6+
set_editing_timestamp: (timestamp: number | null) => void
7+
) => {
8+
const prev_ids_ref = useRef<Set<number>>(new Set())
9+
const is_first_render = useRef(true)
10+
11+
useEffect(() => {
12+
const current_ids = new Set<number>()
13+
const collect_ids = (t: Task[]) => {
14+
t.forEach((task) => {
15+
current_ids.add(task.created_at)
16+
if (task.children) collect_ids(task.children)
17+
})
18+
}
19+
collect_ids(tasks)
20+
21+
if (is_first_render.current) {
22+
is_first_render.current = false
23+
prev_ids_ref.current = current_ids
24+
return
25+
}
26+
27+
const added_ids = Array.from(current_ids).filter(
28+
(id) => !prev_ids_ref.current.has(id)
29+
)
30+
31+
if (added_ids.length === 1) {
32+
set_editing_timestamp(added_ids[0])
33+
}
34+
35+
prev_ids_ref.current = current_ids
36+
}, [tasks, set_editing_timestamp])
37+
}

‎packages/vscode/src/views/panel/frontend/Home/Home.module.scss‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
display: flex;
145145
align-items: center;
146146
justify-content: space-between;
147-
padding: 1px 12px 0px 12px;
147+
padding: 1px 12px 3px 12px;
148148
font-size: 11px;
149149
font-weight: bold;
150150
color: var(--cwc-text-color-dimmed);

0 commit comments

Comments
 (0)