9 const [loading, setLoading] = useState(true);
10
11 const fetchData = async () => {
12 const endpoint = new URL(ENDPOINT, window.location.origin);
13 endpoint.searchParams.append("projectId", projectId);
14
15 const res = await fetch(endpoint, {
16 headers: {
17 "Authorization": "Bearer " + token,
24 useEffect(() => {
25 if (!projectId) return;
26 fetchData();
27 }, [projectId]);
28
29 return { data, loading, refetch: fetchData };
30}
31
15 // replace all this with oauth when it's ready
16 try {
17 const res = await fetch("/api/user", {
18 headers: {
19 "Authorization": "Bearer " + valTownAPIKey,
47<!--
48
49- [x] refetch project data on create/etc
50- [x] Loading favicon
51- [x] Ensure main branch is default selected
136 let type_: "file" | "http" | "script";
137 if (path.includes("backend/index.ts")) type_ = "http";
138 if (file_text?.includes("export default app.fetch")) type_ = "http";
139 if ([".ts", ".tsx", ".js", ".jsx"].some(ext => path.endsWith(ext))) {
140 type_ = "script";
233
234 // Inject data to avoid extra round-trips
235 const initialData = await fetchInitialData();
236 const dataScript = `<script>
237 window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
280
2815. **API Design:**
282 - `fetch` handler is the entry point for HTTP vals
283 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
95 }
96
97 // If there are selected files, fetch their content and add them to the messages
98 if (selectedFiles && selectedFiles.length > 0) {
99 const vt = new ValTown({ bearerToken });
115 fileContents += `## File: ${filePath}\n\`\`\`\n${fileWithLinesNumbers(content)}\n\`\`\`\n\n`;
116 } catch (error) {
117 console.error(`Error fetching file ${filePath}:`, error);
118 fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
119 }
120 }
30 return c.json({ files: files.data });
31 } catch (error) {
32 console.error("Error fetching project files:", error);
33 return Response.json({ error: "Failed to fetch project files" }, { status: 500 });
34 }
35});
21 return c.json({ branches: branches.data });
22 } catch (error) {
23 console.error("Error fetching branches:", error);
24 return Response.json({ error: "Failed to fetch branches" }, { status: 500 });
25 }
26});
4
5export function LayoutRoute () {
6 // TODO fetch here because we're not doing any caching
7 // and we want the user data in the header ?
8 // const projects = useProjects();
62});
63
64export default app.fetch;
65