diff options
Diffstat (limited to 'src/containers/settings/RecipesScreen.js')
-rw-r--r-- | src/containers/settings/RecipesScreen.js | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/src/containers/settings/RecipesScreen.js b/src/containers/settings/RecipesScreen.js index f12f67b1f..52bf31383 100644 --- a/src/containers/settings/RecipesScreen.js +++ b/src/containers/settings/RecipesScreen.js | |||
@@ -1,11 +1,9 @@ | |||
1 | import { shell } from 'electron'; | 1 | import { shell } from 'electron'; |
2 | import { app } from '@electron/remote'; | 2 | import { ensureDirSync, readJsonSync } from 'fs-extra'; |
3 | import fs from 'fs-extra'; | ||
4 | import React, { Component } from 'react'; | 3 | import React, { Component } from 'react'; |
5 | import PropTypes from 'prop-types'; | 4 | import PropTypes from 'prop-types'; |
6 | import { autorun } from 'mobx'; | 5 | import { autorun } from 'mobx'; |
7 | import { inject, observer } from 'mobx-react'; | 6 | import { inject, observer } from 'mobx-react'; |
8 | import path from 'path'; | ||
9 | 7 | ||
10 | import RecipePreviewsStore from '../../stores/RecipePreviewsStore'; | 8 | import RecipePreviewsStore from '../../stores/RecipePreviewsStore'; |
11 | import RecipeStore from '../../stores/RecipesStore'; | 9 | import RecipeStore from '../../stores/RecipesStore'; |
@@ -15,7 +13,7 @@ import UserStore from '../../stores/UserStore'; | |||
15 | import RecipesDashboard from '../../components/settings/recipes/RecipesDashboard'; | 13 | import RecipesDashboard from '../../components/settings/recipes/RecipesDashboard'; |
16 | import ErrorBoundary from '../../components/util/ErrorBoundary'; | 14 | import ErrorBoundary from '../../components/util/ErrorBoundary'; |
17 | import { CUSTOM_WEBSITE_RECIPE_ID, FRANZ_DEV_DOCS } from '../../config'; | 15 | import { CUSTOM_WEBSITE_RECIPE_ID, FRANZ_DEV_DOCS } from '../../config'; |
18 | import { RECIPES_PATH } from '../../environment'; | 16 | import { asarRecipesPath, userDataRecipesPath } from '../../environment'; |
19 | import { communityRecipesStore } from '../../features/communityRecipes'; | 17 | import { communityRecipesStore } from '../../features/communityRecipes'; |
20 | import RecipePreview from '../../models/RecipePreview'; | 18 | import RecipePreview from '../../models/RecipePreview'; |
21 | import AppStore from '../../stores/AppStore'; | 19 | import AppStore from '../../stores/AppStore'; |
@@ -45,18 +43,16 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
45 | constructor(props) { | 43 | constructor(props) { |
46 | super(props); | 44 | super(props); |
47 | 45 | ||
48 | this.customRecipes = fs.readJsonSync(path.join(RECIPES_PATH, 'all.json')); | 46 | this.customRecipes = readJsonSync(asarRecipesPath('all.json')); |
49 | } | 47 | } |
50 | 48 | ||
51 | componentDidMount() { | 49 | componentDidMount() { |
52 | this.autorunDisposer = autorun(() => { | 50 | this.autorunDisposer = autorun(() => { |
53 | const { filter } = this.props.params; | 51 | const { filter } = { filter: 'all', ...this.props.params }; |
54 | const { currentFilter } = this.state; | 52 | const { currentFilter } = this.state; |
55 | 53 | ||
56 | if (filter === 'all' && currentFilter !== 'all') { | 54 | if (filter === 'all' && currentFilter !== 'all') { |
57 | this.setState({ currentFilter: 'all' }); | 55 | this.setState({ currentFilter: 'all' }); |
58 | } else if (filter === 'featured' && currentFilter !== 'featured') { | ||
59 | this.setState({ currentFilter: 'featured' }); | ||
60 | } else if (filter === 'dev' && currentFilter !== 'dev') { | 56 | } else if (filter === 'dev' && currentFilter !== 'dev') { |
61 | this.setState({ currentFilter: 'dev' }); | 57 | this.setState({ currentFilter: 'dev' }); |
62 | } | 58 | } |
@@ -82,7 +78,7 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
82 | return recipes | 78 | return recipes |
83 | // Filter out duplicate recipes | 79 | // Filter out duplicate recipes |
84 | .filter((recipe, index, self) => { | 80 | .filter((recipe, index, self) => { |
85 | const ids = self.map(rec => rec.id); | 81 | const ids = self.map((rec) => rec.id); |
86 | return ids.indexOf(recipe.id) === index; | 82 | return ids.indexOf(recipe.id) === index; |
87 | 83 | ||
88 | // Sort alphabetically | 84 | // Sort alphabetically |
@@ -95,7 +91,7 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
95 | 91 | ||
96 | // Create an array of RecipePreviews from an array of recipe objects | 92 | // Create an array of RecipePreviews from an array of recipe objects |
97 | createPreviews(recipes) { | 93 | createPreviews(recipes) { |
98 | return recipes.map(recipe => new RecipePreview(recipe)); | 94 | return recipes.map((recipe) => new RecipePreview(recipe)); |
99 | } | 95 | } |
100 | 96 | ||
101 | resetSearch() { | 97 | resetSearch() { |
@@ -107,7 +103,6 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
107 | recipePreviews, | 103 | recipePreviews, |
108 | recipes, | 104 | recipes, |
109 | services, | 105 | services, |
110 | user, | ||
111 | } = this.props.stores; | 106 | } = this.props.stores; |
112 | 107 | ||
113 | const { | 108 | const { |
@@ -115,7 +110,7 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
115 | service: serviceActions, | 110 | service: serviceActions, |
116 | } = this.props.actions; | 111 | } = this.props.actions; |
117 | 112 | ||
118 | const { filter } = this.props.params; | 113 | const { filter } = { filter: 'all', ...this.props.params }; |
119 | let recipeFilter; | 114 | let recipeFilter; |
120 | 115 | ||
121 | if (filter === 'all') { | 116 | if (filter === 'all') { |
@@ -125,8 +120,6 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
125 | ]); | 120 | ]); |
126 | } else if (filter === 'dev') { | 121 | } else if (filter === 'dev') { |
127 | recipeFilter = communityRecipesStore.communityRecipes; | 122 | recipeFilter = communityRecipesStore.communityRecipes; |
128 | } else { | ||
129 | recipeFilter = recipePreviews.featured; | ||
130 | } | 123 | } |
131 | 124 | ||
132 | const allRecipes = this.state.needle ? this.prepareRecipes([ | 125 | const allRecipes = this.state.needle ? this.prepareRecipes([ |
@@ -135,18 +128,17 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
135 | // All search recipes from local recipes | 128 | // All search recipes from local recipes |
136 | ...this.createPreviews( | 129 | ...this.createPreviews( |
137 | this.customRecipes | 130 | this.customRecipes |
138 | .filter(service => service.name.toLowerCase().includes(this.state.needle.toLowerCase())), | 131 | .filter((service) => service.name.toLowerCase().includes(this.state.needle.toLowerCase()) || (service.aliases || []).some(alias => alias.toLowerCase().includes(this.state.needle.toLowerCase()))), |
139 | ), | 132 | ), |
140 | ]) : recipeFilter; | 133 | ]) : recipeFilter; |
141 | 134 | ||
142 | const customWebsiteRecipe = recipePreviews.all.find(service => service.id === CUSTOM_WEBSITE_RECIPE_ID); | 135 | const customWebsiteRecipe = recipePreviews.all.find((service) => service.id === CUSTOM_WEBSITE_RECIPE_ID); |
143 | 136 | ||
144 | const isLoading = recipePreviews.featuredRecipePreviewsRequest.isExecuting | 137 | const isLoading = recipePreviews.allRecipePreviewsRequest.isExecuting |
145 | || recipePreviews.allRecipePreviewsRequest.isExecuting | ||
146 | || recipes.installRecipeRequest.isExecuting | 138 | || recipes.installRecipeRequest.isExecuting |
147 | || recipePreviews.searchRecipePreviewsRequest.isExecuting; | 139 | || recipePreviews.searchRecipePreviewsRequest.isExecuting; |
148 | 140 | ||
149 | const recipeDirectory = path.join(app.getPath('userData'), 'recipes', 'dev'); | 141 | const recipeDirectory = userDataRecipesPath('dev'); |
150 | 142 | ||
151 | return ( | 143 | return ( |
152 | <ErrorBoundary> | 144 | <ErrorBoundary> |
@@ -155,24 +147,20 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend | |||
155 | customWebsiteRecipe={customWebsiteRecipe} | 147 | customWebsiteRecipe={customWebsiteRecipe} |
156 | isLoading={isLoading} | 148 | isLoading={isLoading} |
157 | addedServiceCount={services.all.length} | 149 | addedServiceCount={services.all.length} |
158 | isPremium={user.data.isPremium} | ||
159 | hasLoadedRecipes={recipePreviews.featuredRecipePreviewsRequest.wasExecuted} | ||
160 | showAddServiceInterface={serviceActions.showAddServiceInterface} | 150 | showAddServiceInterface={serviceActions.showAddServiceInterface} |
161 | searchRecipes={e => this.searchRecipes(e)} | 151 | searchRecipes={(e) => this.searchRecipes(e)} |
162 | resetSearch={() => this.resetSearch()} | 152 | resetSearch={() => this.resetSearch()} |
163 | searchNeedle={this.state.needle} | 153 | searchNeedle={this.state.needle} |
164 | serviceStatus={services.actionStatus} | 154 | serviceStatus={services.actionStatus} |
165 | recipeFilter={filter} | 155 | recipeFilter={filter} |
166 | recipeDirectory={recipeDirectory} | 156 | recipeDirectory={recipeDirectory} |
167 | openRecipeDirectory={async () => { | 157 | openRecipeDirectory={async () => { |
168 | await fs.ensureDir(recipeDirectory); | 158 | ensureDirSync(recipeDirectory); |
169 | shell.openExternal(`file://${recipeDirectory}`); | 159 | shell.openExternal(`file://${recipeDirectory}`); |
170 | }} | 160 | }} |
171 | openDevDocs={() => { | 161 | openDevDocs={() => { |
172 | appActions.openExternalUrl({ url: FRANZ_DEV_DOCS }); | 162 | appActions.openExternalUrl({ url: FRANZ_DEV_DOCS }); |
173 | }} | 163 | }} |
174 | isCommunityRecipesIncludedInCurrentPlan={communityRecipesStore.isCommunityRecipesIncludedInCurrentPlan} | ||
175 | isUserPremiumUser={user.isPremium} | ||
176 | /> | 164 | /> |
177 | </ErrorBoundary> | 165 | </ErrorBoundary> |
178 | ); | 166 | ); |