-
Notifications
You must be signed in to change notification settings - Fork 4
/
RecipeDetailsPage.vue
70 lines (56 loc) · 1.82 KB
/
RecipeDetailsPage.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template>
<q-card flat class="my-card" v-if="recipe !== undefined">
<q-card-section>
<div class="text-h6">{{ recipe.name }}</div>
</q-card-section>
<q-item-label overline class="q-pa-md">Instructions</q-item-label>
<q-card-section class="q-pt-none">
<p>
{{ recipe.instructions }}
</p>
</q-card-section>
<q-item-label overline class="q-pa-md">Ingredients</q-item-label>
<q-card-section
class="q-pt-none"
v-for="ingredient of recipe.ingredients"
:key="ingredient.id"
>
<q-item-label overline>{{ ingredient.name }}</q-item-label>
<q-item-label caption>{{ ingredient.measurements }}</q-item-label>
</q-card-section>
<q-card-section class="q-pt-none">
<!-- {{ recipe.nutritionInformation }} -->
</q-card-section>
<q-item-label overline class="q-pa-md">Nutrition</q-item-label>
<q-card-section class="q-pt-none">
<p>{{ recipe.nutritionInformation }}</p>
</q-card-section>
<q-card-section>
<q-btn color="accent" :loading="isLoading" @click="remove()"
>Delete</q-btn
>
</q-card-section>
</q-card>
<div v-else>Recipe not found!</div>
</template>
<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { Recipe } from 'src/components/models';
import { useDatabaseStore } from 'src/stores/database';
import { watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const store = useDatabaseStore();
const route = useRoute();
const router = useRouter();
const { getRecipeById, deleteRecipe } = store;
const { isLoading } = storeToRefs(store);
const recipe = getRecipeById(route.params.id as string);
const remove = () => {
deleteRecipe(recipe as Recipe);
watch(isLoading, (loading) => {
if (!loading) {
router.push({ path: '/' });
}
});
};
</script>