diff --git a/frontend/src/pages/Timeline.tsx b/frontend/src/pages/Timeline.tsx index c1ce77d..07d2aef 100644 --- a/frontend/src/pages/Timeline.tsx +++ b/frontend/src/pages/Timeline.tsx @@ -1,8 +1,9 @@ import { useState, useEffect, useCallback } from 'react' import { ChevronLeft, ChevronRight, Sparkles, Calendar, Clock, Layers, RefreshCw } from 'lucide-react' +import axios from 'axios' import clsx from 'clsx' -const API = 'http://localhost:8000' +const api = axios.create({ baseURL: '/api' }) interface MarketEvent { id: number @@ -231,42 +232,42 @@ export default function Timeline() { const fetchDay = useCallback(async (d: string) => { setLoading(true) try { - const res = await fetch(`${API}/api/timeline/day/${d}`) - if (res.ok) setCtx(await res.json()) - } finally { + const res = await api.get(`/timeline/day/${d}`) + setCtx(res.data) + } catch { /* ignore */ } finally { setLoading(false) } }, []) const fetchEvents = useCallback(async () => { - const res = await fetch(`${API}/api/timeline/events`) - if (res.ok) setAllEvents(await res.json()) + try { + const res = await api.get('/timeline/events') + setAllEvents(res.data) + } catch { /* ignore */ } }, []) const bootstrap = useCallback(async () => { - const res = await fetch(`${API}/api/timeline/bootstrap`, { method: 'POST' }) - if (res.ok) { + try { + await api.post('/timeline/bootstrap') setBootstrapped(true) await fetchEvents() await fetchDay(refDate) - } + } catch { /* ignore */ } }, [refDate, fetchDay, fetchEvents]) const generateAI = useCallback(async () => { setGenerating(true) try { - const res = await fetch(`${API}/api/timeline/generate/${refDate}`, { method: 'POST' }) - if (res.ok) { - const data = await res.json() - setCtx(prev => prev ? { - ...prev, - long_commentary: data.long_commentary, - medium_commentary: data.medium_commentary, - short_commentary: data.short_commentary, - has_commentary: true, - } : prev) - } - } finally { + const res = await api.post(`/timeline/generate/${refDate}`) + const data = res.data + setCtx(prev => prev ? { + ...prev, + long_commentary: data.long_commentary, + medium_commentary: data.medium_commentary, + short_commentary: data.short_commentary, + has_commentary: true, + } : prev) + } catch { /* ignore */ } finally { setGenerating(false) } }, [refDate])