enrecipes/app/components/ViewRecipe.vue

321 lines
9.7 KiB
Vue
Raw Normal View History

2020-10-14 19:32:32 +00:00
<template>
2020-10-21 17:54:45 +00:00
<Page @loaded="setCurrentComponent">
<ActionBar height="128" margin="0" flat="true">
2020-10-14 19:32:32 +00:00
<GridLayout
2020-10-21 17:54:45 +00:00
rows="64, 64"
columns="auto, *, auto,auto, auto"
2020-10-14 19:32:32 +00:00
class="actionBarContainer"
>
<Label
2020-10-21 17:54:45 +00:00
row="0"
2020-10-14 19:32:32 +00:00
col="0"
class="bx leftAction"
:text="icon.back"
automationText="Back"
2020-10-21 17:54:45 +00:00
@tap="$navigateBack()"
2020-10-14 19:32:32 +00:00
/>
2020-10-21 17:54:45 +00:00
<ScrollView
row="1"
2020-10-14 19:32:32 +00:00
col="1"
2020-10-21 17:54:45 +00:00
colSpan="3"
orientation="horizontal"
scrollBarIndicatorVisible="false"
>
<Label
class="title orkm"
:text="recipe.title"
verticalAlignment="bottom"
/>
</ScrollView>
<Label row="0" col="2" class="bx" :text="icon.share" @tap="" />
2020-10-14 19:32:32 +00:00
<Label
2020-10-21 17:54:45 +00:00
row="0"
2020-10-14 19:32:32 +00:00
col="3"
class="bx"
:class="{ 'view-favorited': recipe.isFavorite }"
:text="recipe.isFavorite ? icon.heart : icon.heartOutline"
@tap="toggleFavorite"
2020-10-21 17:54:45 +00:00
/>
<Label
row="0"
col="4"
class="bx"
:class="{ 'view-favorited': !recipe.tried }"
:text="recipe.tried ? icon.musttryOutline : icon.musttry"
@tap="toggleMustTry"
2020-10-14 19:32:32 +00:00
/>
</GridLayout>
</ActionBar>
<AbsoluteLayout>
<TabView androidElevation="0" width="100%" height="100%">
<TabViewItem title="Overview">
<ScrollView scrollBarIndicatorVisible="false">
2020-10-21 17:54:45 +00:00
<StackLayout>
2020-10-14 19:32:32 +00:00
<StackLayout
width="100%"
:height="screenWidth"
verticalAlignment="center"
class="view-imageHolder"
>
<Image
v-if="recipe.imageSrc"
:src="recipe.imageSrc"
stretch="aspectFill"
width="100%"
:height="screenWidth"
/>
<Label
v-else
horizontalAlignment="center"
class="bx"
fontSize="160"
2020-10-21 17:54:45 +00:00
:text="icon.image"
2020-10-14 19:32:32 +00:00
/>
</StackLayout>
2020-10-21 17:54:45 +00:00
<StackLayout margin="16 16 144">
2020-10-14 19:32:32 +00:00
<Label class="view-cat orkm" :text="recipe.category" />
<Label
2020-10-21 17:54:45 +00:00
class="view-title orkm"
2020-10-14 19:32:32 +00:00
:text="recipe.title"
textWrap="true"
/>
<Label
class="view-other"
:text="`Preparation time: ${getTime(recipe.prepTime)}`"
/>
<Label
class="view-other"
:text="`Cooking time: ${getTime(recipe.cookTime)}`"
/>
<Label
class="view-other"
:text="`Portion size: ${recipe.portionSize}`"
/>
</StackLayout>
</StackLayout>
</ScrollView>
</TabViewItem>
2020-10-21 17:54:45 +00:00
<TabViewItem title="Ingredients" v-if="recipe.ingredients.length">
2020-10-14 19:32:32 +00:00
<ScrollView scrollBarIndicatorVisible="false">
2020-10-21 17:54:45 +00:00
<StackLayout padding="16 16 124">
2020-10-14 19:32:32 +00:00
<AbsoluteLayout class="inputField">
<TextField
width="50%"
v-model="portionScale"
keyboardType="number"
/>
<Label top="0" class="fieldLabel" text="Set portion size" />
</AbsoluteLayout>
<StackLayout margin="24 0 8 0">
<Label
2020-10-21 17:54:45 +00:00
class="view-title orkm"
2020-10-14 19:32:32 +00:00
:text="
`Ingredients for ${portionScale}${
portionScale > 1
? ' portions'
: portionScale == 0
? '1 portion'
: ' portion'
}`
"
textWrap="true"
/>
<Label
class="view-ingredient"
v-for="(item, index) in recipe.ingredients"
:key="index"
:text="
`${roundedQuantity(item.quantity)}${
item.unit ? ' ' + item.unit : ''
} ${item.item}`
"
textWrap="true"
/>
</StackLayout>
</StackLayout>
</ScrollView>
</TabViewItem>
2020-10-21 17:54:45 +00:00
<TabViewItem title="Instructions" v-if="recipe.instructions.length">
2020-10-14 19:32:32 +00:00
<ScrollView scrollBarIndicatorVisible="false">
2020-10-21 17:54:45 +00:00
<StackLayout padding="32 16 132">
2020-10-14 19:32:32 +00:00
<GridLayout
columns="auto ,*"
v-for="(instruction, index) in recipe.instructions"
:key="index"
>
<Label
col="0"
colSpan="2"
class="view-instruction"
:class="{
instructionWOBorder:
index === recipe.instructions.length - 1,
}"
:text="instruction"
textWrap="true"
/>
<Label
verticalAlignment="top"
horizontalAlignment="center"
class="view-count orkb"
col="0"
:text="index + 1"
/>
</GridLayout>
</StackLayout>
</ScrollView>
</TabViewItem>
2020-10-21 17:54:45 +00:00
<TabViewItem title="Notes" v-if="recipe.notes.length">
2020-10-14 19:32:32 +00:00
<ScrollView scrollBarIndicatorVisible="false">
2020-10-21 17:54:45 +00:00
<StackLayout padding="32 16 132">
2020-10-14 19:32:32 +00:00
<GridLayout
columns="auto ,*"
v-for="(note, index) in recipe.notes"
:key="index"
>
<Label
col="0"
colSpan="2"
class="view-note"
:text="note"
textWrap="true"
/>
<Label
verticalAlignment="top"
horizontalAlignment="center"
class="view-count orkb"
col="0"
:text="index + 1"
/>
</GridLayout>
</StackLayout>
</ScrollView>
</TabViewItem>
2020-10-21 17:54:45 +00:00
<TabViewItem title="References" v-if="recipe.references.length">
2020-10-14 19:32:32 +00:00
<ScrollView scrollBarIndicatorVisible="false">
2020-10-21 17:54:45 +00:00
<StackLayout padding="32 16 132">
2020-10-14 19:32:32 +00:00
<GridLayout
columns="auto ,*"
v-for="(reference, index) in recipe.references"
:key="index"
@tap="openURL($event, reference)"
>
<Label
col="0"
colSpan="2"
class="view-reference"
:text="reference"
textWrap="true"
/>
<Label
verticalAlignment="top"
horizontalAlignment="center"
class="orkb view-count"
col="0"
:text="index + 1"
/>
</GridLayout>
</StackLayout>
</ScrollView>
</TabViewItem>
</TabView>
<GridLayout id="btnFabContainer" rows="*,88" columns="*,88">
<Label
2020-10-21 17:54:45 +00:00
v-if="!busy"
2020-10-14 19:32:32 +00:00
row="1"
col="1"
class="bx btnFab"
:text="icon.edit"
androidElevation="8"
@tap="editRecipe"
/>
2020-10-21 17:54:45 +00:00
<ActivityIndicator v-else row="1" col="1" :busy="busy" />
2020-10-14 19:32:32 +00:00
</GridLayout>
</AbsoluteLayout>
</Page>
</template>
<script>
import { screen } from "tns-core-modules/platform"
import * as utils from "tns-core-modules/utils/utils"
2020-10-21 17:54:45 +00:00
import { getNumber, setNumber } from "application-settings"
import * as Toast from "nativescript-toast"
import EditRecipe from "./EditRecipe.vue"
2020-10-14 19:32:32 +00:00
import { mapState, mapActions } from "vuex"
export default {
2020-10-21 17:54:45 +00:00
props: ["recipeIndex", "hijackGlobalBackEvent", "releaseGlobalBackEvent"],
2020-10-14 19:32:32 +00:00
data() {
return {
2020-10-21 17:54:45 +00:00
busy: false,
2020-10-14 19:32:32 +00:00
portionScale: 1,
}
},
computed: {
...mapState(["icon", "recipes"]),
2020-10-21 17:54:45 +00:00
recipe() {
return this.recipes[this.recipeIndex]
},
2020-10-14 19:32:32 +00:00
screenWidth() {
return screen.mainScreen.widthDIPs
},
isPortionScalePositive() {
return this.portionScale && !isNaN(this.portionScale)
? parseFloat(this.portionScale)
: 1
},
},
methods: {
roundedQuantity(quantity, unit) {
return Math.round(quantity * this.isPortionScalePositive * 100) / 100
},
editRecipe() {
2020-10-21 17:54:45 +00:00
this.busy = true
this.$navigateTo(EditRecipe, {
transition: {
name: "slide",
duration: 250,
curve: "easeIn",
},
props: {
recipeIndex: this.recipeIndex,
},
// backstackVisible: false,
})
2020-10-14 19:32:32 +00:00
},
toggleFavorite() {
2020-10-21 17:54:45 +00:00
this.recipe.isFavorite
? Toast.makeText("Removed from Favorites").show()
: Toast.makeText("Added to Favorites").show()
this.$store.dispatch("toggleFavorite", this.recipeIndex)
},
toggleMustTry() {
this.recipe.tried
? Toast.makeText("Added to Must-Try").show()
: Toast.makeText("Removed from Must-Try").show()
this.$store.dispatch("toggleMustTry", this.recipeIndex)
2020-10-14 19:32:32 +00:00
},
getTime(time) {
let t = time.split(":")
let h = t[0]
let m = t[1]
return h !== "00" ? `${h}h ${m}m` : `${m}m`
},
openURL(args, url) {
utils.openUrl(url)
},
2020-10-21 17:54:45 +00:00
setCurrentComponent() {
this.releaseGlobalBackEvent()
this.busy = false
setTimeout((e) => {
this.$store.dispatch("setCurrentComponent", "ViewRecipe")
}, 500)
},
2020-10-14 19:32:32 +00:00
},
}
</script>