enrecipes/app/components/modals/ActionWithSearch.vue

107 lines
2.7 KiB
Vue
Raw Normal View History

2020-11-15 16:21:10 +05:30
<template>
2021-04-12 23:39:48 +05:30
<Page
@loaded="transparentPage"
backgroundColor="transparent"
:class="appTheme"
>
2021-04-01 16:25:35 +05:30
<GridLayout columns="*" rows="auto, auto, *, auto" class="modal">
<Label class="title" :text="title | L" />
2021-02-28 20:40:26 +05:30
<StackLayout
2021-04-01 16:25:35 +05:30
row="1"
2021-02-28 20:40:26 +05:30
v-if="filteredRecipes.length || searchQuery"
2021-04-01 16:25:35 +05:30
class="input"
2021-02-28 20:40:26 +05:30
>
2021-05-22 14:26:31 +05:30
<TextField class="modalInput" :hint="'ser' | L" v-model="searchQuery" />
</StackLayout>
2021-04-12 23:39:48 +05:30
<ListView row="2" for="recipe in filteredRecipes">
2021-04-01 16:25:35 +05:30
<v-template>
2021-02-28 20:40:26 +05:30
<Label
2021-04-01 16:25:35 +05:30
class="listItem"
:text="recipe.title"
@touch="touch($event, recipe)"
2021-02-28 20:40:26 +05:30
/>
2021-04-01 16:25:35 +05:30
</v-template>
</ListView>
<Label
row="2"
class="noResInfo"
v-if="!filteredRecipes.length && !searchQuery"
:text="'recListEmp' | L"
/>
<Label
row="2"
class="noResInfo"
v-if="!filteredRecipes.length && searchQuery"
:text="'noRecs' | L"
/>
<GridLayout row="3" columns="auto, *, auto" class="actions">
<Button
2021-02-28 20:40:26 +05:30
v-if="action"
2021-04-01 16:25:35 +05:30
class="text sm"
:text="action | L"
2021-02-28 20:40:26 +05:30
@tap="$modal.close(action)"
/>
2021-04-01 16:25:35 +05:30
<Button
2021-02-28 20:40:26 +05:30
col="2"
2021-04-01 16:25:35 +05:30
class="text sm"
2021-05-22 14:26:31 +05:30
:text="'cBtn' | L"
2021-02-28 20:40:26 +05:30
@tap="$modal.close(false)"
/>
</GridLayout>
</GridLayout>
2021-02-28 20:40:26 +05:30
</Page>
2020-11-15 16:21:10 +05:30
</template>
<script>
2021-02-28 20:40:26 +05:30
import { mapState } from "vuex";
2020-11-15 16:21:10 +05:30
export default {
2021-04-01 16:25:35 +05:30
props: ["title", "recipes", "height", "action"],
2020-11-15 16:21:10 +05:30
data() {
return {
2020-12-29 16:05:19 +05:30
searchQuery: "",
2021-02-28 20:40:26 +05:30
};
2020-11-15 16:21:10 +05:30
},
computed: {
2021-04-01 16:25:35 +05:30
...mapState(["icon", "appTheme"]),
2020-11-15 16:21:10 +05:30
filteredRecipes() {
2021-02-28 20:40:26 +05:30
return this.recipes
.map((e, i) => {
return {
id: e.id,
title: e.title,
cuisine: e.cuisine,
category: e.category,
tags: e.tags.map((e) => e.toLowerCase()).join(),
ingredients: e.ingredients.map((e) => e.item.toLowerCase()).join(),
};
})
.filter((e) => this.recipeFilter(e));
2020-11-15 16:21:10 +05:30
},
},
methods: {
2021-02-28 20:40:26 +05:30
tapAction(recipe) {
this.$modal.close(recipe.id);
2020-11-15 16:21:10 +05:30
},
2021-02-28 20:40:26 +05:30
centerLabel(args) {
args.object.android.setGravity(16);
2020-11-15 16:21:10 +05:30
},
2021-02-28 20:40:26 +05:30
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-12-29 16:05:19 +05:30
},
2021-04-01 16:25:35 +05:30
touch({ object, action }, recipe) {
object.className = action.match(/down|move/)
? "listItem fade"
: "listItem";
if (action == "up") this.tapAction(recipe);
},
2020-11-15 16:21:10 +05:30
},
2021-02-28 20:40:26 +05:30
};
2020-11-15 16:21:10 +05:30
</script>