aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/RecipesStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-06-12 15:16:56 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-06-12 15:16:56 +0200
commiteba50bc5a41b8492c0350b73936405eab1b8c453 (patch)
treecaac808d019f324fa970dfd721aeb2641dea6609 /src/stores/RecipesStore.js
parentUpdate CHANGELOG.md (diff)
downloadferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.tar.gz
ferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.tar.zst
ferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.zip
fix(Recipes): Fix recipe install when directly accessing recipe
Diffstat (limited to 'src/stores/RecipesStore.js')
-rw-r--r--src/stores/RecipesStore.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/stores/RecipesStore.js b/src/stores/RecipesStore.js
index ab64bf79c..d51192078 100644
--- a/src/stores/RecipesStore.js
+++ b/src/stores/RecipesStore.js
@@ -20,6 +20,11 @@ export default class RecipesStore extends Store {
20 // Register action handlers 20 // Register action handlers
21 this.actions.recipe.install.listen(this._install.bind(this)); 21 this.actions.recipe.install.listen(this._install.bind(this));
22 this.actions.recipe.update.listen(this._update.bind(this)); 22 this.actions.recipe.update.listen(this._update.bind(this));
23
24 // Reactions
25 this.registerReactions([
26 this._checkIfRecipeIsInstalled.bind(this),
27 ]);
23 } 28 }
24 29
25 setup() { 30 setup() {
@@ -99,4 +104,26 @@ export default class RecipesStore extends Store {
99 syncUpdate(0); 104 syncUpdate(0);
100 } 105 }
101 } 106 }
107
108 async _checkIfRecipeIsInstalled() {
109 const { router } = this.stores;
110
111 const match = matchRoute('/settings/services/add/:id', router.location.pathname);
112 if (match) {
113 const recipeId = match.id;
114
115 if (!this.stores.recipes.isInstalled(recipeId)) {
116 router.push('/settings/recipes');
117 debug(`Recipe ${recipeId} is not installed, trying to install it`);
118
119 const recipe = await this.installRecipeRequest.execute(recipeId)._promise;
120 if (recipe) {
121 await this.allRecipesRequest.invalidate({ immediately: true })._promise;
122 router.push(`/settings/services/add/${recipeId}`);
123 } else {
124 router.push('/settings/recipes');
125 }
126 }
127 }
128 }
102} 129}