File tree Expand file tree Collapse file tree 2 files changed +28
-17
lines changed Expand file tree Collapse file tree 2 files changed +28
-17
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export default class RecipesStore extends Store {
20
20
// Register action handlers
21
21
this . actions . recipe . install . listen ( this . _install . bind ( this ) ) ;
22
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
30
setup ( ) {
@@ -99,4 +104,26 @@ export default class RecipesStore extends Store {
99
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
}
Original file line number Diff line number Diff line change @@ -148,18 +148,7 @@ export default class ServicesStore extends Store {
148
148
}
149
149
150
150
async _showAddServiceInterface ( { recipeId } ) {
151
- const recipesStore = this . stores . recipes ;
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
- }
151
+ this . stores . router . push ( `/settings/services/add/${ recipeId } ` ) ;
163
152
}
164
153
165
154
// Actions
@@ -690,11 +679,6 @@ export default class ServicesStore extends Store {
690
679
}
691
680
692
681
// Helper
693
- _redirectToAddServiceRoute ( recipeId ) {
694
- const route = `/settings/services/add/${ recipeId } ` ;
695
- this . stores . router . push ( route ) ;
696
- }
697
-
698
682
_initializeServiceRecipeInWebview ( serviceId ) {
699
683
const service = this . one ( serviceId ) ;
700
684
You can’t perform that action at this time.
0 commit comments