feat(fc2c-i): pinia stores for showcase, tag directory, artist

This commit is contained in:
2026-05-15 21:12:19 -04:00
parent d166871be8
commit 861e8baeb8
3 changed files with 165 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
import { useApi } from '../composables/useApi.js'
const PAGE = 60
export const useShowcaseStore = defineStore('showcase', () => {
const api = useApi()
const images = ref([])
const loading = ref(false)
const error = ref(null)
const exhausted = ref(false)
const seen = new Set()
async function fetchPage() {
if (loading.value) return
loading.value = true
error.value = null
try {
const body = await api.get('/api/showcase', { params: { limit: PAGE } })
const fresh = body.images.filter(i => !seen.has(i.id))
if (fresh.length === 0) { exhausted.value = true; return }
for (const i of fresh) seen.add(i.id)
images.value.push(...fresh)
} catch (e) {
error.value = e.message
} finally {
loading.value = false
}
}
async function shuffle() {
images.value = []
seen.clear()
exhausted.value = false
await fetchPage()
}
const hasMore = computed(() => !exhausted.value)
const isEmpty = computed(
() => !loading.value && images.value.length === 0 && error.value === null
)
return { images, loading, error, hasMore, isEmpty, fetchPage, shuffle }
})