From cca575e4fefebc28fd4b3ce498862adc6cf66af6 Mon Sep 17 00:00:00 2001 From: Benny Samir Hierl Date: Sun, 13 Feb 2022 11:52:42 +0100 Subject: [PATCH] small changes Signed-off-by: Benny Samir Hierl --- src/composables/useWishlistStore.ts | 6 +++++- src/views/DetailView.vue | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/composables/useWishlistStore.ts b/src/composables/useWishlistStore.ts index f64d2a2..11e4920 100644 --- a/src/composables/useWishlistStore.ts +++ b/src/composables/useWishlistStore.ts @@ -3,12 +3,15 @@ import { Wishlist, WishlistItem } from '@/types' import { ref } from 'vue' const { client } = useAxios() -const state = ref(null) +//@ts-expect-error ... +const state = ref({}) +const isReady = ref(false) const fetch = async (slugText: string): Promise => { try { const { data } = await client.get(`/wishlist/${slugText}`) state.value = data + isReady.value = true } catch (e: any) { if (e.isAxiosError && !(e.ignore)) { throw e @@ -43,6 +46,7 @@ const itemBought = async (item: WishlistItem): Promise => { export const useWishlistStore = () => { return { state, + isReady, fetch, update, itemBought, diff --git a/src/views/DetailView.vue b/src/views/DetailView.vue index 92d539c..1afb058 100644 --- a/src/views/DetailView.vue +++ b/src/views/DetailView.vue @@ -3,7 +3,7 @@ import { useI18n } from 'vue-i18n' import { Wishlist, WishlistItem as WishlistItemType } from '@/types' import { computed } from 'vue' import { useRoute, useRouter } from 'vue-router' -import { useWishlistStore, useModal } from '@/composables' +import { useWishlistStore, useModal, useEditMode } from '@/composables' import WishlistItem from '@/components/WishlistItem.vue' import WishlistHeader from '@/components/WishlistHeader.vue' import { IconNoGift } from '../components/icons' @@ -11,14 +11,25 @@ import { IconNoGift } from '../components/icons' const route = useRoute() const router = useRouter() const modal = useModal() - +const { isActive: editModeIsActive } = useEditMode() const { t } = useI18n() -const { state, fetch, itemBought, update: updateWishlist } = useWishlistStore() +const { + state, + fetch, + isReady, + itemBought, + update: updateWishlist, +} = useWishlistStore() await fetch(route.params.slug as string) -const notBoughtItems = computed(() => { - return state.value?.items?.filter( +const filteredItems = computed(() => { + if (!state.value || !state.value.items) { + return [] + } else if (editModeIsActive.value) { + return state.value.items + } + return state.value.items.filter( (item: WishlistItemType) => item.bought === false ) }) @@ -42,14 +53,14 @@ const handleUpdateWishlist = async (values: Wishlist) => {