Skip to content

Commit

Permalink
fix(Recipes): Fix recipe install when directly accessing recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Jun 12, 2019
1 parent 1075df8 commit eba50bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
27 changes: 27 additions & 0 deletions src/stores/RecipesStore.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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');
}
}
}
}
}
18 changes: 1 addition & 17 deletions src/stores/ServicesStore.js
Expand Up @@ -148,18 +148,7 @@ export default class ServicesStore extends Store {
}

async _showAddServiceInterface({ recipeId }) {
const recipesStore = this.stores.recipes;

if (recipesStore.isInstalled(recipeId)) {
debug(`Recipe ${recipeId} is installed`);
this._redirectToAddServiceRoute(recipeId);
} else {
debug(`Recipe ${recipeId} is not installed`);
// We access the RecipeStore action directly
// returns Promise instead of action
await this.stores.recipes._install({ recipeId });
this._redirectToAddServiceRoute(recipeId);
}
this.stores.router.push(`/settings/services/add/${recipeId}`);
}

// Actions
Expand Down Expand Up @@ -690,11 +679,6 @@ export default class ServicesStore extends Store {
}

// Helper
_redirectToAddServiceRoute(recipeId) {
const route = `/settings/services/add/${recipeId}`;
this.stores.router.push(route);
}

_initializeServiceRecipeInWebview(serviceId) {
const service = this.one(serviceId);

Expand Down

0 comments on commit eba50bc

Please sign in to comment.