enrecipes/app/components/modal/ActionDialogWithSearch.vue

82 lines
2.9 KiB
Vue
Raw Normal View History

2020-11-15 10:51:10 +00:00
<template>
<Page>
2021-01-13 05:02:48 +00:00
<GridLayout columns="*" rows="auto, auto, auto, *, auto" class="dialogContainer" :class="appTheme">
2021-01-23 17:20:15 +00:00
<Label row="0" class="er dialogIcon" backgroundColor="#858585" :color="iconColor" :text="icon[helpIcon]" />
2021-01-13 05:02:48 +00:00
<Label row="1" class="dialogTitle orkm" :text="`${title}` | L" textWrap='true' />
<StackLayout row="2" v-if="filteredRecipes.length || searchQuery" padding="0 24 24">
2020-12-29 10:35:19 +00:00
<TextField :hint="'Search' | L" v-model="searchQuery" />
2020-11-15 10:51:10 +00:00
</StackLayout>
2021-01-13 05:02:48 +00:00
<ScrollView row="3" width="100%" :height="height ? height : ''">
<StackLayout>
2021-01-23 17:20:15 +00:00
<MDButton v-for="(recipe, index) in filteredRecipes" :key="index" class="actionItem" variant="text" :rippleColor="rippleColor" :text="recipe.title" @loaded="centerLabel" @tap="tapAction(recipe)" />
<Label padding="24" lineHeight="6" v-if="!filteredRecipes.length && !searchQuery" :text="'recListEmp' | L" textAlignment="center" textWrap="true" />
<Label padding="24" lineHeight="6" v-if="!filteredRecipes.length && searchQuery" :text="'noRecs' | L" textAlignment="center" textWrap="true" />
</StackLayout>
</ScrollView>
2021-01-13 05:02:48 +00:00
<GridLayout row="4" rows="auto" columns="auto, *, auto" class="actionsContainer">
<MDButton :rippleColor="rippleColor" variant="text" v-if="action" col="0" class="action orkm pull-left" :text="`${action}` | L" @tap="$modal.close(action)" />
<MDButton :rippleColor="rippleColor" variant="text" col="2" class="action orkm pull-right" :text="'CANCEL' | L" @tap="$modal.close(false)" />
</GridLayout>
2020-12-29 10:35:19 +00:00
</GridLayout>
</Page>
2020-11-15 10:51:10 +00:00
</template>
<script>
import {
2021-01-13 05:02:48 +00:00
Application
}
from "@nativescript/core"
2021-01-13 05:02:48 +00:00
import {
mapState
}
from "vuex"
2020-11-15 10:51:10 +00:00
export default {
2021-01-13 05:02:48 +00:00
props: [ "title", "recipes", "height", "action", "helpIcon" ],
2020-11-15 10:51:10 +00:00
data() {
return {
2020-12-29 10:35:19 +00:00
searchQuery: "",
2020-11-15 10:51:10 +00:00
}
},
computed: {
2021-01-13 05:02:48 +00:00
...mapState( [ 'icon' ] ),
2020-11-15 10:51:10 +00:00
appTheme() {
return Application.systemAppearance()
},
2021-01-13 05:02:48 +00:00
isLightMode() {
return this.appTheme == "light"
},
2020-11-15 10:51:10 +00:00
rippleColor() {
2021-01-23 17:20:15 +00:00
return "rgba(133,133,133,0.2)"
2020-11-15 10:51:10 +00:00
},
2021-01-13 05:02:48 +00:00
iconColor() {
2021-01-23 17:20:15 +00:00
return this.isLightMode ? "#f0f0f0" : "#1A1A1A"
2020-11-15 10:51:10 +00:00
},
filteredRecipes() {
return this.recipes.map( ( e, i ) => {
return {
id: e.id,
title: e.title,
2020-12-29 10:35:19 +00:00
cuisine: e.cuisine,
category: e.category,
tags: e.tags.map( e => e.toLowerCase() ).join(),
ingredients: e.ingredients.map( e => e.item.toLowerCase() ).join(),
}
2020-12-29 10:35:19 +00:00
} ).filter( ( e ) => this.recipeFilter( e ) )
2020-11-15 10:51:10 +00:00
},
2020-12-29 10:35:19 +00:00
2020-11-15 10:51:10 +00:00
},
methods: {
tapAction( recipe ) {
this.$modal.close( recipe.id )
2020-11-15 10:51:10 +00:00
},
2021-01-23 17:20:15 +00:00
centerLabel( args ) {
args.object.android.setGravity( 16 )
2020-11-15 10:51:10 +00:00
},
2020-12-29 10:35:19 +00:00
recipeFilter( e ) {
let searchQuery = this.searchQuery.toLowerCase()
return e.title.includes( searchQuery ) || e.cuisine.includes( searchQuery ) || e.category.includes( searchQuery ) || e.tags.includes( searchQuery ) || e.ingredients.includes( searchQuery )
},
2020-11-15 10:51:10 +00:00
},
}
</script>