e66987f092
Extracts gallery.js's hand-rolled inflightId pattern into a new useInflightToken composable; adopts in every store that previously had no guard against late-response overwrites or wrong-image URL interpolation. Two operator-impacting bugs the audit (workflow wf_bbe3fdb1-e62) flagged: - modal.removeTag rolled back the chip rail unconditionally even when only the secondary dismiss POST had failed — UI lied until refresh. And all tag-mutation URLs interpolated currentImageId AFTER an await, so a fast prev/next could route DELETE/POST to the wrong image. Both fixed: split try/catch (dismiss failure surfaces a warning, doesn't roll back the delete); imageId captured at call-time and used in URLs throughout. - suggestions.accept dereferenced currentImageId after the awaited POST /api/tags, so the subsequent /suggestions/accept could apply A's chosen tag to image B AND push it to B's allowlist. Fixed by capturing imageId at click-time + inflight guard on load(). Same shape across artist / downloads / artistDirectory / tagDirectory / posts stores: rapid filter/nav changes used to interleave responses (last-writer-wins). Now the late response is discarded and the most-recent request wins. Filter-change-during- search no longer drops the second fetch because the loading flag was still true from the first. gallery.js's inflightId removed in favor of the shared composable so the pattern stays consistent.
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import { useApi } from '../composables/useApi.js'
|
|
import { useAsyncAction } from '../composables/useAsyncAction.js'
|
|
import { useInflightToken } from '../composables/useInflightToken.js'
|
|
|
|
const PAGE = 60
|
|
|
|
export const useArtistDirectoryStore = defineStore('artistDirectory', () => {
|
|
const api = useApi()
|
|
const cards = ref([])
|
|
const nextCursor = ref(null)
|
|
const { loading, error, run } = useAsyncAction({ errorAs: 'message' })
|
|
const q = ref('')
|
|
const platform = ref(null)
|
|
let started = false
|
|
// Typed "alice" then "alice bob" used to drop the second fetch
|
|
// entirely (loading flag still true from the first), so the UI
|
|
// showed alice results while the input said "alice bob". Inflight
|
|
// token + reset() cancelling in-flight requests fixes both: the
|
|
// first response is discarded, the second is fetched. Audit 2026-06-02.
|
|
const inflight = useInflightToken()
|
|
|
|
async function loadMore() {
|
|
if (started && nextCursor.value === null) return
|
|
const t = inflight.claim()
|
|
await run(async () => {
|
|
const params = { limit: PAGE }
|
|
if (q.value) params.q = q.value
|
|
if (platform.value) params.platform = platform.value
|
|
if (nextCursor.value) params.cursor = nextCursor.value
|
|
const body = await api.get('/api/artists/directory', { params })
|
|
if (!t.isCurrent()) return
|
|
cards.value.push(...body.cards)
|
|
nextCursor.value = body.next_cursor
|
|
started = true
|
|
})
|
|
}
|
|
|
|
async function reset() {
|
|
inflight.cancel()
|
|
cards.value = []
|
|
nextCursor.value = null
|
|
started = false
|
|
await loadMore()
|
|
}
|
|
|
|
function setQuery(text) { q.value = text; reset() }
|
|
function setPlatform(p) { platform.value = p; reset() }
|
|
|
|
const hasMore = computed(() => !started || nextCursor.value !== null)
|
|
const isEmpty = computed(
|
|
() => !loading.value && cards.value.length === 0 && error.value === null
|
|
)
|
|
|
|
return {
|
|
cards, loading, error, q, platform, hasMore, isEmpty,
|
|
loadMore, reset, setQuery, setPlatform,
|
|
}
|
|
})
|