TownieCreditBalance.tsx5 matches
7const [loading, setLoading] = useState(true);
89const fetchBalance = async () => {
10try {
11const response = await fetch("/api/credit-balance");
12if (response.ok) {
13const data = await response.json();
15setBalance(data.balance);
16} else {
17console.error("Failed to fetch balance");
18}
19} catch (err) {
20console.error("Error fetching balance:", err);
21} finally {
22setLoading(false);
2526useEffect(() => {
27fetchBalance();
28}, []);
29
TownieChatRouteSingleColumn.tsx13 matches
51files={project.data?.files}
52branchId={branchId}
53refetch={project.refetch}
54/>
55</ProjectContext.Provider>
61files,
62branchId,
63refetch,
64}: {
65project: any;
66files: any[];
67branchId: string;
68refetch: () => void;
69}) {
70const [images, setImages] = useState<(string|null)[]>([]);
71const [selectedFiles, setSelectedFiles] = useState<string[]>([]);
72const { audio, user } = useContext(AppContext);
73const { balance, loading: balanceLoading, refetch: refetchBalance } = useCreditBalance();
7475const {
94useLoadingFavicon(running);
9596// Track when requests end and refetch balance
97const prevRunning = useRef(running);
98useEffect(() => {
99// If running changed from true to false, request just ended
100if (prevRunning.current === true && running === false) {
101refetchBalance();
102}
103prevRunning.current = running;
104}, [running, refetchBalance]);
105106// Auto-poll balance every 4 seconds when credits are insufficient
110if (hasInsufficientCredits) {
111const intervalId = setInterval(() => {
112refetchBalance();
113}, 4000); // 4 seconds
114
115return () => clearInterval(intervalId);
116}
117}, [balanceLoading, balance, refetchBalance]);
118119useEffect(() => {
120if (!messages?.length) return;
121let last = messages.at(-1);
122if (shouldRefetch(last)) {
123refetch();
124}
125}, [messages]);
196<button
197onClick={() => {
198refetchBalance();
199}}
200className="icon-button"
227}
228229function shouldRefetch (message) {
230for (let i = 0; i < message?.parts?.length; i++) {
231let part = message.parts[i];
TownieBranchSelect.tsx1 match
32return;
33}
34branches.refetch();
35if (res?.branch?.id) {
36navigate(`/chat/${projectId}/branch/${res.branch.id}`);
vtEditorFilesAGENTS.md3 matches
239
240// Inject data to avoid extra round-trips
241const initialData = await fetchInitialData();
242const dataScript = `<script>
243window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
2862875. **API Design:**
288- `fetch` handler is the entry point for HTTP vals
289- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290291
untitled-8651main.ts1 match
30});
3132export default app.fetch;
19const now = Date.now();
20if (!cached.accessToken || now >= cached.expiresAt) {
21const tokenResp = await fetch("https://accounts.spotify.com/api/token", {
22method: "POST",
23headers: {
4950while (nextUrl) {
51const resp = await fetch(nextUrl, {
52headers: { Authorization: `Bearer ${accessToken}` },
53});
54if (!resp.ok) {
55const text = await resp.text();
56return new Response("Failed to fetch playlists: " + text, {
57status: 500,
58});
untitled-7644new-file-7315.ts2 matches
1export default async function (interval: Interval) {
2const f = await fetch("https://sih-2025-demo.onrender.com/");
3const s = await f.text();
4console.log(s);
5const r = await fetch("https://sih-2025-demo.onrender.com/");
6const p = await r.text();
7console.log(p);
HTTP-Statusmain.ts1 match
13return new Response(`${status}`, { status });
14});
15export default app.fetch;
4647**Content-Type Support**:
48- `application/json` - Standard fetch requests
49- `text/plain` - sendBeacon requests (automatically parsed as JSON)
50197// 500 - Server Error
198{
199error: "Failed to fetch page data",
200details: "Notion API error message"
201}
1920### `useGlimpseData.ts`
21Manages glimpse data fetching and state.
2223**Parameters:**
24- `glimpseId` - ID of the glimpse to fetch
25- `initialData` - Optional initial data to avoid refetching
2627**Returns:** `UseGlimpseDataReturn`
29- `loading` - Loading state
30- `error` - Error state
31- `refetch` - Function to manually refetch data
3233**Usage:**
34```typescript
35const { data, loading, error, refetch } = useGlimpseData(glimpseId, initialData);
36```
3738### `useAgentData.ts`
39Manages agent data fetching with automatic polling.
4041**Parameters:**
68**Session Tracking:**
69- Uses `sendBeacon` API for reliable session ending during page unload
70- Falls back to synchronous fetch if sendBeacon fails
71- Handles both normal component unmount and browser tab closure
72