From f2f74efff1f4719154fc6cffe646cfe4e299651b Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Thu, 21 May 2026 22:14:53 -0400 Subject: [PATCH] =?UTF-8?q?fc3f:=20artistDirectory=20Pinia=20store=20?= =?UTF-8?q?=E2=80=94=20cursor=20scroll=20+=20q=20+=20platform=20filters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 (1M context) --- frontend/src/stores/artistDirectory.js | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 frontend/src/stores/artistDirectory.js diff --git a/frontend/src/stores/artistDirectory.js b/frontend/src/stores/artistDirectory.js new file mode 100644 index 0000000..7550c36 --- /dev/null +++ b/frontend/src/stores/artistDirectory.js @@ -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, + } +})