a37dad33c7
New composables/useAsyncAction.js owns the loading/error/try-finally lifecycle. Migrated 11 stores: credentials, downloads, sources, posts (error=raw) + ml, artistDirectory, tagDirectory, showcase, suggestions, seriesReader, modal (error=message). The errorAs option preserves each store's existing error shape so store.error keeps the same type for components (~50 consumption sites unchanged). Stores whose catch also reset data (suggestions/seriesReader/modal) clear it upfront instead. Deliberately NOT migrated (special control flow, would change behavior): artist (conditional 404 catch + dual loading states), migration (rethrows), gallery (inflight-id stale-response guard), and the Shape-B no-catch / loaded-guard / keyed-cache stores. Net -77 lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
34 lines
914 B
JavaScript
34 lines
914 B
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref } from 'vue'
|
|
import { useApi } from '../composables/useApi.js'
|
|
import { useAsyncAction } from '../composables/useAsyncAction.js'
|
|
|
|
export const useMLStore = defineStore('ml', () => {
|
|
const api = useApi()
|
|
const settings = ref(null)
|
|
const { loading, error, run } = useAsyncAction({ errorAs: 'message' })
|
|
|
|
async function loadSettings() {
|
|
await run(async () => {
|
|
settings.value = await api.get('/api/ml/settings')
|
|
})
|
|
}
|
|
|
|
async function patchSettings(patch) {
|
|
settings.value = await api.patch('/api/ml/settings', { body: patch })
|
|
}
|
|
|
|
async function triggerBackfill() {
|
|
await api.post('/api/ml/backfill')
|
|
}
|
|
|
|
async function triggerRecomputeCentroids() {
|
|
await api.post('/api/ml/recompute-centroids')
|
|
}
|
|
|
|
return {
|
|
settings, loading, error,
|
|
loadSettings, patchSettings, triggerBackfill, triggerRecomputeCentroids
|
|
}
|
|
})
|