ditheringMaybeindex.ts2 matches
21});
2223// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
OpenTownieChat.tsx1 match
28const [isDragging, setIsDragging] = useState(false);
2930// Use custom hook to fetch project files
31const {
32projectFiles,
OpenTownieuseProjectFiles.ts4 matches
1import { useState, useEffect } from "https://esm.sh/react@18.2.0?dev";
2import { fetchProjectFiles } from "../utils/api.ts";
34interface UseProjectFilesProps {
1516/**
17* Custom hook to fetch and manage project files
18*/
19export function useProjectFiles({
38
39try {
40const filesData = await fetchProjectFiles({
41bearerToken,
42projectId,
51}
52} catch (err) {
53console.error("Error fetching project files:", err);
54setProjectFiles([]);
55setError(err instanceof Error ? err : new Error(String(err)));
OpenTowniesystem_prompt.txt5 matches
71```
72735. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
74```ts
75const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
76```
77200
201// Inject data to avoid extra round-trips
202const initialData = await fetchInitialData();
203const dataScript = `<script>
204window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
2582595. **API Design:**
260- `fetch` handler is the entry point for HTTP vals
261- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
262- Properly handle CORS if needed for external access
OpenTownieProjects.tsx1 match
1011async function loader({ bearerToken }: { bearerToken: string }) {
12const data = await (await fetch("/api/projects-loader", {
13headers: {
14"Authorization": "Bearer " + bearerToken,
OpenTownieindex.ts1 match
28});
2930export default app.fetch;
OpenTownieindex.ts7 matches
128}
129130// If there are selected files, fetch their content and add them to the messages
131if (selectedFiles && selectedFiles.length > 0) {
132const vt = new ValTown({ bearerToken });
148fileContents += `## File: ${filePath}\n\`\`\`\n${content}\n\`\`\`\n\n`;
149} catch (error) {
150console.error(`Error fetching file ${filePath}:`, error);
151fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
152}
153}
260return c.json({ files: files.data });
261} catch (error) {
262console.error("Error fetching project files:", error);
263return Response.json({ error: "Failed to fetch project files" }, { status: 500 });
264}
265});
282return c.json({ branches: branches.data });
283} catch (error) {
284console.error("Error fetching branches:", error);
285return Response.json({ error: "Failed to fetch branches" }, { status: 500 });
286}
287});
OpenTownieCreateBranch.tsx1 match
43
44try {
45const response = await fetch("/api/create-branch", {
46method: "POST",
47headers: {
OpenTownieChat.tsx1 match
26const [images, setImages] = useState<(string | null)[]>([]);
2728// Use custom hook to fetch project files
29const {
30projectFiles,
OpenTownieBranchControl.tsx22 matches
30const [showCreateBranch, setShowCreateBranch] = useState<boolean>(false);
3132// Fetch branches when project changes
33useEffect(() => {
34if (!projectId) return;
3536const fetchBranches = async () => {
37setIsLoadingBranches(true);
38try {
39const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
40headers: {
41"Authorization": `Bearer ${bearerToken}`,
4445if (!response.ok) {
46throw new Error(`Failed to fetch branches: ${response.statusText}`);
47}
4849const data = await response.json();
50const fetchedBranches = data.branches || [];
51setBranches(fetchedBranches);
5253// Check if the stored branchId is valid for this project
54const storedBranchIsValid = fetchedBranches.some((branch: Branch) => branch.id === branchId);
5556// Only set a new branchId if there isn't a valid one already stored
57if (!storedBranchIsValid && fetchedBranches.length > 0) {
58// If branches are loaded and there's a "main" branch, select it by default
59const mainBranch = fetchedBranches.find((branch: Branch) => branch.name === "main");
60if (mainBranch) {
61setBranchId(mainBranch.id);
63} else {
64// Otherwise select the first branch
65setBranchId(fetchedBranches[0].id);
66setSelectedBranchName(fetchedBranches[0].name);
67}
68} else if (storedBranchIsValid) {
69// Set the selected branch name based on the stored branchId
70const selectedBranch = fetchedBranches.find((branch: Branch) => branch.id === branchId);
71if (selectedBranch) {
72setSelectedBranchName(selectedBranch.name);
74}
75} catch (error) {
76console.error("Error fetching branches:", error);
77} finally {
78setIsLoadingBranches(false);
80};
8182fetchBranches();
83}, [projectId, bearerToken, branchId, setBranchId]);
84105// Refresh the branches list
106if (projectId) {
107const fetchBranches = async () => {
108try {
109const response = await fetch(`/api/project-branches?projectId=${projectId}`, {
110headers: {
111"Authorization": `Bearer ${bearerToken}`,
114115if (!response.ok) {
116throw new Error(`Failed to fetch branches: ${response.statusText}`);
117}
118119const data = await response.json();
120const fetchedBranches = data.branches || [];
121setBranches(fetchedBranches);
122123// Update the selected branch name
124const selectedBranch = fetchedBranches.find((branch: Branch) => branch.id === newBranchId);
125if (selectedBranch) {
126setSelectedBranchName(selectedBranch.name);
127}
128} catch (error) {
129console.error("Error fetching branches:", error);
130}
131};
132133fetchBranches();
134}
135};