diff --git a/src/composables/useWishlistStore.ts b/src/composables/useWishlistStore.ts index f4eb658..2ef06c7 100644 --- a/src/composables/useWishlistStore.ts +++ b/src/composables/useWishlistStore.ts @@ -4,12 +4,12 @@ import { AxiosError } from 'axios' import { ref } from 'vue' const { client } = useAxios() -const list = ref(null) +const state = ref(null) const fetch = async (slugText: string): Promise => { try { const { data } = await client.get(`/wishlist/${slugText}`) - list.value = data + state.value = data } catch (e: any) { if (e.isAxiosError && !(e.ignore)) { throw e @@ -18,12 +18,13 @@ const fetch = async (slugText: string): Promise => { } const itemBought = async (item: WishlistItem): Promise => { - await client.post(`/wishlist/${item.wishlistId}/item/${item.id}/bought`, item) + await client.post(`/wishlist/${item.wishlistId}/item/${item.id}/bought`) + item.bought = true } export const useWishlistStore = () => { return { - list, + state, fetch, itemBought, } diff --git a/src/composables/useWishlistsStore.ts b/src/composables/useWishlistsStore.ts index 9ef34c6..5475f68 100644 --- a/src/composables/useWishlistsStore.ts +++ b/src/composables/useWishlistsStore.ts @@ -1,19 +1,19 @@ import useAxios from '@/composables/useAxios' import { Wishlist } from '@/types' -import { ref } from 'vue' +import { readonly, ref } from 'vue' const { client } = useAxios() const prefix = '/wishlist' -const refState = ref([]) +const state = ref([]) export const fetch = async (): Promise => { const { data } = await client.get(prefix) - refState.value = data + state.value = data } export const useWishlistsStore = () => { return { - lists: refState, + state: readonly(state), fetch, } } diff --git a/src/types.ts b/src/types.ts index 7b0df49..3742140 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,5 +1,5 @@ export interface WishlistItem { - id: string + id: number title: string url: string imageSrc: string diff --git a/src/views/DetailView.vue b/src/views/DetailView.vue index 50c777b..53bfc9a 100644 --- a/src/views/DetailView.vue +++ b/src/views/DetailView.vue @@ -13,11 +13,11 @@ const modal = useModal() const { t } = useI18n() -const { list, fetch, itemBought } = useWishlistStore() +const { state, fetch, itemBought } = useWishlistStore() await fetch(route.params.slug as string) const notBoughtItems = computed(() => { - return list.value?.items?.filter( + return state.value?.items?.filter( (item: WishlistItemType) => item.bought === false ) }) @@ -30,24 +30,23 @@ const bought = async (item: WishlistItemType): Promise => { t('pages.detail-view.confirmation-modal.body.text') ) if (confirmed) { - item.bought = true itemBought(item) } }