43
44try {
45const response = await fetch("/api/create-branch", {
46method: "POST",
47headers: {
OpenTownieNormalBranchControl.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};
cerebras_coderindex1 match
5async function servePublicFile(path: string): Promise<Response> {
6const url = new URL("./public/" + path, import.meta.url);
7const text = await (await fetch(url, {
8headers: {
9"User-Agent": "", // to transpile TS to JS
cerebras_coderindex1 match
181182try {
183const response = await fetch("/", {
184method: "POST",
185body: JSON.stringify({
MiniAppStarterindex.ts2 matches
47});
4849// HTTP vals expect an exported "fetch handler"
50// This is how you "run the server" in Val Town with Hono
51export default app.fetch;
MiniAppStarterfarcaster.ts1 match
8485async function sendFarcasterNotification(payload: any) {
86return await fetch("https://api.warpcast.com/v1/frame-notifications", {
87method: "POST",
88headers: { "Content-Type": "application/json" },
openTownieMadeThis1index.js6 matches
74
75try {
76const response = await fetch('/api/hotels');
77const hotels = await response.json();
78
90alert('Hotel search results would display here in a real implementation');
91} catch (error) {
92console.error('Error fetching hotels:', error);
93}
94});
102getOfferDetailsBtn.addEventListener('click', async () => {
103try {
104const response = await fetch('/api/offers');
105const offers = await response.json();
106const mainOffer = offers[0]; // Get the first offer (Anniversary offer)
108alert(`Offer Details: ${mainOffer.title}\n\n${mainOffer.details}`);
109} catch (error) {
110console.error('Error fetching offer details:', error);
111}
112});
114viewAllOffersBtn.addEventListener('click', async () => {
115try {
116const response = await fetch('/api/offers');
117const offers = await response.json();
118
120alert(`All Available Offers:\n\n${offersList}`);
121} catch (error) {
122console.error('Error fetching all offers:', error);
123}
124});
MiniAppStarterWeather4 matches
910useEffect(() => {
11async function fetchWeather() {
12try {
13const response = await fetch(
14`https://api.open-meteo.com/v1/forecast?latitude=${location.latitude}&longitude=${location.longitude}¤t_weather=true&hourly=temperature_2m,relativehumidity_2m,windspeed_10m`,
15);
17setWeatherData(data);
18} catch (err) {
19setError("Could not fetch weather data");
20}
21}
2223fetchWeather();
24}, [location]);
25
MiniAppStarterindex.ts2 matches
47});
4849// HTTP vals expect an exported "fetch handler"
50// This is how you "run the server" in Val Town with Hono
51export default app.fetch;
MiniAppStarterfarcaster.ts1 match
8485async function sendFarcasterNotification(payload: any) {
86return await fetch("https://api.warpcast.com/v1/frame-notifications", {
87method: "POST",
88headers: { "Content-Type": "application/json" },