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,
ValTownForNotionhelpers.ts3 matches
28const origin = parsedUrl.origin;
2930// Fetch the HTML from the URL
31const response = await fetch(url);
32const html = await response.text();
336263// Verify the favicon exists
64const faviconResponse = await fetch(faviconUrl, { method: "HEAD" });
6566if (!faviconResponse.ok) {
jeevessendDailyBrief.ts1 match
135const lastSunday = today.startOf("week").minus({ days: 1 });
136137// Fetch relevant memories using the utility function
138const memories = await getRelevantMemories();
139
jeevesNotebookView.tsx12 matches
67const [currentPage, setCurrentPage] = useState(1);
6869const fetchMemories = useCallback(async () => {
70setLoading(true);
71setError(null);
72try {
73const response = await fetch(API_BASE);
74if (!response.ok) {
75throw new Error(`HTTP error! status: ${response.status}`);
78setMemories(data);
79} catch (e) {
80console.error("Failed to fetch memories:", e);
81setError(e.message || "Failed to fetch memories.");
82} finally {
83setLoading(false);
8687useEffect(() => {
88fetchMemories();
89}, [fetchMemories]);
9091const handleAddMemory = async (e: React.FormEvent) => {
100101try {
102const response = await fetch(API_BASE, {
103method: "POST",
104headers: { "Content-Type": "application/json" },
112setNewMemoryTags("");
113setShowAddForm(false);
114await fetchMemories();
115} catch (e) {
116console.error("Failed to add memory:", e);
123124try {
125const response = await fetch(`${API_BASE}/${id}`, {
126method: "DELETE",
127});
129throw new Error(`HTTP error! status: ${response.status}`);
130}
131await fetchMemories();
132} catch (e) {
133console.error("Failed to delete memory:", e);
155156try {
157const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158method: "PUT",
159headers: { "Content-Type": "application/json" },
164}
165setEditingMemory(null);
166await fetchMemories();
167} catch (e) {
168console.error("Failed to update memory:", e);
135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
jeeves.cursorrules5 matches
163```
1641655. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
166```ts
167const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
168```
169242243// Inject data to avoid extra round-trips
244const initialData = await fetchInitialData();
245const dataScript = `<script>
246window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
3003015. **API Design:**
302- `fetch` handler is the entry point for HTTP vals
303- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
304- Properly handle CORS if needed for external access
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);
stevensDemosendDailyBrief.ts1 match
300}
301302// Fetch relevant memories using the utility function
303const memories = await getRelevantMemories();
304
stevensDemogetCalendarEvents.ts13 matches
150
151try {
152const tokenResponse = await fetch("https://oauth2.googleapis.com/token", {
153method: "POST",
154headers: { "Content-Type": "application/x-www-form-urlencoded" },
168return tokenData.access_token;
169} catch (error) {
170console.error("OAuth Debug - Fetch Error:", error.message);
171throw error;
172}
181const accessToken = await getGoogleAccessToken();
182
183// Fetch the list of available calendars
184const calListUrl = "https://www.googleapis.com/calendar/v3/users/me/calendarList";
185const calListResponse = await fetch(calListUrl, {
186headers: {
187"Authorization": `Bearer ${accessToken}`
190
191if (!calListResponse.ok) {
192throw new Error(`Failed to fetch calendar list: ${await calListResponse.text()}`);
193}
194
210
211try {
212// Fetch events for this specific calendar
213const calendarEvents = await fetchCalendarEventsForCalendar(calendar.id, accessToken);
214console.log(`Found ${calendarEvents.length} events in calendar "${calendar.summary}"`);
215
223allEvents = allEvents.concat(calendarEvents);
224} catch (error) {
225console.error(`Error fetching events for calendar ${calendar.summary}:`, error);
226}
227}
273}
274275// Function to fetch events for a specific calendar
276async function fetchCalendarEventsForCalendar(calendarId: string, accessToken: string): Promise<CalendarEvent[]> {
277// Get events for the next 30 days
278const timeMin = new Date();
280timeMax.setDate(timeMax.getDate() + 30);
281
282console.log(`Fetching events for calendar ${calendarId} from ${timeMin.toISOString()} to ${timeMax.toISOString()}`);
283
284const url = `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events?` +
291});
292
293const response = await fetch(url, {
294headers: {
295"Authorization": `Bearer ${accessToken}`
299if (!response.ok) {
300const error = await response.text();
301throw new Error(`Failed to fetch calendar events: ${error}`);
302}
303