From eba50bc5a41b8492c0350b73936405eab1b8c453 Mon Sep 17 00:00:00 2001 From: Stefan Malzner Date: Wed, 12 Jun 2019 15:16:56 +0200 Subject: fix(Recipes): Fix recipe install when directly accessing recipe --- src/stores/RecipesStore.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/stores/RecipesStore.js') 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 { // Register action handlers this.actions.recipe.install.listen(this._install.bind(this)); this.actions.recipe.update.listen(this._update.bind(this)); + + // Reactions + this.registerReactions([ + this._checkIfRecipeIsInstalled.bind(this), + ]); } setup() { @@ -99,4 +104,26 @@ export default class RecipesStore extends Store { syncUpdate(0); } } + + async _checkIfRecipeIsInstalled() { + const { router } = this.stores; + + const match = matchRoute('/settings/services/add/:id', router.location.pathname); + if (match) { + const recipeId = match.id; + + if (!this.stores.recipes.isInstalled(recipeId)) { + router.push('/settings/recipes'); + debug(`Recipe ${recipeId} is not installed, trying to install it`); + + const recipe = await this.installRecipeRequest.execute(recipeId)._promise; + if (recipe) { + await this.allRecipesRequest.invalidate({ immediately: true })._promise; + router.push(`/settings/services/add/${recipeId}`); + } else { + router.push('/settings/recipes'); + } + } + } + } } -- cgit v1.2.3-70-g09d2