From 7a6b490e51dcdc04407fc1902410668305b1d09e Mon Sep 17 00:00:00 2001 From: hay-kot Date: Sat, 3 Apr 2021 16:42:13 -0800 Subject: [PATCH] advanced search apge --- .../components/Recipe/MobileRecipeCard.vue | 2 +- .../src/components/UI/Search/SearchBar.vue | 4 +- .../src/pages/SearchPage/FilterSelector.vue | 64 +++++++++----- frontend/src/pages/SearchPage/index.vue | 87 ++++++++----------- 4 files changed, 85 insertions(+), 72 deletions(-) diff --git a/frontend/src/components/Recipe/MobileRecipeCard.vue b/frontend/src/components/Recipe/MobileRecipeCard.vue index a11accdbb..c0df606bf 100644 --- a/frontend/src/components/Recipe/MobileRecipeCard.vue +++ b/frontend/src/components/Recipe/MobileRecipeCard.vue @@ -7,7 +7,7 @@ > - + diff --git a/frontend/src/components/UI/Search/SearchBar.vue b/frontend/src/components/UI/Search/SearchBar.vue index a1ef1a209..564e36995 100644 --- a/frontend/src/components/UI/Search/SearchBar.vue +++ b/frontend/src/components/UI/Search/SearchBar.vue @@ -27,7 +27,7 @@ @click="navOnClick ? null : selected(item.item.slug, item.item.name)" > - + - - Include - + + + + Include + - - Exclude - - - - Any - - + + Exclude + + + + + + And + + + Or + + + diff --git a/frontend/src/pages/SearchPage/index.vue b/frontend/src/pages/SearchPage/index.vue index fcf5726cd..50533313a 100644 --- a/frontend/src/pages/SearchPage/index.vue +++ b/frontend/src/pages/SearchPage/index.vue @@ -26,8 +26,8 @@ -

Category Filter

- +

Category Filter

+
-

Tag Filter

- +

Tag Filter

+ { - const includesTags = this.checkTags(recipe.tags); - const includesCats = this.checkCategories(recipe.recipeCategory); + const includesTags = this.check( + this.includeTags, + recipe.tags, + this.tagFilter.matchAny, + this.tagFilter.exclude + ); + const includesCats = this.check( + this.includeCategories, + recipe.recipeCategory, + this.catFilter.matchAny, + this.catFilter.exclude + ); return [includesTags, includesCats].every(x => x === true); }); }, @@ -136,50 +149,26 @@ export default { }, }, methods: { - checkIncludes(filterBy, recipeList) { + check(filterBy, recipeList, matchAny, exclude) { + let isMatch = true; + if (filterBy.length === 0) return isMatch; + if (recipeList) { - return filterBy.every(t => recipeList.includes(t)); + if (matchAny) { + isMatch = filterBy.some(t => recipeList.includes(t)); // Checks if some items are a match + } else { + isMatch = filterBy.every(t => recipeList.includes(t)); // Checks if every items is a match + } + return exclude ? !isMatch : isMatch; } else; return false; }, - checkExcludes(filterBy, recipeList) { - if (recipeList) { - return filterBy.every(t => !recipeList.includes(t)); - } else; - return false; + updateTagParams(params) { + this.tagFilter = params; }, - - checkAny(filterBy, recipeList) { - if (filterBy.length === 0) return true; - if (recipeList) { - return filterBy.some(t => recipeList.includes(t)); - } else; - return false; - }, - - checkTags(recipeTags) { - if (this.tagFilterType === INCLUDE) { - return this.checkIncludes(this.includeTags, recipeTags); - } - if (this.tagFilterType === EXCLUDE) { - return this.checkExcludes(this.includeTags, recipeTags); - } - if (this.tagFilterType === ANY) { - return this.checkAny(this.includeTags, recipeTags); - } - }, - - checkCategories(recipeCategories) { - if (this.catFilterType === INCLUDE) { - return this.checkIncludes(this.includeCategories, recipeCategories); - } - if (this.catFilterType === EXCLUDE) { - return this.checkExcludes(this.includeCategories, recipeCategories); - } - if (this.catFilterType === ANY) { - return this.checkAny(this.includeCategories, recipeCategories); - } + updateCatParams(params) { + this.catFilter = params; }, }, };