mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-04-19 15:27:41 +00:00
small changes
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
30b8dd6433
commit
a45ab85e71
5 changed files with 20 additions and 20 deletions
|
@ -4,12 +4,12 @@ import { AxiosError } from 'axios'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
const { client } = useAxios()
|
const { client } = useAxios()
|
||||||
|
|
||||||
const list = ref<Wishlist | null>(null)
|
const state = ref<Wishlist | null>(null)
|
||||||
|
|
||||||
const fetch = async (slugText: string): Promise<void> => {
|
const fetch = async (slugText: string): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { data } = await client.get(`/wishlist/${slugText}`)
|
const { data } = await client.get(`/wishlist/${slugText}`)
|
||||||
list.value = data
|
state.value = data
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (e.isAxiosError && !(<AxiosError>e.ignore)) {
|
if (e.isAxiosError && !(<AxiosError>e.ignore)) {
|
||||||
throw e
|
throw e
|
||||||
|
@ -18,12 +18,13 @@ const fetch = async (slugText: string): Promise<void> => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const itemBought = async (item: WishlistItem): Promise<void> => {
|
const itemBought = async (item: WishlistItem): Promise<void> => {
|
||||||
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 = () => {
|
export const useWishlistStore = () => {
|
||||||
return {
|
return {
|
||||||
list,
|
state,
|
||||||
fetch,
|
fetch,
|
||||||
itemBought,
|
itemBought,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import useAxios from '@/composables/useAxios'
|
import useAxios from '@/composables/useAxios'
|
||||||
import { Wishlist } from '@/types'
|
import { Wishlist } from '@/types'
|
||||||
import { ref } from 'vue'
|
import { readonly, ref } from 'vue'
|
||||||
const { client } = useAxios()
|
const { client } = useAxios()
|
||||||
const prefix = '/wishlist'
|
const prefix = '/wishlist'
|
||||||
|
|
||||||
const refState = ref<Wishlist[]>([])
|
const state = ref<Wishlist[]>([])
|
||||||
|
|
||||||
export const fetch = async (): Promise<void> => {
|
export const fetch = async (): Promise<void> => {
|
||||||
const { data } = await client.get(prefix)
|
const { data } = await client.get(prefix)
|
||||||
refState.value = data
|
state.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useWishlistsStore = () => {
|
export const useWishlistsStore = () => {
|
||||||
return {
|
return {
|
||||||
lists: refState,
|
state: readonly(state),
|
||||||
fetch,
|
fetch,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export interface WishlistItem {
|
export interface WishlistItem {
|
||||||
id: string
|
id: number
|
||||||
title: string
|
title: string
|
||||||
url: string
|
url: string
|
||||||
imageSrc: string
|
imageSrc: string
|
||||||
|
|
|
@ -13,11 +13,11 @@ const modal = useModal()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const { list, fetch, itemBought } = useWishlistStore()
|
const { state, fetch, itemBought } = useWishlistStore()
|
||||||
await fetch(route.params.slug as string)
|
await fetch(route.params.slug as string)
|
||||||
|
|
||||||
const notBoughtItems = computed(() => {
|
const notBoughtItems = computed(() => {
|
||||||
return list.value?.items?.filter(
|
return state.value?.items?.filter(
|
||||||
(item: WishlistItemType) => item.bought === false
|
(item: WishlistItemType) => item.bought === false
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -30,24 +30,23 @@ const bought = async (item: WishlistItemType): Promise<void> => {
|
||||||
t('pages.detail-view.confirmation-modal.body.text')
|
t('pages.detail-view.confirmation-modal.body.text')
|
||||||
)
|
)
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
item.bought = true
|
|
||||||
itemBought(item)
|
itemBought(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="list !== null" class="h-full">
|
<div v-if="state !== null" class="h-full">
|
||||||
<div
|
<div
|
||||||
class="flex flex-col items-center space-x-0 space-y-2 md:flex-row md:space-x-6 md:space-y-0"
|
class="flex flex-col items-center space-x-0 space-y-2 md:flex-row md:space-x-6 md:space-y-0"
|
||||||
>
|
>
|
||||||
<Tile :image-src="list.imageSrc" class="shrink-0"></Tile>
|
<Tile :image-src="state.imageSrc" class="shrink-0"></Tile>
|
||||||
<div>
|
<div>
|
||||||
<h1 class="mb-2 text-center text-2xl font-bold md:text-left">
|
<h1 class="mb-2 text-center text-2xl font-bold md:text-left">
|
||||||
{{ list.title }}
|
{{ state.title }}
|
||||||
</h1>
|
</h1>
|
||||||
<p v-if="list.description" class="text-lg">
|
<p v-if="state.description" class="text-lg">
|
||||||
{{ list.description }}
|
{{ state.description }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -4,7 +4,7 @@ import Tile from '@/components/Tile.vue'
|
||||||
import { useWishlistsStore } from '@/composables'
|
import { useWishlistsStore } from '@/composables'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { lists, fetch } = useWishlistsStore()
|
const { state: wishlists, fetch } = useWishlistsStore()
|
||||||
await fetch()
|
await fetch()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -12,9 +12,9 @@ await fetch()
|
||||||
<h1 class="text-semibold text-center text-3xl">
|
<h1 class="text-semibold text-center text-3xl">
|
||||||
{{ t('common.app-title.text') }}
|
{{ t('common.app-title.text') }}
|
||||||
</h1>
|
</h1>
|
||||||
<div v-if="lists" class="flex flex-row flex-wrap justify-around p-10">
|
<div v-if="wishlists" class="flex flex-row flex-wrap justify-around p-10">
|
||||||
<router-link
|
<router-link
|
||||||
v-for="(item, index) in lists"
|
v-for="(item, index) in wishlists"
|
||||||
:key="index"
|
:key="index"
|
||||||
:to="'/' + item.slugUrlText"
|
:to="'/' + item.slugUrlText"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Add table
Reference in a new issue