diff options
author | 2019-09-26 11:52:54 +0200 | |
---|---|---|
committer | 2019-09-26 11:52:54 +0200 | |
commit | e7e0e4548a0531c8c7b7992050c0a2c76e8486d6 (patch) | |
tree | 796f69a3e812776464d47a9b000fa26eeea8a4bf /src/containers | |
parent | Add note on how-to clone repository with submodule (diff) | |
download | ferdium-app-e7e0e4548a0531c8c7b7992050c0a2c76e8486d6.tar.gz ferdium-app-e7e0e4548a0531c8c7b7992050c0a2c76e8486d6.tar.zst ferdium-app-e7e0e4548a0531c8c7b7992050c0a2c76e8486d6.zip |
Add local recipes to recipe list
Diffstat (limited to 'src/containers')
-rw-r--r-- | src/containers/settings/RecipesScreen.js | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/containers/settings/RecipesScreen.js b/src/containers/settings/RecipesScreen.js index 692dc26f1..813c008f1 100644 --- a/src/containers/settings/RecipesScreen.js +++ b/src/containers/settings/RecipesScreen.js | |||
@@ -14,6 +14,9 @@ import RecipesDashboard from '../../components/settings/recipes/RecipesDashboard | |||
14 | import ErrorBoundary from '../../components/util/ErrorBoundary'; | 14 | import ErrorBoundary from '../../components/util/ErrorBoundary'; |
15 | import { FRANZ_DEV_DOCS } from '../../config'; | 15 | import { FRANZ_DEV_DOCS } from '../../config'; |
16 | import { communityRecipesStore } from '../../features/communityRecipes'; | 16 | import { communityRecipesStore } from '../../features/communityRecipes'; |
17 | import RecipePreview from '../../models/RecipePreview'; | ||
18 | |||
19 | import allFerdiRecipes from '../../../recipes/all.json' | ||
17 | 20 | ||
18 | const { app } = remote; | 21 | const { app } = remote; |
19 | 22 | ||
@@ -67,6 +70,27 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
67 | } | 70 | } |
68 | } | 71 | } |
69 | 72 | ||
73 | |||
74 | prepareRecipes(recipes) { | ||
75 | return recipes | ||
76 | // Filter out duplicate recipes | ||
77 | .filter((recipe, index, self) => { | ||
78 | const ids = self.map(rec => rec.id); | ||
79 | return ids.indexOf(recipe.id) === index; | ||
80 | |||
81 | // Sort alphabetically | ||
82 | }).sort((a, b) => { | ||
83 | if(a.id < b.id) { return -1; } | ||
84 | if(a.id > b.id) { return 1; } | ||
85 | return 0; | ||
86 | }); | ||
87 | } | ||
88 | |||
89 | // Create an array of RecipePreviews from an array of recipe objects | ||
90 | createPreviews(recipes) { | ||
91 | return recipes.map(recipe => new RecipePreview(recipe)); | ||
92 | } | ||
93 | |||
70 | resetSearch() { | 94 | resetSearch() { |
71 | this.setState({ needle: null }); | 95 | this.setState({ needle: null }); |
72 | } | 96 | } |
@@ -88,14 +112,25 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
88 | let recipeFilter; | 112 | let recipeFilter; |
89 | 113 | ||
90 | if (filter === 'all') { | 114 | if (filter === 'all') { |
91 | recipeFilter = recipePreviews.all; | 115 | recipeFilter = this.prepareRecipes([ |
116 | ...recipePreviews.all, | ||
117 | ...this.createPreviews(allFerdiRecipes) | ||
118 | ]) | ||
92 | } else if (filter === 'dev') { | 119 | } else if (filter === 'dev') { |
93 | recipeFilter = communityRecipesStore.communityRecipes; | 120 | recipeFilter = communityRecipesStore.communityRecipes; |
94 | } else { | 121 | } else { |
95 | recipeFilter = recipePreviews.featured; | 122 | recipeFilter = recipePreviews.featured; |
96 | } | 123 | } |
97 | 124 | ||
98 | const allRecipes = this.state.needle ? recipePreviews.searchResults : recipeFilter; | 125 | const allRecipes = this.state.needle ? this.prepareRecipes([ |
126 | // All search recipes from server | ||
127 | ...recipePreviews.searchResults, | ||
128 | // All search recipes from local recipes | ||
129 | ...this.createPreviews( | ||
130 | allFerdiRecipes | ||
131 | .filter(service => service.name.toLowerCase().includes(this.state.needle.toLowerCase())) | ||
132 | ) | ||
133 | ]) : recipeFilter; | ||
99 | 134 | ||
100 | const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting | 135 | const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting |
101 | || recipePreviews.allRecipePreviewsRequest.isExecuting | 136 | || recipePreviews.allRecipePreviewsRequest.isExecuting |