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};
OpenTownieapi.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,
blob_adminmain.tsx1 match
195});
196197export default lastlogin((request: Request) => app.fetch(request));
blob_adminapp.tsx22 matches
231const [isDragging, setIsDragging] = useState(false);
232233const fetchBlobs = useCallback(async () => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
239} catch (error) {
240console.error("Error fetching blobs:", error);
241} finally {
242setLoading(false);
245246useEffect(() => {
247fetchBlobs();
248}, [fetchBlobs]);
249250const handleSearch = (e) => {
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
266setEditContent(content);
267} catch (error) {
268console.error("Error fetching blob content:", error);
269} finally {
270setBlobContentLoading(false);
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
312}
313}
314fetchBlobs();
315};
316326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
Jobs_aboard2main.tsx3 matches
99// Load existing jobs from server
100useEffect(() => {
101async function fetchJobs() {
102try {
103const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
121setJobs(result.rows);
122} catch (error) {
123console.error("Error fetching jobs:", error);
124}
125}
126127fetchJobs();
128}, []);
129
pondiversemain2 matches
1import addCreation from "./addCreation";
2import fetchCreations from "./fetchCreations";
3import getCreationImage from "./getCreationImage";
4import updateTable from "./updateTable";
13return getCreationImage(req);
14if (req.method == "GET" && url.pathname == "/creations")
15return fetchCreations(req);
16if (req.method == "POST" && url.pathname == "/updateTable")
17return updateTable(req);
3export default async function(interval: Interval) {
4// Use open-meteo for free weather API
5const response = await fetch(
6"https://api.open-meteo.com/v1/forecast?latitude=-1.2921&longitude=36.8219¤t_weather=true&temperature_unit=celsius&windspeed_unit=km/h&precipitation_unit=millimeters&timezone=Africa/Nairobi",
7);
scintillatingLimeParakeetmain.tsx6 matches
2122useEffect(() => {
23async function fetchFacts() {
24const response = await fetch("/api/facts");
25const data = await response.json();
26setFacts(data);
27}
28fetchFacts();
29}, []);
3031useEffect(() => {
32async function fetchDailyFact() {
33const response = await fetch("/api/daily-fact");
34const data = await response.json();
35setDailyFact(data);
36}
37fetchDailyFact();
38}, []);
39
trustingYellowChickadeemain.tsx6 matches
2122useEffect(() => {
23async function fetchFacts() {
24const response = await fetch("/api/facts");
25const data = await response.json();
26setFacts(data);
27}
28fetchFacts();
29}, []);
3031useEffect(() => {
32async function fetchDailyFact() {
33const response = await fetch("/api/daily-fact");
34const data = await response.json();
35setDailyFact(data);
36}
37fetchDailyFact();
38}, []);
39
templateTwitterAlertmain.tsx1 match
19: Math.floor((Date.now() - 2 * 24 * 60 * 60 * 1000) / 1000);
2021// Fetch and log tweets
22const response = await socialDataSearch(`${query} since_time:${timeFrame}`);
23console.log("Response from socialDataSearch:", response);