OpenTowniexCreateBranch.tsx1 match
43
44try {
45const response = await fetch("/api/create-branch", {
46method: "POST",
47headers: {
OpenTowniexChat.tsx1 match
28const [isDragging, setIsDragging] = useState(false);
2930// Use custom hook to fetch project files
31const {
32projectFiles,
OpenTowniexBranchControl.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};
OpenTowniexapi.ts3 matches
1// Fetch project files from the backend
2export async function fetchProjectFiles(
3{ bearerToken, projectId, branchId }: { bearerToken: string; projectId: string; branchId?: string },
4) {
9}
1011const response = await fetch(url.toString(), {
12headers: {
13"Authorization": "Bearer " + bearerToken,
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)));
OpenTownietext-editor.ts1 match
136let type_: "file" | "http" | "script";
137if (path.includes("backend/index.ts")) type_ = "http";
138if (file_text?.includes("export default app.fetch")) type_ = "http";
139if ([".ts", ".tsx", ".js", ".jsx"].some(ext => path.endsWith(ext))) {
140type_ = "script";
OpenTowniesystem_prompt.txt3 matches
233
234// Inject data to avoid extra round-trips
235const initialData = await fetchInitialData();
236const dataScript = `<script>
237window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
2802815. **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`
OpenTowniesend-message.ts3 matches
95}
9697// If there are selected files, fetch their content and add them to the messages
98if (selectedFiles && selectedFiles.length > 0) {
99const vt = new ValTown({ bearerToken });
115fileContents += `## File: ${filePath}\n\`\`\`\n${fileWithLinesNumbers(content)}\n\`\`\`\n\n`;
116} catch (error) {
117console.error(`Error fetching file ${filePath}:`, error);
118fileContents += `## File: ${filePath}\nError: Could not fetch file content\n\n`;
119}
120}
OpenTownieProjects.tsx1 match
1011async function loader({ bearerToken }: { bearerToken: string }) {
12const data = await (await fetch("/api/projects-loader", {
13headers: {
14"Authorization": "Bearer " + bearerToken,
OpenTownieproject-files.ts2 matches
30return c.json({ files: files.data });
31} catch (error) {
32console.error("Error fetching project files:", error);
33return Response.json({ error: "Failed to fetch project files" }, { status: 500 });
34}
35});