aboutsummaryrefslogtreecommitdiffstats
path: root/src/containers/settings/RecipesScreen.js
diff options
context:
space:
mode:
authorLibravatar Markus Hatvan <markus_hatvan@aon.at>2021-09-13 14:45:46 +0200
committerLibravatar GitHub <noreply@github.com>2021-09-13 14:45:46 +0200
commit537697a6e9757f118d09d9e76362ba1ff617e2c6 (patch)
treebc55447115e385137684e84697a8c15d2199b8d5 /src/containers/settings/RecipesScreen.js
parentBumped up version to: 5.6.3-nightly.0 [skip ci] (diff)
downloadferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.tar.gz
ferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.tar.zst
ferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.zip
chore: upgrade intl dependencies (#1920)
Diffstat (limited to 'src/containers/settings/RecipesScreen.js')
-rw-r--r--src/containers/settings/RecipesScreen.js92
1 files changed, 55 insertions, 37 deletions
diff --git a/src/containers/settings/RecipesScreen.js b/src/containers/settings/RecipesScreen.js
index 784052bbe..06ddabe4c 100644
--- a/src/containers/settings/RecipesScreen.js
+++ b/src/containers/settings/RecipesScreen.js
@@ -18,7 +18,9 @@ import RecipePreview from '../../models/RecipePreview';
18import AppStore from '../../stores/AppStore'; 18import AppStore from '../../stores/AppStore';
19import { openPath } from '../../helpers/url-helpers'; 19import { openPath } from '../../helpers/url-helpers';
20 20
21export default @inject('stores', 'actions') @observer class RecipesScreen extends Component { 21@inject('stores', 'actions')
22@observer
23class RecipesScreen extends Component {
22 static propTypes = { 24 static propTypes = {
23 params: PropTypes.shape({ 25 params: PropTypes.shape({
24 filter: PropTypes.string, 26 filter: PropTypes.string,
@@ -75,25 +77,32 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
75 } 77 }
76 78
77 _sortByName(recipe1, recipe2) { 79 _sortByName(recipe1, recipe2) {
78 if (recipe1.name.toLowerCase() < recipe2.name.toLowerCase()) { return -1; } 80 if (recipe1.name.toLowerCase() < recipe2.name.toLowerCase()) {
79 if (recipe1.name.toLowerCase() > recipe2.name.toLowerCase()) { return 1; } 81 return -1;
82 }
83 if (recipe1.name.toLowerCase() > recipe2.name.toLowerCase()) {
84 return 1;
85 }
80 return 0; 86 return 0;
81 } 87 }
82 88
83 prepareRecipes(recipes) { 89 prepareRecipes(recipes) {
84 return recipes 90 return (
85 // Filter out duplicate recipes 91 recipes
86 .filter((recipe, index, self) => { 92 // Filter out duplicate recipes
87 const ids = self.map((rec) => rec.id); 93 .filter((recipe, index, self) => {
88 return ids.indexOf(recipe.id) === index; 94 const ids = self.map(rec => rec.id);
89 95 return ids.indexOf(recipe.id) === index;
90 // Sort alphabetically 96
91 }).sort(this._sortByName); 97 // Sort alphabetically
98 })
99 .sort(this._sortByName)
100 );
92 } 101 }
93 102
94 // Create an array of RecipePreviews from an array of recipe objects 103 // Create an array of RecipePreviews from an array of recipe objects
95 createPreviews(recipes) { 104 createPreviews(recipes) {
96 return recipes.map((recipe) => new RecipePreview(recipe)); 105 return recipes.map(recipe => new RecipePreview(recipe));
97 } 106 }
98 107
99 resetSearch() { 108 resetSearch() {
@@ -101,16 +110,9 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
101 } 110 }
102 111
103 render() { 112 render() {
104 const { 113 const { recipePreviews, recipes, services } = this.props.stores;
105 recipePreviews,
106 recipes,
107 services,
108 } = this.props.stores;
109 114
110 const { 115 const { app: appActions, service: serviceActions } = this.props.actions;
111 app: appActions,
112 service: serviceActions,
113 } = this.props.actions;
114 116
115 const { filter } = { filter: 'all', ...this.props.params }; 117 const { filter } = { filter: 'all', ...this.props.params };
116 let recipeFilter; 118 let recipeFilter;
@@ -125,21 +127,33 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
125 } 127 }
126 recipeFilter = recipeFilter.sort(this._sortByName); 128 recipeFilter = recipeFilter.sort(this._sortByName);
127 129
128 const allRecipes = this.state.needle ? this.prepareRecipes([ 130 const allRecipes = this.state.needle
129 // All search recipes from server 131 ? this.prepareRecipes([
130 ...recipePreviews.searchResults, 132 // All search recipes from server
131 // All search recipes from local recipes 133 ...recipePreviews.searchResults,
132 ...this.createPreviews( 134 // All search recipes from local recipes
133 this.customRecipes 135 ...this.createPreviews(
134 .filter((service) => service.name.toLowerCase().includes(this.state.needle.toLowerCase()) || (service.aliases || []).some(alias => alias.toLowerCase().includes(this.state.needle.toLowerCase()))), 136 this.customRecipes.filter(
135 ), 137 service =>
136 ]).sort(this._sortByName) : recipeFilter; 138 service.name
137 139 .toLowerCase()
138 const customWebsiteRecipe = recipePreviews.all.find((service) => service.id === CUSTOM_WEBSITE_RECIPE_ID); 140 .includes(this.state.needle.toLowerCase()) ||
141 (service.aliases || []).some(alias =>
142 alias.toLowerCase().includes(this.state.needle.toLowerCase()),
143 ),
144 ),
145 ),
146 ]).sort(this._sortByName)
147 : recipeFilter;
148
149 const customWebsiteRecipe = recipePreviews.all.find(
150 service => service.id === CUSTOM_WEBSITE_RECIPE_ID,
151 );
139 152
140 const isLoading = recipePreviews.allRecipePreviewsRequest.isExecuting 153 const isLoading =
141 || recipes.installRecipeRequest.isExecuting 154 recipePreviews.allRecipePreviewsRequest.isExecuting ||
142 || recipePreviews.searchRecipePreviewsRequest.isExecuting; 155 recipes.installRecipeRequest.isExecuting ||
156 recipePreviews.searchRecipePreviewsRequest.isExecuting;
143 157
144 const recipeDirectory = userDataRecipesPath('dev'); 158 const recipeDirectory = userDataRecipesPath('dev');
145 159
@@ -151,14 +165,16 @@ export default @inject('stores', 'actions') @observer class RecipesScreen extend
151 isLoading={isLoading} 165 isLoading={isLoading}
152 addedServiceCount={services.all.length} 166 addedServiceCount={services.all.length}
153 showAddServiceInterface={serviceActions.showAddServiceInterface} 167 showAddServiceInterface={serviceActions.showAddServiceInterface}
154 searchRecipes={(e) => this.searchRecipes(e)} 168 searchRecipes={e => this.searchRecipes(e)}
155 resetSearch={() => this.resetSearch()} 169 resetSearch={() => this.resetSearch()}
156 searchNeedle={this.state.needle} 170 searchNeedle={this.state.needle}
157 serviceStatus={services.actionStatus} 171 serviceStatus={services.actionStatus}
158 recipeFilter={filter} 172 recipeFilter={filter}
159 recipeDirectory={recipeDirectory} 173 recipeDirectory={recipeDirectory}
160 openRecipeDirectory={() => openPath(recipeDirectory)} 174 openRecipeDirectory={() => openPath(recipeDirectory)}
161 openDevDocs={() => appActions.openExternalUrl({ url: FRANZ_DEV_DOCS })} 175 openDevDocs={() =>
176 appActions.openExternalUrl({ url: FRANZ_DEV_DOCS })
177 }
162 /> 178 />
163 </ErrorBoundary> 179 </ErrorBoundary>
164 ); 180 );
@@ -180,3 +196,5 @@ RecipesScreen.wrappedComponent.propTypes = {
180 }).isRequired, 196 }).isRequired,
181 }).isRequired, 197 }).isRequired,
182}; 198};
199
200export default RecipesScreen;