285});
286287export default api.fetch;
54});
5556export default app.fetch;
57
32// Initialize with demo data
33useEffect(() => {
34// Simulate API fetch
35setLoading(true);
36setTimeout(() => {
250// View user profile
251const viewProfile = (userId) => {
252// In a real app, fetch the user profile
253// For demo, use current user's profile if it's their profile
254if (userId === currentUser.id) {
dailySlackRoundupmain.tsx2 matches
1import { fetch } from "https://esm.town/v/std/fetch";
2import { getDayName } from "https://esm.town/v/stevekrouse/getDayName?v=2";
3import process from "node:process";
45export const dailySlackRoundup = (async () => {
6const res = await fetch(process.env.BRAINBOT_WEBHOOK_URL, {
7method: "POST",
8body: JSON.stringify({
tangledRSSmain.tsx7 matches
9try {
10// Resolve handle to DID
11const handleResolveResponse = await fetch(
12`https://bsky.social/xrpc/com.atproto.identity.resolveHandle?handle=${handle}`,
13);
14const { did } = await handleResolveResponse.json();
1516// Fetch DID document
17const didDocResponse = await fetch(`https://plc.directory/${did}`);
18const didDoc = await didDocResponse.json();
19const serviceEndpoint = didDoc.service[0].serviceEndpoint;
2021// Fetch all records
22const allRecords = await fetchAllRecords(serviceEndpoint, did);
2324// Generate RSS feed
35}
3637async function fetchAllRecords(serviceEndpoint: string, did: string): Promise<any[]> {
38const allRecords: any[] = [];
39let cursor = "";
46if (cursor) url.searchParams.set("cursor", cursor);
4748const response = await fetch(url.toString());
49const data = await response.json();
50
38.where(eq(usersTable.id, id));
3940// Fetch and return the updated user
41return getUserById(id);
42}
314function App() {
315const [songs, setSongs] = React.useState<Song[]>([]);
316const [sortBy, setSortBy] = React.useState<"date" | "title">("date"); // Default sort should match initial fetch if possible
317const [selectedTag, setSelectedTag] = React.useState<string>("");
318const [isLoading, setIsLoading] = React.useState(true);
321322// Using useCallback to stabilize the function reference
323const fetchSongs = React.useCallback(async () => {
324setError(""); // Clear previous errors before fetching
325// Keep isLoading true if it was already true (initial load)
326// Don't set it to true on subsequent fetches unless desired (e.g., manual refresh button)
327try {
328const response = await fetch("/api/songs");
329if (!response.ok) {
330const errorText = await response.text(); // Try to get error text
331throw new Error(`Failed to fetch songs: ${response.status} ${errorText || response.statusText}`);
332}
333const data = await response.json();
339setSongs(data as Song[]);
340} catch (err) {
341console.error("Fetch error:", err);
342setError(`Failed to load songs. ${err.message || "Please try again later."}`);
343// Consider clearing songs or leaving stale data based on desired UX
344// setSongs([]); // Optional: Clear songs on error
345} finally {
346setIsLoading(false); // Always set loading to false after fetch attempt
347}
348}, []); // Empty dependency array: function created once
350React.useEffect(() => {
351setIsLoading(true); // Set loading true when the component mounts
352fetchSongs();
353}, [fetchSongs]); // Run effect when fetchSongs changes (which is only on mount)
354355const handleAdd = async (songData: Omit<Song, "id" | "created_at">) => {
363};
364try {
365const response = await fetch("/api/songs", {
366method: "POST",
367headers: { "Content-Type": "application/json" },
372throw new Error(`Failed to add song: ${response.status} ${errorText || response.statusText}`);
373}
374await fetchSongs(); // Refetch to update the list
375} catch (err) {
376console.error("Add error:", err);
400401try {
402const response = await fetch(`/api/songs/${song.id}`, {
403method: "PUT",
404headers: { "Content-Type": "application/json" },
410throw new Error(`Failed to update song: ${response.status} ${errorText || response.statusText}`);
411}
412// Optional: Refetch if server might modify data (e.g., updated_at, though not used here)
413// await fetchSongs();
414// If optimistic update is enough, no fetch needed here.
415} catch (err) {
416console.error("Edit error:", err);
428429try {
430const response = await fetch(`/api/songs/${id}`, {
431method: "DELETE",
432});
435throw new Error(`Failed to delete song: ${response.status} ${errorText || response.statusText}`);
436}
437// No fetch needed after successful delete with optimistic update
438} catch (err) {
439console.error("Delete error:", err);
464465// Sort (Client-side sorting is kept)
466// Note: The initial fetch order from the original server was `position, created_at DESC`.
467// Client-side sort overrides this. If you want initial load to match server,
468// set default `sortBy` state based on that, or remove client sort initially.
594{/* Songs Display Area */}
595<main className="songs-area">
596{isLoading && songs.length > 0 && ( // Show subtle loading indicator when refetching
597<div className="loading-inline">
598<span className="material-icons loading">sync</span> Refreshing...
305306useEffect(() => {
307fetchProducts();
308}, []);
309310async function fetchProducts() {
311const response = await fetch("/products");
312const data = await response.json();
313setProducts(data);
328if (pendingAction.type === "delete") {
329const productId = pendingAction.data as number;
330fetch(`/delete-product/${productId}`, { method: "DELETE" })
331.then(async (response) => {
332if (response.ok) {
333await fetchProducts();
334setView("home");
335alert("Product deleted successfully!");
338} else if (pendingAction.type === "add") {
339const product = pendingAction.data as Product;
340fetch("/add-product", {
341method: "POST",
342headers: { "Content-Type": "application/json" },
345if (response.ok) {
346alert("Product added successfully!");
347fetchProducts();
348setView("home");
349}
bskySoloLikesmain.tsx4 matches
12url.searchParams.append("cursor", cursor);
13}
14const response = await fetch(url.toString());
15if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
16return await response.json();
1819async function getLikes(uri: string): Promise<any> {
20const response = await fetch(`${BASE_URL}/app.bsky.feed.getLikes?uri=${uri}`);
21if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
22return await response.json();
3132if (!feed.cursor) {
33break; // No more posts to fetch
34}
3542}
4344// Trim excess posts if we fetched more than 500
45if (allPosts.length > 500) {
46allPosts.length = 500;
simpleLogoGeneratormain.tsx2 matches
119
120// Store SVG blob
121await fetch('https://api.val.town/v1/blobs', {
122method: 'POST',
123headers: {
133
134// Store metadata blob
135await fetch('https://api.val.town/v1/blobs', {
136method: 'POST',
137headers: {