1- import { useState , useRef , useEffect } from 'react'
1+ import { useState , useRef , useEffect , useCallback } from 'react'
22import { Layout } from '@ui/components/editor/settings/Layout'
33import { NavigationItem } from '@ui/components/editor/settings/NavigationItem'
44import { ModelProvidersSection } from './sections/ModelProvidersSection'
@@ -83,8 +83,12 @@ export const Home: React.FC<Props> = (props) => {
8383 const [ commit_instructions , set_commit_instructions ] = useState ( '' )
8484 const [ stuck_sections , set_stuck_sections ] = useState ( new Set < NavItem > ( ) )
8585
86- const handle_stuck_change = ( id : NavItem , is_stuck : boolean ) => {
86+ const handle_stuck_change = useCallback ( ( id : NavItem , is_stuck : boolean ) => {
8787 set_stuck_sections ( ( prev ) => {
88+ const is_currently_stuck = prev . has ( id )
89+ if ( is_stuck === is_currently_stuck ) {
90+ return prev
91+ }
8892 const next = new Set ( prev )
8993 if ( is_stuck ) {
9094 next . add ( id )
@@ -93,7 +97,32 @@ export const Home: React.FC<Props> = (props) => {
9397 }
9498 return next
9599 } )
96- }
100+ } , [ ] )
101+
102+ const general_on_stuck_change = useCallback (
103+ ( is_stuck : boolean ) => handle_stuck_change ( 'general' , is_stuck ) ,
104+ [ handle_stuck_change ]
105+ )
106+ const model_providers_on_stuck_change = useCallback (
107+ ( is_stuck : boolean ) => handle_stuck_change ( 'model-providers' , is_stuck ) ,
108+ [ handle_stuck_change ]
109+ )
110+ const edit_context_on_stuck_change = useCallback (
111+ ( is_stuck : boolean ) => handle_stuck_change ( 'edit-context' , is_stuck ) ,
112+ [ handle_stuck_change ]
113+ )
114+ const code_completions_on_stuck_change = useCallback (
115+ ( is_stuck : boolean ) => handle_stuck_change ( 'code-completions' , is_stuck ) ,
116+ [ handle_stuck_change ]
117+ )
118+ const intelligent_update_on_stuck_change = useCallback (
119+ ( is_stuck : boolean ) => handle_stuck_change ( 'intelligent-update' , is_stuck ) ,
120+ [ handle_stuck_change ]
121+ )
122+ const commit_messages_on_stuck_change = useCallback (
123+ ( is_stuck : boolean ) => handle_stuck_change ( 'commit-messages' , is_stuck ) ,
124+ [ handle_stuck_change ]
125+ )
97126
98127 const nav_item_ids = NAV_ITEMS_CONFIG . map ( ( item ) => item . id )
99128 const active_nav_item_id =
@@ -174,9 +203,7 @@ export const Home: React.FC<Props> = (props) => {
174203 ref = { ( el ) => ( section_refs . current [ 'general' ] = el ) }
175204 title = "General"
176205 subtitle = "General settings for the extension."
177- on_stuck_change = { ( is_stuck ) =>
178- handle_stuck_change ( 'general' , is_stuck )
179- }
206+ on_stuck_change = { general_on_stuck_change }
180207 >
181208 < Item
182209 title = "Open Editor Settings"
@@ -192,9 +219,7 @@ export const Home: React.FC<Props> = (props) => {
192219 ref = { ( el ) => ( section_refs . current [ 'model-providers' ] = el ) }
193220 title = "Model Providers"
194221 subtitle = "Manage your model providers here. Add, edit, reorder, or delete providers as needed."
195- on_stuck_change = { ( is_stuck ) =>
196- handle_stuck_change ( 'model-providers' , is_stuck )
197- }
222+ on_stuck_change = { model_providers_on_stuck_change }
198223 >
199224 < ModelProvidersSection
200225 providers = { props . providers }
@@ -212,9 +237,7 @@ export const Home: React.FC<Props> = (props) => {
212237 ref = { ( el ) => ( section_refs . current [ 'edit-context' ] = el ) }
213238 title = { dictionary . settings . EDIT_CONTEXT_LABEL }
214239 subtitle = { dictionary . settings . EDIT_CONTEXT_SUBTITLE }
215- on_stuck_change = { ( is_stuck ) =>
216- handle_stuck_change ( 'edit-context' , is_stuck )
217- }
240+ on_stuck_change = { edit_context_on_stuck_change }
218241 >
219242 < ApiToolConfigurationSection
220243 configurations = { props . edit_context_configs }
@@ -233,9 +256,7 @@ export const Home: React.FC<Props> = (props) => {
233256 ref = { ( el ) => ( section_refs . current [ 'code-completions' ] = el ) }
234257 title = { dictionary . settings . CODE_COMPLETIONS_LABEL }
235258 subtitle = { dictionary . settings . CODE_COMPLETIONS_SUBTITLE }
236- on_stuck_change = { ( is_stuck ) =>
237- handle_stuck_change ( 'code-completions' , is_stuck )
238- }
259+ on_stuck_change = { code_completions_on_stuck_change }
239260 >
240261 < ApiToolConfigurationSection
241262 configurations = { props . code_completions_configs }
@@ -260,9 +281,7 @@ export const Home: React.FC<Props> = (props) => {
260281 ref = { ( el ) => ( section_refs . current [ 'intelligent-update' ] = el ) }
261282 title = { dictionary . settings . INTELLIGENT_UPDATE_LABEL }
262283 subtitle = { dictionary . settings . INTELLIGENT_UPDATE_SUBTITLE }
263- on_stuck_change = { ( is_stuck ) =>
264- handle_stuck_change ( 'intelligent-update' , is_stuck )
265- }
284+ on_stuck_change = { intelligent_update_on_stuck_change }
266285 >
267286 < ApiToolConfigurationSection
268287 configurations = { props . intelligent_update_configs }
@@ -287,9 +306,7 @@ export const Home: React.FC<Props> = (props) => {
287306 ref = { ( el ) => ( section_refs . current [ 'commit-messages' ] = el ) }
288307 title = { dictionary . settings . COMMIT_MESSAGES_LABEL }
289308 subtitle = "Configure models for generating commit messages, and customize the instructions used."
290- on_stuck_change = { ( is_stuck ) =>
291- handle_stuck_change ( 'commit-messages' , is_stuck )
292- }
309+ on_stuck_change = { commit_messages_on_stuck_change }
293310 >
294311 < Item
295312 title = "Commit Message Instructions"
0 commit comments