-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added possibility to crud pastries and flavours
- Loading branch information
1 parent
f4ae4c9
commit 3fd0868
Showing
4 changed files
with
120 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<template> | ||
<div> | ||
<div class="flex flex-col gap-2"> | ||
<div v-for="(flavour, index) in localSelectedFlavours" :key="index" class="flex flex-row gap-2"> | ||
<div>{{ flavour }}</div> | ||
<button @click="removeFlavour(index)">Remove</button> | ||
</div> | ||
</div> | ||
<div class="flex flex-row gap-5 mt-5"> | ||
<input v-model="newFlavour" placeholder="New Flavour" class="text-black" /> | ||
<button @click="addFlavour" :disabled="newFlavour.length === 0">Add Flavour</button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref, defineEmits, watch } from 'vue' | ||
const props = defineProps<{ selectedFlavours: string[] }>() | ||
const emit = defineEmits(['update:selectedFlavours']) | ||
const localSelectedFlavours = ref<string[]>([]) | ||
const newFlavour = ref('') | ||
const addFlavour = () => { | ||
if (newFlavour.value && !localSelectedFlavours.value.includes(newFlavour.value)) { | ||
localSelectedFlavours.value.push(newFlavour.value) | ||
newFlavour.value = '' | ||
emitSelectedFlavours() | ||
} | ||
} | ||
const removeFlavour = (index: number) => { | ||
localSelectedFlavours.value.splice(index, 1) | ||
emitSelectedFlavours() | ||
} | ||
const emitSelectedFlavours = () => { | ||
emit('update:selectedFlavours', localSelectedFlavours.value) | ||
} | ||
watch(localSelectedFlavours, emitSelectedFlavours) | ||
watch(() => props.selectedFlavours, (newSelectedPastries) => { | ||
localSelectedFlavours.value = newSelectedPastries | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<LoadingWrapper :state="state"> | ||
<div v-for="pastry in data" :key="pastry.id" class="flex flex-row gap-2"> | ||
<input | ||
type="checkbox" | ||
:id="pastry.id" | ||
:value="pastry.id" | ||
v-model="localSelectedPastryIds" | ||
@change="emitSelectedPastries" | ||
> | ||
<label :for="pastry.id">{{ pastry.name }}</label><br> | ||
</div> | ||
</LoadingWrapper> | ||
</template> | ||
<script lang="ts" setup> | ||
import { type Ref, ref, watch } from 'vue' | ||
import { AppContainerKey } from '@/core/container/app-container' | ||
import { injectStrict } from '@/core/container/inject' | ||
import { useLoading } from '../../shared/functions/use-loading' | ||
import type { Pastry } from '../../core/models/pastry' | ||
const props = defineProps<{ selectedPastries: Pastry[] }>() | ||
const emit = defineEmits(['update:selectedPastries']) | ||
const getPastriesListUseCase = injectStrict(AppContainerKey.getPastriesUseCase) | ||
const { state, data, load } = useLoading<Pastry[]>() | ||
const localSelectedPastryIds: Ref<string[]> = ref(props.selectedPastries.map(pastry => pastry.id)) | ||
load(() => { | ||
return getPastriesListUseCase.execute() | ||
}) | ||
const emitSelectedPastries = () => { | ||
const selectedPastries = data.value.filter(pastry => localSelectedPastryIds.value.includes(pastry.id)) | ||
emit('update:selectedPastries', selectedPastries) | ||
} | ||
watch(localSelectedPastryIds, emitSelectedPastries) | ||
watch(() => props.selectedPastries, (newSelectedPastries) => { | ||
localSelectedPastryIds.value = newSelectedPastries.map(pastry => pastry.id) | ||
}) | ||
</script> |