| 45 | |
| 46 | React.useEffect(() => { |
| 47 | async function loadSourceCode() { |
| 48 | try { |
| 49 | const mod = await import(`../../public/r/${name}.json`) |
| 50 | const json = mod.default |
| 51 | |
| 52 | // Find the main component file that matches the name |
| 53 | const mainFile = json.files.find( |
| 54 | (file: any) => file.path.split("/").pop().replace(".tsx", "") === name |
| 55 | ) |
| 56 | |
| 57 | if (mainFile) { |
| 58 | setSourceCode(mainFile.content) |
| 59 | } else { |
| 60 | console.error(`Could not find main file for ${name}`) |
| 61 | setSourceCode("") |
| 62 | } |
| 63 | } catch (error) { |
| 64 | console.error(`Failed to load source for ${name}:`, error) |
| 65 | setSourceCode("") |
| 66 | } |
| 67 | } |
| 68 | loadSourceCode() |
| 69 | }, [name]) |
| 70 | |