@@ -424,8 +424,8 @@ export default function App() {
424424 downloadJson ( { nodes, edges, board : selectedBoard } , 'my-logic-project' ) ;
425425 } ;
426426
427- // Function to load project data (reusable)
428- const loadProjectData = ( data : any ) => {
427+ // Wrap your loadProjectData function with useCallback
428+ const loadProjectData = useCallback ( ( data : any ) => {
429429 // Reset ID counter based on loaded nodes
430430 resetIdCounter ( data . nodes ) ;
431431
@@ -446,7 +446,12 @@ export default function App() {
446446 setNodes ( updatedNodes ) ;
447447 setEdges ( data . edges ) ;
448448 if ( data . board ) setSelectedBoard ( data . board ) ;
449- } ;
449+ } , [ selectedBoard , handlePinChange , handleInputsChange , handleInitialStateChange , handlePulseLengthChange , handleIntervalChange ] ) ;
450+
451+ // Then use it in your useEffect
452+ useEffect ( ( ) => {
453+ loadProjectData ( defaultProject ) ;
454+ } , [ loadProjectData ] ) ; // Now loadProjectData is properly included
450455
451456 const handleUpload = ( ) => {
452457 uploadJson ( ( data ) => {
@@ -475,9 +480,9 @@ export default function App() {
475480 } ;
476481
477482 const getArduinoInoFile = async ( ) => {
478- const githubUrl = 'https://raw.githubusercontent.com/MerzSebastian/OpenPLC/refs/heads/main/arduino/arduino.ino' ;
479- const response = await fetch ( githubUrl ) ;
480- return await response . text ( ) ;
483+ const githubUrl = 'https://raw.githubusercontent.com/MerzSebastian/OpenPLC/refs/heads/main/arduino/arduino.ino' ;
484+ const response = await fetch ( githubUrl ) ;
485+ return await response . text ( ) ;
481486 }
482487
483488 const copyArduinoCode = async ( ) => {
@@ -535,7 +540,7 @@ export default function App() {
535540 // Create message with structure [START_BYTE][LENGTH][DATA...][CHECKSUM]
536541 const START_BYTE = 0x7E ;
537542 const LENGTH = bytecode . length ;
538-
543+
539544 // Calculate checksum
540545 let checksum = 0 ;
541546 for ( let i = 0 ; i < bytecode . length ; i ++ ) {
@@ -544,10 +549,10 @@ export default function App() {
544549
545550 // Create message array
546551 const message = [ START_BYTE , LENGTH , ...bytecode , checksum ] ;
547-
552+
548553 // Convert to Uint8Array
549554 const data = new Uint8Array ( message ) ;
550-
555+
551556 // Write the data
552557 const writer = port . writable . getWriter ( ) ;
553558 await writer . write ( data ) ;
@@ -559,7 +564,7 @@ export default function App() {
559564 let response = '' ;
560565
561566 // Set a timeout for reading response
562- const timeoutPromise = new Promise ( ( _ , reject ) =>
567+ const timeoutPromise = new Promise ( ( _ , reject ) =>
563568 setTimeout ( ( ) => reject ( new Error ( 'Timeout waiting for response' ) ) , 60000 )
564569 ) ;
565570
@@ -568,7 +573,7 @@ export default function App() {
568573 while ( true ) {
569574 const { value, done } = await reader . read ( ) ;
570575 if ( done ) break ;
571-
576+
572577 response += new TextDecoder ( ) . decode ( value ) ;
573578 if ( response . includes ( 'SUCCESS' ) || response . includes ( 'ERROR' ) ) {
574579 responseReceived = true ;
@@ -662,13 +667,12 @@ export default function App() {
662667 Copy Arduino Code
663668 </ button >
664669 When you want to test on Wokwi.com you can use see the default project < a className = 'text-blue-700' href = 'https://wokwi.com/projects/441553408946374657' > here</ a >
665-
670+
666671 { uploadStatus && (
667- < div className = { `mt-2 p-2 text-center text-sm rounded ${
668- uploadStatus . includes ( 'success' ) || uploadStatus . includes ( 'copied' ) || uploadStatus . includes ( 'loaded' ) || uploadStatus . includes ( 'reset' )
669- ? 'bg-green-100 text-green-800'
672+ < div className = { `mt-2 p-2 text-center text-sm rounded ${ uploadStatus . includes ( 'success' ) || uploadStatus . includes ( 'copied' ) || uploadStatus . includes ( 'loaded' ) || uploadStatus . includes ( 'reset' )
673+ ? 'bg-green-100 text-green-800'
670674 : 'bg-red-100 text-red-800'
671- } `} >
675+ } `} >
672676 { uploadStatus }
673677 </ div >
674678 ) }
0 commit comments