50 files={project.data?.files}
51 branchId={branchId}
52 refetch={project.refetch}
53 />
54 </ProjectContext>
60 files,
61 branchId,
62 refetch,
63}: {
64 project: any;
65 files: any[];
66 branchId: string;
67 refetch: () => void;
68}) {
69 const [images, setImages] = useState<(string|null)[]>([]);
94 if (!messages?.length) return;
95 let last = messages.at(-1);
96 if (shouldRefetch(last)) {
97 refetch();
98 }
99 }, [messages]);
177}
178
179function shouldRefetch (message) {
180 for (let i = 0; i < message?.parts?.length; i++) {
181 let part = message.parts[i];
32 return;
33 }
34 branches.refetch();
35 if (res?.branch?.id) {
36 navigate(`/chat/${projectId}/branch/${res.branch.id}`);
29 .toString("base64");
30
31 const response = await fetch(`https://api.switch-bot.com/${path}`, {
32 headers: {
33 "Authorization": token,
156});
157
158export default app.fetch;
12
13The routes are defined in `routes` and can include data loading and actions.
14The `/about` route includes a loader that fetches data from the `/api` route, which returns a JSON response.
15The About page uses the `useLoaderData` hook to render the data from the loader in the page.
16
46
47 try {
48 const response = await fetch('/api/login/', {
49 method: 'POST',
50 headers: { 'Content-Type': 'application/json' },
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
2import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
3
4async function alphaVantage(symbol: string) {
5 let data = await fetchJSON(
6 `https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=${symbol}&apikey=${Deno.env.get("alphaVantage")}`,
7 );
10
11export function getStockData(symbol: string) {
12 return fetchJSON(
13 `${thisWebURL()}?symbol=${symbol}`,
14 );
44});
45
46export default app.fetch;
46
47// Export the Hono app for HTTP val
48export default app.fetch;
54};
55
56// Fetch and display messages
57const fetchMessages = async () => {
58 try {
59 const response = await fetch('/api/messages');
60 if (!response.ok) {
61 throw new Error('Failed to fetch messages');
62 }
63
72 });
73 } catch (error) {
74 console.error('Error fetching messages:', error);
75 }
76};
94
95 try {
96 const response = await fetch('/api/messages', {
97 method: 'POST',
98 headers: {
109 messageInput.value = '';
110
111 // Fetch updated messages
112 await fetchMessages();
113
114 // Save username
121// Set up polling for new messages
122const setupPolling = () => {
123 // Fetch messages immediately
124 fetchMessages();
125
126 // Then fetch every 3 seconds
127 setInterval(fetchMessages, 3000);
128};
129
255
256// Export the app
257export default app.fetch;