enrecipes/app/components/modals/ActionWithSearch.vue

105 lines
2.7 KiB
Vue
Raw Normal View History

2020-11-15 10:51:10 +00:00
<template>
2021-06-18 12:52:03 +00:00
<Page @loaded="mLoad" backgroundColor="transparent" :class="theme">
2021-04-01 10:55:35 +00:00
<GridLayout columns="*" rows="auto, auto, *, auto" class="modal">
2021-06-15 11:04:42 +00:00
<RLabel class="title" :text="title | L" />
2021-02-28 15:10:26 +00:00
<StackLayout
2021-04-01 10:55:35 +00:00
row="1"
2021-06-15 11:04:42 +00:00
:hidden="!filteredRecipes.length && !searchQuery"
2021-04-01 10:55:35 +00:00
class="input"
2021-02-28 15:10:26 +00:00
>
2021-06-15 11:04:42 +00:00
<TextField
@loaded="setGravity"
class="modalInput"
:hint="'ser' | L"
v-model="searchQuery"
/>
</StackLayout>
2021-04-12 18:09:48 +00:00
<ListView row="2" for="recipe in filteredRecipes">
2021-04-01 10:55:35 +00:00
<v-template>
2021-06-15 11:04:42 +00:00
<RLabel
2021-04-01 10:55:35 +00:00
class="listItem"
:text="recipe.title"
@touch="touch($event, recipe)"
2021-02-28 15:10:26 +00:00
/>
2021-04-01 10:55:35 +00:00
</v-template>
</ListView>
<Label
row="2"
2021-06-18 12:52:03 +00:00
padding="16"
lineHeight="4"
class="tc tw"
:hidden="!noResult"
:text="noResult | L"
2021-04-01 10:55:35 +00:00
/>
2021-06-15 11:04:42 +00:00
<RGridLayout :rtl="RTL" row="3" columns="auto, *, auto" class="actions">
2021-04-01 10:55:35 +00:00
<Button
2021-06-15 11:04:42 +00:00
:hidden="!action"
2021-06-18 12:52:03 +00:00
class="text tb st fb"
2021-04-01 10:55:35 +00:00
:text="action | L"
2021-02-28 15:10:26 +00:00
@tap="$modal.close(action)"
/>
2021-04-01 10:55:35 +00:00
<Button
2021-02-28 15:10:26 +00:00
col="2"
2021-06-18 12:52:03 +00:00
class="text tb st fb"
2021-05-22 08:56:31 +00:00
:text="'cBtn' | L"
2021-06-15 11:04:42 +00:00
@tap="$modal.close(0)"
2021-02-28 15:10:26 +00:00
/>
2021-06-15 11:04:42 +00:00
</RGridLayout>
</GridLayout>
2021-02-28 15:10:26 +00:00
</Page>
2020-11-15 10:51:10 +00:00
</template>
<script>
2021-02-28 15:10:26 +00:00
import { mapState } from "vuex";
2020-11-15 10:51:10 +00:00
export default {
2021-04-01 10:55:35 +00:00
props: ["title", "recipes", "height", "action"],
2020-11-15 10:51:10 +00:00
data() {
return {
2020-12-29 10:35:19 +00:00
searchQuery: "",
2021-02-28 15:10:26 +00:00
};
2020-11-15 10:51:10 +00:00
},
computed: {
2021-06-15 11:04:42 +00:00
...mapState(["icon", "theme", "RTL"]),
2020-11-15 10:51:10 +00:00
filteredRecipes() {
2021-02-28 15:10:26 +00:00
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 10:51:10 +00:00
},
2021-06-18 12:52:03 +00:00
noResult() {
if (!this.recipes.length) return "recListEmp";
else if (!this.filteredRecipes.length && this.searchQuery)
return "noRecs";
else 0;
},
2020-11-15 10:51:10 +00:00
},
methods: {
2021-02-28 15:10:26 +00:00
tapAction(recipe) {
this.$modal.close(recipe.id);
2020-11-15 10:51:10 +00:00
},
2021-02-28 15:10:26 +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-12-29 10:35:19 +00:00
},
2021-04-01 10:55:35 +00:00
touch({ object, action }, recipe) {
2021-06-18 12:52:03 +00:00
this.touchFade(object, action);
2021-04-01 10:55:35 +00:00
if (action == "up") this.tapAction(recipe);
},
2020-11-15 10:51:10 +00:00
},
2021-02-28 15:10:26 +00:00
};
2020-11-15 10:51:10 +00:00
</script>