File tree Expand file tree Collapse file tree
ui/src/components/editor/panel/Tasks
vscode/src/views/panel/frontend/Home Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import cn from 'classnames'
99import { Task } from '@shared/types/task'
1010import { IconButton } from '../IconButton'
1111import { TaskGroup , SortableTask } from './components/TaskGroup'
12+ import { use_auto_focus_new_task } from './hooks/use-auto-focus-new-task'
1213
1314dayjs . 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 ]
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 144144 display : flex ;
145145 align-items : center ;
146146 justify-content : space-between ;
147- padding : 1px 12px 0 px 12px ;
147+ padding : 1px 12px 3 px 12px ;
148148 font-size : 11px ;
149149 font-weight : bold ;
150150 color : var (--cwc-text-color-dimmed );
You can’t perform that action at this time.
0 commit comments