29 lines
771 B
TypeScript
29 lines
771 B
TypeScript
import { create } from 'zustand'
|
|
import axios from 'axios'
|
|
import useAuthStore from './useAuthStore'
|
|
|
|
type SubState = {
|
|
subscriptions: { [key: number]: Subscription }
|
|
fetch: () => Promise<void>
|
|
}
|
|
|
|
export default create<SubState>(set => ({
|
|
subscriptions: {},
|
|
fetch: async () => {
|
|
const credential = useAuthStore.getState().credential
|
|
if (!credential) return
|
|
try {
|
|
const res = await axios.get('https://api.feedbin.com/v2/subscriptions.json', { auth: credential })
|
|
let subs: { [key: number]: Subscription } = {}
|
|
for (let i in res.data) {
|
|
subs[res.data[i].feed_id] = res.data[i]
|
|
}
|
|
set({ subscriptions: subs })
|
|
// console.log(subs)
|
|
} catch(e) {
|
|
console.log("`fetch` (useSubscription) has encounted an error")
|
|
console.log(e)
|
|
}
|
|
}
|
|
}))
|