fc3f: artistDirectory Pinia store — cursor scroll + q + platform filters
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { ref, computed } from 'vue'
|
||||||
|
import { useApi } from '../composables/useApi.js'
|
||||||
|
|
||||||
|
const PAGE = 60
|
||||||
|
|
||||||
|
export const useArtistDirectoryStore = defineStore('artistDirectory', () => {
|
||||||
|
const api = useApi()
|
||||||
|
const cards = ref([])
|
||||||
|
const nextCursor = ref(null)
|
||||||
|
const loading = ref(false)
|
||||||
|
const error = ref(null)
|
||||||
|
const q = ref('')
|
||||||
|
const platform = ref(null)
|
||||||
|
let started = false
|
||||||
|
|
||||||
|
async function loadMore() {
|
||||||
|
if (loading.value) return
|
||||||
|
if (started && nextCursor.value === null) return
|
||||||
|
loading.value = true
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
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 })
|
||||||
|
cards.value.push(...body.cards)
|
||||||
|
nextCursor.value = body.next_cursor
|
||||||
|
started = true
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e.message
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reset() {
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user