-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathhome.ts
More file actions
38 lines (35 loc) · 1010 Bytes
/
Copy pathhome.ts
File metadata and controls
38 lines (35 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
export const useHomeStore = defineStore('home', () => {
const pixivClient = usePixivClientStore().client
const randomBg = ref<ArtworkInfo | null>(null)
const discoveryList = ref<ArtworkInfo[]>([])
const loadingDiscovery = ref(false)
async function fetchRandomBg(): Promise<void> {
try {
const illusts = await pixivClient.getDiscovery({ mode: 'safe', max: 1 })
if (illusts.length) {
randomBg.value = illusts[0]!
}
} catch (err) {
console.error(err)
}
}
async function fetchDiscovery(): Promise<void> {
if (loadingDiscovery.value) return
try {
loadingDiscovery.value = true
const illusts = await pixivClient.getDiscovery({ mode: 'all', max: 8 })
discoveryList.value = illusts
} catch (err) {
console.error('Failed to fetch discovery', err)
} finally {
loadingDiscovery.value = false
}
}
return {
randomBg,
discoveryList,
loadingDiscovery,
fetchRandomBg,
fetchDiscovery,
}
})