diff --git a/frontend/src/pages/Analysis.jsx b/frontend/src/pages/Analysis.jsx index 7b4e5c5..3838f06 100644 --- a/frontend/src/pages/Analysis.jsx +++ b/frontend/src/pages/Analysis.jsx @@ -117,7 +117,7 @@ export default function Analysis() { const loadAll = async () => { const [p, i] = await Promise.all([ - fetch('/api/prompts').then(r=>r.json()), + api.listPrompts(), api.listInsights() ]) setPrompts(Array.isArray(p)?p:[]) @@ -128,12 +128,7 @@ export default function Analysis() { const runPipeline = async () => { setPipelineLoading(true); setError(null); setNewResult(null) try { - const pid = localStorage.getItem('bodytrack_active_profile')||'' - const r = await fetch('/api/insights/pipeline', { - method:'POST', headers: pid ? {'X-Profile-Id':pid} : {} - }) - if (!r.ok) throw new Error(await r.text()) - const result = await r.json() + const result = await api.insightPipeline() setNewResult(result) await loadAll() setTab('run') @@ -145,12 +140,7 @@ export default function Analysis() { const runPrompt = async (slug) => { setLoading(slug); setError(null); setNewResult(null) try { - const pid = localStorage.getItem('bodytrack_active_profile')||'' - const r = await fetch(`/api/insights/run/${slug}`, { - method:'POST', headers: pid ? {'X-Profile-Id':pid} : {} - }) - if (!r.ok) throw new Error(await r.text()) - const result = await r.json() + const result = await api.runInsight(slug) setNewResult(result) // show immediately await loadAll() // refresh lists setTab('run') // stay on run tab to see result diff --git a/frontend/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx index c99db2e..d9d6c59 100644 --- a/frontend/src/pages/Dashboard.jsx +++ b/frontend/src/pages/Dashboard.jsx @@ -208,10 +208,7 @@ export default function Dashboard() { setPipelineLoading(true); setPipelineError(null) try { const pid = localStorage.getItem('mitai-jinkendo_active_profile')||'' - const r = await fetch('/api/insights/pipeline', { - method:'POST', headers: pid ? {'X-Profile-Id':pid} : {} - }) - if (!r.ok) throw new Error(await r.text()) + await api.insightPipeline() await load() } catch(e) { setPipelineError('Fehler: '+e.message) diff --git a/frontend/src/pages/History.jsx b/frontend/src/pages/History.jsx index 1a5263c..b3bfe98 100644 --- a/frontend/src/pages/History.jsx +++ b/frontend/src/pages/History.jsx @@ -924,7 +924,7 @@ export default function History() { setLoadingSlug(slug) try { const pid=localStorage.getItem('bodytrack_active_profile')||'' - const r=await fetch(`/api/insights/run/${slug}`,{method:'POST',headers:pid?{'X-Profile-Id':pid}:{}}) + const r=await api.runInsight(slug) if(!r.ok) throw new Error(await r.text()) const ins=await api.latestInsights() setInsights(Array.isArray(ins)?ins:[]) diff --git a/frontend/src/pages/NutritionPage.jsx b/frontend/src/pages/NutritionPage.jsx index 4e77674..04281c8 100644 --- a/frontend/src/pages/NutritionPage.jsx +++ b/frontend/src/pages/NutritionPage.jsx @@ -335,7 +335,7 @@ export default function NutritionPage() { const [corr, wkly, prof] = await Promise.all([ nutritionApi.nutritionCorrelations(), nutritionApi.nutritionWeekly(16), - fetch('/api/profile').then(r=>r.json()), + api.getActiveProfile(), ]) setCorr(Array.isArray(corr)?corr:[]) setWeekly(Array.isArray(wkly)?wkly:[]) diff --git a/frontend/src/utils/api.js b/frontend/src/utils/api.js index 976afa5..003f9e4 100644 --- a/frontend/src/utils/api.js +++ b/frontend/src/utils/api.js @@ -23,6 +23,7 @@ const jput=(d)=>({method:'PUT', headers:{'Content-Type':'application/json'},body export const api = { // Profiles + getActiveProfile: () => req('/profile'), listProfiles: () => req('/profiles'), createProfile: (d) => req('/profiles', json(d)), updateProfile: (id,d) => req(`/profiles/${id}`, jput(d)), @@ -82,6 +83,8 @@ export const api = { // Stats & AI getStats: () => req('/stats'), insightTrend: () => req('/insights/trend',{method:'POST'}), + listPrompts: () => req('/prompts'), + runInsight: (slug) => req(`/insights/run/${slug}`,{method:'POST'}), insightPipeline: () => req('/insights/pipeline',{method:'POST'}), listInsights: () => req('/insights'), latestInsights: () => req('/insights/latest'),