diff options
author | 2019-06-12 15:16:56 +0200 | |
---|---|---|
committer | 2019-06-12 15:16:56 +0200 | |
commit | eba50bc5a41b8492c0350b73936405eab1b8c453 (patch) | |
tree | caac808d019f324fa970dfd721aeb2641dea6609 | |
parent | Update CHANGELOG.md (diff) | |
download | ferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.tar.gz ferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.tar.zst ferdium-app-eba50bc5a41b8492c0350b73936405eab1b8c453.zip |
fix(Recipes): Fix recipe install when directly accessing recipe
-rw-r--r-- | src/stores/RecipesStore.js | 27 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 18 |
2 files changed, 28 insertions, 17 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 | } |
diff --git a/src/stores/ServicesStore.js b/src/stores/ServicesStore.js index d63302fce..109ac5cd7 100644 --- a/src/stores/ServicesStore.js +++ b/src/stores/ServicesStore.js | |||
@@ -148,18 +148,7 @@ export default class ServicesStore extends Store { | |||
148 | } | 148 | } |
149 | 149 | ||
150 | async _showAddServiceInterface({ recipeId }) { | 150 | async _showAddServiceInterface({ recipeId }) { |
151 | const recipesStore = this.stores.recipes; | 151 | this.stores.router.push(`/settings/services/add/${recipeId}`); |
152 | |||
153 | if (recipesStore.isInstalled(recipeId)) { | ||
154 | debug(`Recipe ${recipeId} is installed`); | ||
155 | this._redirectToAddServiceRoute(recipeId); | ||
156 | } else { | ||
157 | debug(`Recipe ${recipeId} is not installed`); | ||
158 | // We access the RecipeStore action directly | ||
159 | // returns Promise instead of action | ||
160 | await this.stores.recipes._install({ recipeId }); | ||
161 | this._redirectToAddServiceRoute(recipeId); | ||
162 | } | ||
163 | } | 152 | } |
164 | 153 | ||
165 | // Actions | 154 | // Actions |
@@ -690,11 +679,6 @@ export default class ServicesStore extends Store { | |||
690 | } | 679 | } |
691 | 680 | ||
692 | // Helper | 681 | // Helper |
693 | _redirectToAddServiceRoute(recipeId) { | ||
694 | const route = `/settings/services/add/${recipeId}`; | ||
695 | this.stores.router.push(route); | ||
696 | } | ||
697 | |||
698 | _initializeServiceRecipeInWebview(serviceId) { | 682 | _initializeServiceRecipeInWebview(serviceId) { |
699 | const service = this.one(serviceId); | 683 | const service = this.one(serviceId); |
700 | 684 | ||