10 const [aiLoading, setAiLoading] = useState(false);
11
12 // Fetch todos from API
13 const fetchTodos = async () => {
14 try {
15 const response = await fetch("/api/todos");
16 if (response.ok) {
17 const data = await response.json();
19 }
20 } catch (error) {
21 console.error("Error fetching todos:", error);
22 } finally {
23 setLoading(false);
28 const addTodo = async (title: string, description: string, priority: number) => {
29 try {
30 const response = await fetch("/api/todos", {
31 method: "POST",
32 headers: { "Content-Type": "application/json" },
46 const updateTodo = async (id: number, updates: Partial<Todo>) => {
47 try {
48 const response = await fetch(`/api/todos/${id}`, {
49 method: "PUT",
50 headers: { "Content-Type": "application/json" },
64 const deleteTodo = async (id: number) => {
65 try {
66 const response = await fetch(`/api/todos/${id}`, {
67 method: "DELETE",
68 });
80 setAiLoading(true);
81 try {
82 const response = await fetch("/api/ai/prioritize", {
83 method: "POST",
84 headers: { "Content-Type": "application/json" },
87 if (response.ok) {
88 // Refresh todos to get updated AI priorities
89 await fetchTodos();
90 }
91 } catch (error) {
97
98 useEffect(() => {
99 fetchTodos();
100 }, []);
101
17 return c.json(todoList);
18 } catch (error) {
19 console.error("Error fetching todos:", error);
20 return c.json({ error: "Failed to fetch todos" }, 500);
21 }
22});
37 return c.json(todo);
38 } catch (error) {
39 console.error("Error fetching todo:", error);
40 return c.json({ error: "Failed to fetch todo" }, 500);
41 }
42});
178
179// This is the entry point for HTTP vals
180export default app.fetch;
226 const data = Object.fromEntries(formData);
227
228 const response = await fetch('/api/contact', {
229 method: 'POST',
230 headers: {
250 async function loadSessions() {
251 try {
252 const response = await fetch('/api/sessions');
253 if (response.ok) {
254 sessions = await response.json();
298 async function loadSession(sessionId) {
299 try {
300 const response = await fetch(`/api/sessions/${sessionId}`);
301 if (response.ok) {
302 const data = await response.json();
344 if (!currentSession) {
345 try {
346 const response = await fetch('/api/sessions', {
347 method: 'POST',
348 headers: { 'Content-Type': 'application/json' },
371 try {
372 // Send message to API
373 const response = await fetch(`/api/sessions/${currentSession.id}/messages`, {
374 method: 'POST',
375 headers: { 'Content-Type': 'application/json' },
27});
28
29export default app.fetch;
11 return c.json(todoList);
12 } catch (error) {
13 console.error("Error fetching todos:", error);
14 return c.json({ error: "Failed to fetch todos" }, 500);
15 }
16});
52});
53
54const handler = app.fetch;
55export default lastlogin(handler);
24 }, []);
25
26 const fetchTodos = async () => {
27 if (!user) return;
28
29 setLoading(true);
30 try {
31 const response = await fetch('/api/todos');
32 if (response.ok) {
33 const todosData = await response.json();
45
46 try {
47 const response = await fetch('/api/todos', {
48 method: 'POST',
49 headers: {
70
71 try {
72 const response = await fetch(`/api/todos/${id}`, {
73 method: 'PUT',
74 headers: {
97
98 try {
99 const response = await fetch(`/api/todos/${id}`, {
100 method: 'DELETE',
101 });
169 onUpdate={updateTodo}
170 onDelete={deleteTodo}
171 onRefresh={fetchTodos}
172 />
173 </main>
228 };
229
230 // Fetch crypto data for specific symbol
231 const fetchCryptoData = async (symbol: string = 'bitcoin') => {
232 try {
233 const coinId = symbol.toLowerCase() === 'btc' ? 'bitcoin' :
242 symbol.toLowerCase() === 'avax' ? 'avalanche-2' : 'bitcoin';
243
244 const response = await fetch(`https://api.coingecko.com/api/v3/coins/${coinId}`);
245 const data = await response.json();
246
255 });
256 } catch (error) {
257 console.error('Price fetch error:', error);
258 }
259 };
261 // Real-time price tracking
262 useEffect(() => {
263 fetchCryptoData(currentSymbol);
264 const interval = setInterval(() => fetchCryptoData(currentSymbol), 10000);
265 return () => clearInterval(interval);
266 }, [currentSymbol]);
276 if (detectedSymbol && detectedSymbol !== currentSymbol) {
277 setCurrentSymbol(detectedSymbol);
278 await fetchCryptoData(detectedSymbol);
279 }
280
292
293 try {
294 const response = await fetch('/ai-analysis', {
295 method: 'POST',
296 headers: { 'Content-Type': 'application/json' },