diff options
m--------- | recipes | 0 | ||||
-rw-r--r-- | src/containers/settings/RecipesScreen.js | 39 |
2 files changed, 37 insertions, 2 deletions
diff --git a/recipes b/recipes | |||
Subproject bd8c25be7961d167d315e76276627306b2379dc | Subproject 6471ed12a2fb76b4a13a8e2c2a32c4aba495b44 | ||
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 |