enrecipes/app/components/modals/ActionWithSearch.vue

105 lines
2.7 KiB
Vue
Raw Normal View History

2020-11-15 16:21:10 +05:30
<template>
2021-06-18 18:22:03 +05:30
<Page @loaded="mLoad" backgroundColor="transparent" :class="theme">
2021-04-01 16:25:35 +05:30
<GridLayout columns="*" rows="auto, auto, *, auto" class="modal">
2021-06-15 16:34:42 +05:30
<RLabel 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-06-15 16:34:42 +05:30
:hidden="!filteredRecipes.length && !searchQuery"
2021-04-01 16:25:35 +05:30
class="input"
2021-02-28 20:40:26 +05:30
>
2021-06-15 16:34:42 +05:30
<TextField
@loaded="setGravity"
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-06-15 16:34:42 +05:30
<RLabel
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"
2021-06-18 18:22:03 +05:30
padding="16"
lineHeight="4"
class="tc tw"
:hidden="!noResult"
:text="noResult | L"
2021-04-01 16:25:35 +05:30
/>
2021-06-15 16:34:42 +05:30
<RGridLayout :rtl="RTL" row="3" columns="auto, *, auto" class="actions">
2021-04-01 16:25:35 +05:30
<Button
2021-06-15 16:34:42 +05:30
:hidden="!action"
2021-06-18 18:22:03 +05:30
class="text tb st fb"
2021-04-01 16:25:35 +05:30
: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-06-18 18:22:03 +05:30
class="text tb st fb"
2021-05-22 14:26:31 +05:30
:text="'cBtn' | L"
2021-06-15 16:34:42 +05:30
@tap="$modal.close(0)"
2021-02-28 20:40:26 +05:30
/>
2021-06-15 16:34:42 +05:30
</RGridLayout>
</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-06-15 16:34:42 +05:30
...mapState(["icon", "theme", "RTL"]),
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(),
2021-06-28 17:08:21 +05:30
ingredients: e.ingredients.map((e) => e.value.toLowerCase()).join(),
2021-02-28 20:40:26 +05:30
};
})
.filter((e) => this.recipeFilter(e));
2020-11-15 16:21:10 +05:30
},
2021-06-18 18:22:03 +05:30
noResult() {
if (!this.recipes.length) return "recListEmp";
else if (!this.filteredRecipes.length && this.searchQuery)
return "noRecs";
else 0;
},
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
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) {
2021-06-18 18:22:03 +05:30
this.touchFade(object, action);
2021-04-01 16:25:35 +05:30
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>