wishlist-app/src/composables/useWishlistsStore.ts
Benny Samir Hierl 17dce65127 remove await functions on pages
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
2022-02-02 21:37:08 +01:00

30 lines
652 B
TypeScript

import apiService from '@/services/apiService'
import { Wishlist } from '@/types'
import { ref } from 'vue'
const apiClient = apiService.getClient()
const prefix = '/wishlist'
const refState = ref<Wishlist[]>([])
const isLoading = ref(false)
const hasError = ref(false)
export const loadAll = async (): Promise<void> => {
isLoading.value = true
try {
const { data } = await apiClient.get(prefix)
refState.value = data
} catch (error: any) {
hasError.value = true
} finally {
isLoading.value = false
}
}
export const useWishlistsStore = () => {
loadAll()
return {
lists: refState,
hasError,
isLoading,
}
}