@@ -17,6 +17,7 @@ interface WorkspaceState {
1717 lbrnFileContent : LbrnFileContent | null
1818 lbrnOptions : ConvertCircuitJsonToLbrnOptions
1919 isConverting : boolean
20+ isProcessingFile : boolean
2021 error : string | null
2122}
2223
@@ -25,6 +26,7 @@ interface WorkspaceContextType extends WorkspaceState {
2526 setLbrnFileContent : ( data : LbrnFileContent | null ) => void
2627 setLbrnOptions : ( options : Partial < ConvertCircuitJsonToLbrnOptions > ) => void
2728 setIsConverting : ( converting : boolean ) => void
29+ setIsProcessingFile : ( processing : boolean ) => void
2830 setError : ( error : string | null ) => void
2931 convertToLbrn : ( options ?: any ) => Promise < void >
3032 loadKicadPcbFile : ( pcbContent : string ) => Promise < void >
@@ -54,6 +56,7 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
5456 origin : { x : 0 , y : 0 } ,
5557 } )
5658 const [ isConverting , setIsConverting ] = useState ( false )
59+ const [ isProcessingFile , setIsProcessingFile ] = useState ( false )
5760 const [ error , setError ] = useState < string | null > ( null )
5861
5962 const setCircuitJson = ( data : CircuitJson | null ) => {
@@ -106,23 +109,15 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
106109
107110 if ( fileName . endsWith ( ".json" ) ) {
108111 // Handle Circuit JSON files
109- try {
110- const text = await file . text ( )
111- const circuitJsonData = JSON . parse ( text )
112- setCircuitJson ( circuitJsonData )
113- } catch ( err ) {
114- alert ( "Invalid JSON file" )
115- }
112+ const text = await file . text ( )
113+ const circuitJsonData = JSON . parse ( text )
114+ setCircuitJson ( circuitJsonData )
116115 } else if ( fileName . endsWith ( ".kicad_pcb" ) ) {
117116 // Handle KiCad PCB files
118- try {
119- const text = await file . text ( )
120- await loadKicadPcbFile ( text )
121- } catch ( err ) {
122- alert ( `Failed to convert KiCad file: ${ err } ` )
123- }
117+ const text = await file . text ( )
118+ await loadKicadPcbFile ( text )
124119 } else {
125- alert ( "Please upload a .json or .kicad_pcb file" )
120+ throw new Error ( "Please upload a .json or .kicad_pcb file" )
126121 }
127122 }
128123
@@ -159,30 +154,36 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
159154 const items = dataTransfer . items
160155 if ( items . length === 0 ) return
161156
162- // Check if it's a directory drop
163- for ( let i = 0 ; i < items . length ; i ++ ) {
164- const item = items [ i ]
165- const entry = item . webkitGetAsEntry ?.( )
166-
167- if ( entry ?. isDirectory ) {
168- // Handle folder drop - look for .kicad_pcb file
169- const kicadFile = await findKicadPcbInDirectory (
170- entry as FileSystemDirectoryEntry ,
171- )
172- if ( kicadFile ) {
173- await processCircuitFile ( kicadFile )
174- return
175- } else {
176- alert ( "No .kicad_pcb file found in the dropped folder" )
177- return
157+ try {
158+ setIsProcessingFile ( true )
159+
160+ // Check if it's a directory drop
161+ for ( let i = 0 ; i < items . length ; i ++ ) {
162+ const item = items [ i ]
163+ const entry = item . webkitGetAsEntry ?.( )
164+
165+ if ( entry ?. isDirectory ) {
166+ // Handle folder drop - look for .kicad_pcb file
167+ const kicadFile = await findKicadPcbInDirectory (
168+ entry as FileSystemDirectoryEntry ,
169+ )
170+ if ( kicadFile ) {
171+ await processCircuitFile ( kicadFile )
172+ return
173+ } else {
174+ alert ( "No .kicad_pcb file found in the dropped folder" )
175+ return
176+ }
178177 }
179178 }
180- }
181179
182- // Handle file drops (existing behavior)
183- const files = dataTransfer . files
184- if ( files . length > 0 ) {
185- await processCircuitFile ( files [ 0 ] )
180+ // Handle file drops (existing behavior)
181+ const files = dataTransfer . files
182+ if ( files . length > 0 ) {
183+ await processCircuitFile ( files [ 0 ] )
184+ }
185+ } finally {
186+ setIsProcessingFile ( false )
186187 }
187188 }
188189
@@ -218,11 +219,13 @@ export function WorkspaceProvider({ children }: { children: ReactNode }) {
218219 lbrnFileContent,
219220 lbrnOptions,
220221 isConverting,
222+ isProcessingFile,
221223 error,
222224 setCircuitJson,
223225 setLbrnFileContent,
224226 setLbrnOptions,
225227 setIsConverting,
228+ setIsProcessingFile,
226229 setError,
227230 convertToLbrn,
228231 loadKicadPcbFile,
0 commit comments