mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-04-19 23:37:41 +00:00
small refactoring
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
ff35bb3144
commit
b291a09590
2 changed files with 39 additions and 31 deletions
|
@ -51,12 +51,9 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Wishlist } from '@/types'
|
import { Wishlist } from '@/types'
|
||||||
import { PropType } from 'vue'
|
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { Form } from 'vee-validate'
|
import { Form } from 'vee-validate'
|
||||||
import { object, string, boolean } from 'yup'
|
import { object, string, boolean } from 'yup'
|
||||||
import { useToast } from 'vue-toastification'
|
|
||||||
import {
|
import {
|
||||||
ButtonBase,
|
ButtonBase,
|
||||||
InputText,
|
InputText,
|
||||||
|
@ -65,19 +62,12 @@ import {
|
||||||
InputTextArea,
|
InputTextArea,
|
||||||
} from '@/components'
|
} from '@/components'
|
||||||
import { IconSave } from '@/components/icons'
|
import { IconSave } from '@/components/icons'
|
||||||
import { useWishlistStore } from '@/composables'
|
|
||||||
|
|
||||||
defineProps({
|
defineProps<{
|
||||||
wishlist: {
|
wishlist: Wishlist
|
||||||
type: Object as PropType<Wishlist>,
|
}>()
|
||||||
requried: true,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
const router = useRouter()
|
const emits = defineEmits(['update'])
|
||||||
const toast = useToast()
|
|
||||||
|
|
||||||
const { update } = useWishlistStore()
|
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -112,13 +102,7 @@ const schema = object().shape(
|
||||||
)
|
)
|
||||||
|
|
||||||
const onSubmit = async (values: any): Promise<void> => {
|
const onSubmit = async (values: any): Promise<void> => {
|
||||||
try {
|
|
||||||
values.imageSrc = values.imageFile || values.imageSrc
|
values.imageSrc = values.imageFile || values.imageSrc
|
||||||
await update(values)
|
emits('update', values)
|
||||||
toast.success(t('common.wishlist.saved.text'))
|
|
||||||
router.push(`/${values.slugUrlText}`)
|
|
||||||
} catch (error) {
|
|
||||||
toast.error(t('common.wishlist.saving-failed.text'))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { WishlistItem as WishlistItemType } from '@/types'
|
import { Wishlist, WishlistItem as WishlistItemType } from '@/types'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useWishlistStore, useModal, useEditMode } from '@/composables'
|
import { useWishlistStore, useModal, useEditMode } from '@/composables'
|
||||||
import {
|
import {
|
||||||
FormWishlist,
|
FormWishlist,
|
||||||
|
@ -10,17 +10,37 @@ import {
|
||||||
FormWishlistItem,
|
FormWishlistItem,
|
||||||
} from '@/components'
|
} from '@/components'
|
||||||
import { IconNoGift } from '../components/icons'
|
import { IconNoGift } from '../components/icons'
|
||||||
|
import { useToast } from 'vue-toastification'
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
const modal = useModal()
|
const modal = useModal()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
const toast = useToast()
|
||||||
const { isActive: editModeIsActive } = useEditMode()
|
const { isActive: editModeIsActive } = useEditMode()
|
||||||
|
|
||||||
const { state, fetch, isReady, itemBought, itemDelete, filteredItems } =
|
const {
|
||||||
useWishlistStore()
|
state,
|
||||||
|
fetch,
|
||||||
|
isReady,
|
||||||
|
update,
|
||||||
|
itemBought,
|
||||||
|
itemDelete,
|
||||||
|
filteredItems,
|
||||||
|
} = useWishlistStore()
|
||||||
await fetch(route.params.slug as string)
|
await fetch(route.params.slug as string)
|
||||||
|
|
||||||
const bought = async (item: WishlistItemType): Promise<void> => {
|
const handleUpdateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
||||||
|
try {
|
||||||
|
await update(wishlist)
|
||||||
|
toast.success(t('common.wishlist.saved.text'))
|
||||||
|
router.push(`/${wishlist.slugUrlText}`)
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t('common.wishlist.saving-failed.text'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleBought = async (item: WishlistItemType): Promise<void> => {
|
||||||
const confirmed = await modal.show(
|
const confirmed = await modal.show(
|
||||||
t('pages.detail-view.modal-bought-item.title.text'),
|
t('pages.detail-view.modal-bought-item.title.text'),
|
||||||
t('pages.detail-view.modal-bought-item.confirm-button.text'),
|
t('pages.detail-view.modal-bought-item.confirm-button.text'),
|
||||||
|
@ -31,7 +51,7 @@ const bought = async (item: WishlistItemType): Promise<void> => {
|
||||||
itemBought(item)
|
itemBought(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const deleteItem = async (item: WishlistItemType): Promise<void> => {
|
const handleDeleteItem = async (item: WishlistItemType): Promise<void> => {
|
||||||
const confirmed = await modal.show(
|
const confirmed = await modal.show(
|
||||||
t('pages.detail-view.modal-delete-item.title.text'),
|
t('pages.detail-view.modal-delete-item.title.text'),
|
||||||
t('pages.detail-view.modal-delete-item.confirm-button.text'),
|
t('pages.detail-view.modal-delete-item.confirm-button.text'),
|
||||||
|
@ -58,7 +78,7 @@ const deleteItem = async (item: WishlistItemType): Promise<void> => {
|
||||||
{{ state.description }}
|
{{ state.description }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<FormWishlist v-else :wishlist="state" />
|
<FormWishlist v-else :wishlist="state" @update="handleUpdateWishlist" />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="filteredItems.length > 0"
|
v-if="filteredItems.length > 0"
|
||||||
|
@ -68,9 +88,13 @@ const deleteItem = async (item: WishlistItemType): Promise<void> => {
|
||||||
<WishlistItem
|
<WishlistItem
|
||||||
v-if="!editModeIsActive"
|
v-if="!editModeIsActive"
|
||||||
:item="item"
|
:item="item"
|
||||||
@bought="bought(item)"
|
@bought="handleBought(item)"
|
||||||
|
/>
|
||||||
|
<FormWishlistItem
|
||||||
|
v-else
|
||||||
|
:item="item"
|
||||||
|
@delete="handleDeleteItem(item)"
|
||||||
/>
|
/>
|
||||||
<FormWishlistItem v-else :item="item" @delete="deleteItem(item)" />
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="flex h-1/2 w-full justify-center">
|
<div v-else class="flex h-1/2 w-full justify-center">
|
||||||
|
|
Loading…
Add table
Reference in a new issue