@@ -169,19 +169,27 @@ function EditorComponent() {
169169 DEFAULT_LANGUAGE : selectedLanguage . DEFAULT_LANGUAGE ,
170170 NAME : selectedLanguage . NAME ,
171171 } ) ;
172- const savedCode = localStorage . getItem ( `code-${ currentLanguage } ` ) ;
173- if ( savedCode ) {
172+ const savedCode = localStorage . getItem ( `code-${ selectedLanguage . DEFAULT_LANGUAGE } ` ) ;
173+ if ( savedCode !== null ) {
174174 setCode ( savedCode ) ;
175175 } else {
176176 setCode ( selectedLanguage . HELLO_WORLD ) ;
177177 }
178178 } , [ currentLanguage ] ) ;
179179
180180 useEffect ( ( ) => {
181- if ( code ) {
182- localStorage . setItem ( `code-${ currentLanguage } ` , code ) ;
183- }
184- } , [ code , currentLanguage ] ) ;
181+ const handler = setTimeout ( ( ) => {
182+ if ( code ) {
183+ localStorage . setItem ( `code-${ currentLanguage } ` , code ) ;
184+ } else {
185+ localStorage . removeItem ( `code-${ currentLanguage } ` ) ;
186+ }
187+ } , 500 ) ;
188+
189+ return ( ) => {
190+ clearTimeout ( handler ) ;
191+ } ;
192+ } , [ code ] ) ;
185193
186194 const handleEditorThemeChange = async ( _ , theme ) => {
187195 if ( [ "light" , "vs-dark" ] . includes ( theme . ID ) ) {
@@ -256,16 +264,22 @@ function EditorComponent() {
256264 . then ( ( response ) => response . json ( ) )
257265 . then ( ( data ) => {
258266 const newOutput = [ ] ;
267+ let errorMessage = [ ] ;
268+
259269 if ( data . stdout ) {
260270 newOutput . push ( ...decodeFormat ( data . stdout ) ) ;
261271 }
262272 if ( data . stderr ) {
263273 newOutput . push ( ...decodeFormat ( data . stderr ) ) ;
264- enqueueSnackbar ( "Error in code" , { variant : "error" } ) ;
274+ errorMessage . push ( "Error in code" ) ;
265275 }
266276 if ( data . compile_output ) {
267277 newOutput . push ( ...decodeFormat ( data . compile_output ) ) ;
268- enqueueSnackbar ( "Compilation error" , { variant : "error" } ) ;
278+ errorMessage . push ( "Compilation error" ) ;
279+ }
280+
281+ if ( errorMessage . length > 0 ) {
282+ enqueueSnackbar ( errorMessage . join ( " and " ) , { variant : "error" } ) ;
269283 }
270284 setOutput ( newOutput ) ;
271285 } )
0 commit comments