1+ import { useState , useRef } from 'react'
12import styles from './Home.module.scss'
23import { Scrollable } from '@ui/components/editor/panel/Scrollable'
34import { Timeline } from '@ui/components/editor/panel/Timeline'
@@ -43,6 +44,9 @@ type Props = {
4344
4445export const Home : React . FC < Props > = ( props ) => {
4546 const { t } = use_translation ( )
47+ const [ is_mode_sticky , set_is_mode_sticky ] = useState ( false )
48+ const responses_ref = useRef < HTMLDivElement > ( null )
49+ const mode_ref = useRef < HTMLDivElement > ( null )
4650
4751 const {
4852 handle_reorder,
@@ -93,11 +97,17 @@ export const Home: React.FC<Props> = (props) => {
9397 </ button >
9498 </ div >
9599
96- < Scrollable >
100+ < Scrollable
101+ on_scroll = { ( top ) => {
102+ const responses_height = responses_ref . current ?. clientHeight || 0
103+ const mode_height = mode_ref . current ?. clientHeight || 0
104+ set_is_mode_sticky ( top > responses_height + mode_height + 4 )
105+ } }
106+ >
97107 < div className = { styles . content } >
98108 < div className = { styles . inner } >
99109 { props . response_history . length > 0 && (
100- < div className = { styles . inner__responses } >
110+ < div className = { styles . inner__responses } ref = { responses_ref } >
101111 < UiResponses
102112 response_history = { props . response_history }
103113 on_response_history_item_click = {
@@ -112,20 +122,27 @@ export const Home: React.FC<Props> = (props) => {
112122 on_response_history_item_remove = {
113123 props . on_response_history_item_remove
114124 }
115- /> { ' ' }
125+ />
116126 </ div >
117127 ) }
118128
119- < div className = { styles . inner__mode } >
129+ < div
130+ className = { cn ( styles . inner__mode , {
131+ [ styles [ 'inner__mode--sticky' ] ] : is_mode_sticky
132+ } ) }
133+ ref = { mode_ref }
134+ >
120135 < ModeButton
121136 pre = "Autofill"
122137 label = "Chatbots"
123138 on_click = { props . on_chatbots_click }
139+ is_compact = { is_mode_sticky }
124140 />
125141 < ModeButton
126142 pre = "Make"
127143 label = "API calls"
128144 on_click = { props . on_api_calls_click }
145+ is_compact = { is_mode_sticky }
129146 />
130147 </ div >
131148
@@ -137,52 +154,83 @@ export const Home: React.FC<Props> = (props) => {
137154 on_toggle_collapsed = { ( ) =>
138155 props . on_tasks_collapsed_change ( ! props . are_tasks_collapsed )
139156 }
157+ actions = {
158+ Object . keys ( props . tasks ) . length == 1 ? (
159+ < IconButton
160+ codicon_icon = "add"
161+ title = "Add Task"
162+ on_click = { ( e ) => {
163+ e . stopPropagation ( )
164+ const roots = Object . keys ( props . tasks )
165+ if ( roots . length > 0 ) {
166+ handle_add ( roots [ 0 ] , props . tasks [ roots [ 0 ] ] , 'top' )
167+ if ( props . are_tasks_collapsed ) {
168+ props . on_tasks_collapsed_change ( false )
169+ }
170+ }
171+ } }
172+ />
173+ ) : undefined
174+ }
140175 />
141176 { ! props . are_tasks_collapsed &&
142- Object . entries ( props . tasks ) . map (
143- ( [ workspace_root_folder , tasks ] , _ , entries ) => (
177+ Object . entries ( props . tasks )
178+ . filter ( ( [ _ , tasks ] , __ , arr ) =>
179+ arr . length == 1 ? tasks . length : true
180+ )
181+ . map ( ( [ workspace_root_folder , tasks ] , _ , entries ) => (
144182 < div
145183 key = { workspace_root_folder }
146184 className = { styles . inner__tasks }
147185 >
148186 { entries . length > 1 && (
149187 < div className = { styles [ 'inner__tasks-header' ] } >
150- { workspace_root_folder . split ( / [ \\ / ] / ) . pop ( ) ||
151- workspace_root_folder }
188+ < span >
189+ { workspace_root_folder . split ( / [ \\ / ] / ) . pop ( ) ||
190+ workspace_root_folder }
191+ </ span >
192+ < button
193+ className = { styles [ 'add-button' ] }
194+ title = "Add Task"
195+ onClick = { ( ) => {
196+ handle_add ( workspace_root_folder , tasks , 'top' )
197+ } }
198+ />
152199 </ div >
153200 ) }
154- < Tasks
155- tasks = { tasks }
156- on_reorder = { ( new_tasks ) =>
157- handle_reorder ( workspace_root_folder , new_tasks )
158- }
159- on_change = { ( updated_task ) => {
160- handle_change (
161- workspace_root_folder ,
162- tasks ,
163- updated_task
164- )
165- } }
166- on_add = { ( ) => {
167- handle_add ( workspace_root_folder , tasks )
168- } }
169- on_add_subtask = { ( parent_task ) => {
170- handle_add_subtask (
171- workspace_root_folder ,
172- tasks ,
173- parent_task
174- )
175- } }
176- on_delete = { ( timestamp ) => {
177- handle_delete ( workspace_root_folder , timestamp )
178- } }
179- on_copy = { ( text ) => {
180- handle_copy ( text )
181- } }
182- />
201+ { tasks . length > 0 && (
202+ < Tasks
203+ tasks = { tasks }
204+ on_reorder = { ( new_tasks ) =>
205+ handle_reorder ( workspace_root_folder , new_tasks )
206+ }
207+ on_change = { ( updated_task ) => {
208+ handle_change (
209+ workspace_root_folder ,
210+ tasks ,
211+ updated_task
212+ )
213+ } }
214+ on_add = { ( ) => {
215+ handle_add ( workspace_root_folder , tasks )
216+ } }
217+ on_add_subtask = { ( parent_task ) => {
218+ handle_add_subtask (
219+ workspace_root_folder ,
220+ tasks ,
221+ parent_task
222+ )
223+ } }
224+ on_delete = { ( timestamp ) => {
225+ handle_delete ( workspace_root_folder , timestamp )
226+ } }
227+ on_copy = { ( text ) => {
228+ handle_copy ( text )
229+ } }
230+ />
231+ ) }
183232 </ div >
184- )
185- ) }
233+ ) ) }
186234
187235 < ListHeader
188236 title = "Timeline"
0 commit comments