()
| 99 | } |
| 100 | |
| 101 | export function AppSelectionModal() { |
| 102 | const [apps, setApps] = useState<AppInfo[]>([]); |
| 103 | const [loading, setLoading] = useState(true); |
| 104 | const [error, setError] = useState(""); |
| 105 | |
| 106 | useEffect(() => { |
| 107 | loadApps(); |
| 108 | }, []); |
| 109 | |
| 110 | const loadApps = async () => { |
| 111 | try { |
| 112 | const appList = await RpcApi.ListAllEditableAppsCommand(TabRpcClient); |
| 113 | const sortedApps = (appList || []).sort((a, b) => b.modtime - a.modtime); |
| 114 | setApps(sortedApps); |
| 115 | } catch (err) { |
| 116 | console.error("Failed to load apps:", err); |
| 117 | setError("Failed to load apps"); |
| 118 | } finally { |
| 119 | setLoading(false); |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | const handleSelectApp = async (appId: string) => { |
| 124 | let appIdToUse = appId; |
| 125 | |
| 126 | // If selecting a local app, convert it to a draft first |
| 127 | if (appId.startsWith("local/")) { |
| 128 | try { |
| 129 | const result = await RpcApi.MakeDraftFromLocalCommand(TabRpcClient, { localappid: appId }); |
| 130 | appIdToUse = result.draftappid; |
| 131 | } catch (err) { |
| 132 | console.error("Failed to create draft from local app:", err); |
| 133 | setError(`Failed to create draft from ${appId}: ${err.message || String(err)}`); |
| 134 | return; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | const builderId = globalStore.get(atoms.builderId); |
| 139 | const oref = WOS.makeORef("builder", builderId); |
| 140 | await RpcApi.SetRTInfoCommand(TabRpcClient, { |
| 141 | oref, |
| 142 | data: { "builder:appid": appIdToUse }, |
| 143 | }); |
| 144 | globalStore.set(atoms.builderAppId, appIdToUse); |
| 145 | document.title = `WaveApp Builder (${appIdToUse})`; |
| 146 | getApi().setBuilderWindowAppId(appIdToUse); |
| 147 | }; |
| 148 | |
| 149 | const handleCreateNew = async (appName: string) => { |
| 150 | const draftAppId = `draft/${appName}`; |
| 151 | const builderId = globalStore.get(atoms.builderId); |
| 152 | const oref = WOS.makeORef("builder", builderId); |
| 153 | await RpcApi.SetRTInfoCommand(TabRpcClient, { |
| 154 | oref, |
| 155 | data: { "builder:appid": draftAppId }, |
| 156 | }); |
| 157 | globalStore.set(atoms.builderAppId, draftAppId); |
| 158 | document.title = `WaveApp Builder (${draftAppId})`; |
nothing calls this directly
no test coverage detected