feat(fc2a): add useApi composable, import store, extend system store with stats
useApi centralizes fetch error handling — every API call throws ApiError on non-2xx with the parsed body attached, so components don't repeat the 'check response.ok' boilerplate. import store wraps import settings, batch status, task list (with cursor pagination), and the trigger/retry/clear admin actions. system store gains a refreshStats() that powers the Settings overview tab. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,30 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { useApi } from '../composables/useApi.js'
|
||||
|
||||
export const useSystemStore = defineStore('system', () => {
|
||||
const api = useApi()
|
||||
const healthy = ref(null) // null=unknown, true=ok, false=down
|
||||
const stats = ref(null)
|
||||
const statsLoading = ref(false)
|
||||
|
||||
async function refreshHealth() {
|
||||
try {
|
||||
const r = await fetch('/api/health')
|
||||
const body = await r.json()
|
||||
healthy.value = r.ok && body.status === 'ok'
|
||||
const body = await api.get('/api/health')
|
||||
healthy.value = body.status === 'ok'
|
||||
} catch {
|
||||
healthy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { healthy, refreshHealth }
|
||||
async function refreshStats() {
|
||||
statsLoading.value = true
|
||||
try {
|
||||
stats.value = await api.get('/api/system/stats')
|
||||
} finally {
|
||||
statsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { healthy, stats, statsLoading, refreshHealth, refreshStats }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user