@@ -6,19 +6,20 @@ import { Home, NavItem } from './Home/Home'
66import { use_web_configuration_editing } from './hooks/use-web-configuration-editing'
77import { Modal as UiModal } from '@ui/components/editor/settings/Modal'
88import { EditWebConfigurationForm } from '@/views/shared/components/EditWebConfigurationForm'
9- import { WebConfiguration } from '@shared/types/web-configuration'
109
1110const vscode = acquireVsCodeApi ( )
1211
1312export const Settings = ( ) => {
1413 const settings_hook = use_settings ( vscode )
15- const { updating_web_configuration, set_updating_web_configuration } =
16- use_web_configuration_editing ( )
14+ const {
15+ updating_web_configuration,
16+ set_updating_web_configuration,
17+ set_updated_web_configuration,
18+ edit_web_configuration_cancel_handler,
19+ edit_web_configuration_save_handler
20+ } = use_web_configuration_editing ( vscode )
1721 const [ scroll_to_section_on_load , set_scroll_to_section_on_load ] =
1822 useState < NavItem > ( )
19- const [ updated_web_configuration , set_updated_web_configuration ] = useState <
20- WebConfiguration | undefined
21- > ( )
2223
2324 const all_data_loaded = useMemo ( ( ) => {
2425 return (
@@ -46,18 +47,12 @@ export const Settings = () => {
4647 )
4748 } , [ settings_hook ] )
4849
49- useEffect ( ( ) => {
50- set_updated_web_configuration ( updating_web_configuration )
51- } , [ updating_web_configuration ] )
52-
5350 useEffect ( ( ) => {
5451 if ( ! all_data_loaded ) return
5552 post_message ( vscode , { command : 'SETTINGS_UI_READY' } )
5653 const handle_message = ( event : MessageEvent < BackendMessage > ) => {
5754 if ( event . data . command == 'SHOW_SECTION' ) {
5855 set_scroll_to_section_on_load ( event . data . section as NavItem )
59- } else if ( event . data . command == 'WEB_CONFIGURATION_UPDATED' ) {
60- set_updating_web_configuration ( undefined )
6156 }
6257 }
6358 window . addEventListener ( 'message' , handle_message )
@@ -201,44 +196,11 @@ export const Settings = () => {
201196 scroll_to_section_on_load = { scroll_to_section_on_load }
202197 />
203198 { updating_web_configuration && (
204- < UiModal
205- on_close = { ( ) => {
206- if ( updated_web_configuration ) {
207- post_message ( vscode , {
208- command : 'UPDATE_WEB_CONFIGURATION' ,
209- updating_web_configuration,
210- updated_web_configuration,
211- origin : 'cancel'
212- } )
213- } else {
214- set_updating_web_configuration ( undefined )
215- }
216- } }
217- >
199+ < UiModal on_close = { edit_web_configuration_cancel_handler } >
218200 < UiModal . Form
219201 title = "Edit Configuration"
220- on_save = { ( ) => {
221- if ( updated_web_configuration ) {
222- post_message ( vscode , {
223- command : 'UPDATE_WEB_CONFIGURATION' ,
224- updating_web_configuration,
225- updated_web_configuration,
226- origin : 'save'
227- } )
228- }
229- } }
230- on_cancel = { ( ) => {
231- if ( updated_web_configuration ) {
232- post_message ( vscode , {
233- command : 'UPDATE_WEB_CONFIGURATION' ,
234- updating_web_configuration,
235- updated_web_configuration,
236- origin : 'cancel'
237- } )
238- } else {
239- set_updating_web_configuration ( undefined )
240- }
241- } }
202+ on_save = { edit_web_configuration_save_handler }
203+ on_cancel = { edit_web_configuration_cancel_handler }
242204 >
243205 < EditWebConfigurationForm
244206 web_configuration = { updating_web_configuration }
0 commit comments