File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export default class RecipesStore extends Store {
2020 // Register action handlers
2121 this . actions . recipe . install . listen ( this . _install . bind ( this ) ) ;
2222 this . actions . recipe . update . listen ( this . _update . bind ( this ) ) ;
23+
24+ // Reactions
25+ this . registerReactions ( [
26+ this . _checkIfRecipeIsInstalled . bind ( this ) ,
27+ ] ) ;
2328 }
2429
2530 setup ( ) {
@@ -99,4 +104,26 @@ export default class RecipesStore extends Store {
99104 syncUpdate ( 0 ) ;
100105 }
101106 }
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+ }
102129}
Original file line number Diff line number Diff line change @@ -148,18 +148,7 @@ export default class ServicesStore extends Store {
148148 }
149149
150150 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 } ` ) ;
163152 }
164153
165154 // Actions
@@ -690,11 +679,6 @@ export default class ServicesStore extends Store {
690679 }
691680
692681 // Helper
693- _redirectToAddServiceRoute ( recipeId ) {
694- const route = `/settings/services/add/${ recipeId } ` ;
695- this . stores . router . push ( route ) ;
696- }
697-
698682 _initializeServiceRecipeInWebview ( serviceId ) {
699683 const service = this . one ( serviceId ) ;
700684
You can’t perform that action at this time.
0 commit comments