@@ -68,53 +68,47 @@ export const WorkshopContextProvider = ({ children }) => {
6868 } ) ;
6969 } , [ activeSectionId , setActiveSection , refreshCounter ] ) ;
7070
71- const runCommand = useCallback (
72- ( codeBlockIndex ) => {
73- return fetch ( `/api/sections/${ activeSection . id } /command` , {
74- method : "POST" ,
75- headers : {
76- "Content-Type" : "application/json" ,
77- } ,
78- body : JSON . stringify ( { codeBlockIndex } ) ,
71+ const runCommand = useCallback ( ( activeSectionId , codeBlockIndex ) => {
72+ return fetch ( `/api/sections/${ activeSectionId } /command` , {
73+ method : "POST" ,
74+ headers : {
75+ "Content-Type" : "application/json" ,
76+ } ,
77+ body : JSON . stringify ( { codeBlockIndex } ) ,
78+ } )
79+ . then ( ( response ) => {
80+ if ( ! response . ok ) throw new Error ( "Failed to run command" ) ;
81+ return response . json ( ) ;
7982 } )
80- . then ( ( response ) => {
81- if ( ! response . ok ) throw new Error ( "Failed to run command" ) ;
82- return response . json ( ) ;
83- } )
84- . then ( ( result ) => {
85- console . log ( "Command result:" , result ) ;
86- } )
87- . catch ( ( error ) => {
88- console . error ( "Error running command:" , error ) ;
89- toast . error ( "Failed to run command. Please try again." ) ;
90- } ) ;
91- } ,
92- [ activeSection ] ,
93- ) ;
94-
95- const saveFileCommand = useCallback (
96- ( codeBlockIndex ) => {
97- return fetch ( `/api/sections/${ activeSection . id } /save-file` , {
98- method : "POST" ,
99- headers : {
100- "Content-Type" : "application/json" ,
101- } ,
102- body : JSON . stringify ( { codeBlockIndex } ) ,
83+ . then ( ( result ) => {
84+ console . log ( "Command result:" , result ) ;
10385 } )
104- . then ( ( response ) => {
105- if ( ! response . ok ) throw new Error ( "Failed to save file" ) ;
106- return response . json ( ) ;
107- } )
108- . then ( ( result ) => {
109- console . log ( "Save file result:" , result ) ;
110- } )
111- . catch ( ( error ) => {
112- console . error ( "Error saving file:" , error ) ;
113- toast . error ( "Failed to save file. Please try again." ) ;
114- } ) ;
115- } ,
116- [ activeSection ] ,
117- ) ;
86+ . catch ( ( error ) => {
87+ console . error ( "Error running command:" , error ) ;
88+ toast . error ( "Failed to run command. Please try again." ) ;
89+ } ) ;
90+ } , [ ] ) ;
91+
92+ const saveFileCommand = useCallback ( ( activeSectionId , codeBlockIndex ) => {
93+ return fetch ( `/api/sections/${ activeSectionId } /save-file` , {
94+ method : "POST" ,
95+ headers : {
96+ "Content-Type" : "application/json" ,
97+ } ,
98+ body : JSON . stringify ( { codeBlockIndex } ) ,
99+ } )
100+ . then ( ( response ) => {
101+ if ( ! response . ok ) throw new Error ( "Failed to save file" ) ;
102+ return response . json ( ) ;
103+ } )
104+ . then ( ( result ) => {
105+ console . log ( "Save file result:" , result ) ;
106+ } )
107+ . catch ( ( error ) => {
108+ console . error ( "Error saving file:" , error ) ;
109+ toast . error ( "Failed to save file. Please try again." ) ;
110+ } ) ;
111+ } , [ ] ) ;
118112
119113 useEffect ( ( ) => {
120114 if ( ! workshop ) return ;
0 commit comments