aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/settings/RecipesScreen.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/containers/settings/RecipesScreen.js')
-rw-r--r--src/containers/settings/RecipesScreen.js51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/containers/settings/RecipesScreen.js b/src/containers/settings/RecipesScreen.js
index 132820b6f..70b599d9c 100644
--- a/src/containers/settings/RecipesScreen.js
+++ b/src/containers/settings/RecipesScreen.js
@@ -1,4 +1,5 @@
1import { remote, shell } from 'electron'; 1import { remote, shell } from 'electron';
2import fs from 'fs-extra';
2import React, { Component } from 'react'; 3import React, { Component } from 'react';
3import PropTypes from 'prop-types'; 4import PropTypes from 'prop-types';
4import { autorun } from 'mobx'; 5import { autorun } from 'mobx';
@@ -12,9 +13,9 @@ import UserStore from '../../stores/UserStore';
12 13
13import RecipesDashboard from '../../components/settings/recipes/RecipesDashboard'; 14import RecipesDashboard from '../../components/settings/recipes/RecipesDashboard';
14import ErrorBoundary from '../../components/util/ErrorBoundary'; 15import ErrorBoundary from '../../components/util/ErrorBoundary';
15import { FRANZ_DEV_DOCS } from '../../config'; 16import { FRANZ_DEV_DOCS, RECIPES_PATH } from '../../config';
16import { gaEvent } from '../../lib/analytics';
17import { communityRecipesStore } from '../../features/communityRecipes'; 17import { communityRecipesStore } from '../../features/communityRecipes';
18import RecipePreview from '../../models/RecipePreview';
18 19
19const { app } = remote; 20const { app } = remote;
20 21
@@ -38,6 +39,14 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
38 39
39 autorunDisposer = null; 40 autorunDisposer = null;
40 41
42 customRecipes = [];
43
44 constructor(props) {
45 super(props);
46
47 this.customRecipes = fs.readJsonSync(path.join(RECIPES_PATH, 'all.json'));
48 }
49
41 componentDidMount() { 50 componentDidMount() {
42 this.autorunDisposer = autorun(() => { 51 this.autorunDisposer = autorun(() => {
43 const { filter } = this.props.params; 52 const { filter } = this.props.params;
@@ -68,6 +77,27 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
68 } 77 }
69 } 78 }
70 79
80
81 prepareRecipes(recipes) {
82 return recipes
83 // Filter out duplicate recipes
84 .filter((recipe, index, self) => {
85 const ids = self.map(rec => rec.id);
86 return ids.indexOf(recipe.id) === index;
87
88 // Sort alphabetically
89 }).sort((a, b) => {
90 if (a.id < b.id) { return -1; }
91 if (a.id > b.id) { return 1; }
92 return 0;
93 });
94 }
95
96 // Create an array of RecipePreviews from an array of recipe objects
97 createPreviews(recipes) {
98 return recipes.map(recipe => new RecipePreview(recipe));
99 }
100
71 resetSearch() { 101 resetSearch() {
72 this.setState({ needle: null }); 102 this.setState({ needle: null });
73 } 103 }
@@ -89,14 +119,25 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
89 let recipeFilter; 119 let recipeFilter;
90 120
91 if (filter === 'all') { 121 if (filter === 'all') {
92 recipeFilter = recipePreviews.all; 122 recipeFilter = this.prepareRecipes([
123 ...recipePreviews.all,
124 ...this.createPreviews(this.customRecipes),
125 ]);
93 } else if (filter === 'dev') { 126 } else if (filter === 'dev') {
94 recipeFilter = communityRecipesStore.communityRecipes; 127 recipeFilter = communityRecipesStore.communityRecipes;
95 } else { 128 } else {
96 recipeFilter = recipePreviews.featured; 129 recipeFilter = recipePreviews.featured;
97 } 130 }
98 131
99 const allRecipes = this.state.needle ? recipePreviews.searchResults : recipeFilter; 132 const allRecipes = this.state.needle ? this.prepareRecipes([
133 // All search recipes from server
134 ...recipePreviews.searchResults,
135 // All search recipes from local recipes
136 ...this.createPreviews(
137 this.customRecipes
138 .filter(service => service.name.toLowerCase().includes(this.state.needle.toLowerCase())),
139 ),
140 ]) : recipeFilter;
100 141
101 const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting 142 const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting
102 || recipePreviews.allRecipePreviewsRequest.isExecuting 143 || recipePreviews.allRecipePreviewsRequest.isExecuting
@@ -122,11 +163,9 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
122 recipeDirectory={recipeDirectory} 163 recipeDirectory={recipeDirectory}
123 openRecipeDirectory={() => { 164 openRecipeDirectory={() => {
124 shell.openItem(recipeDirectory); 165 shell.openItem(recipeDirectory);
125 gaEvent('Recipe', 'open-recipe-folder', 'Open Folder');
126 }} 166 }}
127 openDevDocs={() => { 167 openDevDocs={() => {
128 appActions.openExternalUrl({ url: FRANZ_DEV_DOCS }); 168 appActions.openExternalUrl({ url: FRANZ_DEV_DOCS });
129 gaEvent('Recipe', 'open-dev-docs', 'Developer Documentation');
130 }} 169 }}
131 isCommunityRecipesIncludedInCurrentPlan={communityRecipesStore.isCommunityRecipesIncludedInCurrentPlan} 170 isCommunityRecipesIncludedInCurrentPlan={communityRecipesStore.isCommunityRecipesIncludedInCurrentPlan}
132 isUserPremiumUser={user.isPremium} 171 isUserPremiumUser={user.isPremium}