From 44938941629931519211a36aeee41810c34f6aff Mon Sep 17 00:00:00 2001 From: hay-kot Date: Sat, 13 Feb 2021 18:47:41 -0900 Subject: [PATCH] ui improvements + mealplanner search --- frontend/src/App.vue | 1 + frontend/src/api/recipe.js | 21 +++++++---- .../src/components/MealPlan/MealPlanNew.vue | 9 +++-- frontend/src/components/UI/RecipeCard.vue | 36 +++++++++++++------ frontend/src/components/UI/SearchBar.vue | 19 ++++++---- frontend/src/components/UI/SearchDialog.vue | 5 +-- frontend/src/store/modules/homePage.js | 2 +- frontend/src/store/store.js | 1 - mealie/db/db_base.py | 12 +++++-- mealie/routes/recipe/all_recipe_routes.py | 23 ++++++++---- mealie/routes/recipe/recipe_crud_routes.py | 6 ++-- 11 files changed, 93 insertions(+), 42 deletions(-) diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 31f1429da..0caaacc0c 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -150,4 +150,5 @@ export default { *::-webkit-scrollbar-thumb { background: grey; } + diff --git a/frontend/src/api/recipe.js b/frontend/src/api/recipe.js index c882e6c21..68b674b78 100644 --- a/frontend/src/api/recipe.js +++ b/frontend/src/api/recipe.js @@ -8,13 +8,14 @@ const prefix = baseURL + "recipes/"; const recipeURLs = { allRecipes: baseURL + "recipes", + allRecipesByCategory: prefix + "category", create: prefix + "create", createByURL: prefix + "create-url", - recipe: (slug) => prefix + slug, - update: (slug) => prefix + slug, - delete: (slug) => prefix + slug, - recipeImage: (slug) => `${prefix}${slug}/image`, - updateImage: (slug) => `${prefix}${slug}/image`, + recipe: slug => prefix + slug, + update: slug => prefix + slug, + delete: slug => prefix + slug, + recipeImage: slug => `${prefix}${slug}/image`, + updateImage: slug => `${prefix}${slug}/image`, }; export default { @@ -27,6 +28,14 @@ export default { return response; }, + async getAllByCategory(categories) { + let response = await apiReq.post( + recipeURLs.allRecipesByCategory, + categories + ); + return response.data; + }, + async create(recipeData) { let response = await apiReq.post(recipeURLs.create, recipeData); return response.data; @@ -67,7 +76,7 @@ export default { keys: recipeKeys, num: num, }, - paramsSerializer: (params) => { + paramsSerializer: params => { return qs.stringify(params, { arrayFormat: "repeat" }); }, }); diff --git a/frontend/src/components/MealPlan/MealPlanNew.vue b/frontend/src/components/MealPlan/MealPlanNew.vue index af16cd9bb..1af227f21 100644 --- a/frontend/src/components/MealPlan/MealPlanNew.vue +++ b/frontend/src/components/MealPlan/MealPlanNew.vue @@ -96,6 +96,7 @@ export default { return { isLoading: false, meals: [], + items: [], // Dates startDate: null, @@ -117,11 +118,13 @@ export default { } }, }, + async mounted() { + let settings = await api.settings.requestAll(); + console.log(settings); + this.items = await api.recipes.getAllByCategory(settings.planCategories); + }, computed: { - items() { - return this.$store.getters.getRecentRecipes; - }, actualStartDate() { return Date.parse(this.startDate); }, diff --git a/frontend/src/components/UI/RecipeCard.vue b/frontend/src/components/UI/RecipeCard.vue index 5bf3ffb6a..ad688f2c7 100644 --- a/frontend/src/components/UI/RecipeCard.vue +++ b/frontend/src/components/UI/RecipeCard.vue @@ -6,7 +6,19 @@ :to="route ? `/recipe/${slug}` : ''" @click="$emit('click')" > - + + +
+ + {{ description }} + +
+
+
{{ name | truncate(30) }} @@ -23,16 +35,7 @@ > - - - - {{ description }} - - + @@ -61,4 +64,15 @@ export default { \ No newline at end of file diff --git a/frontend/src/components/UI/SearchBar.vue b/frontend/src/components/UI/SearchBar.vue index 0ddc4e8f7..4d80f4d0d 100644 --- a/frontend/src/components/UI/SearchBar.vue +++ b/frontend/src/components/UI/SearchBar.vue @@ -57,6 +57,7 @@ export default { return { searchSlug: "", search: " ", + data: [], result: [], autoResults: [], isDark: false, @@ -67,27 +68,31 @@ export default { distance: 100, maxPatternLength: 32, minMatchCharLength: 1, - keys: ["name", "slug"], + keys: ["name", "slug", "description"], }, }; }, mounted() { this.isDark = this.$store.getters.getIsDark; + this.data = this.$store.getters.getRecentRecipes; }, computed: { - data() { - return this.$store.getters.getRecentRecipes; - }, fuse() { return new Fuse(this.data, this.options); }, }, watch: { search() { - if (this.search.trim() === "") this.result = this.list; - else this.result = this.fuse.search(this.search.trim()); - + try { + this.result = this.fuse.search(this.search.trim()); + } catch { + this.result = this.data + .map(x => ({ item: x })) + .sort((a, b) => (a.name > b.name ? 1 : -1)); + } + console.log(this.result); this.$emit("results", this.result); + if (this.showResults === true) { this.autoResults = this.result; } diff --git a/frontend/src/components/UI/SearchDialog.vue b/frontend/src/components/UI/SearchDialog.vue index 8874736bf..30d270d6e 100644 --- a/frontend/src/components/UI/SearchDialog.vue +++ b/frontend/src/components/UI/SearchDialog.vue @@ -1,6 +1,6 @@