diff options
author | 2019-06-13 15:48:23 +0200 | |
---|---|---|
committer | 2019-06-13 15:48:23 +0200 | |
commit | e5fbcfc9eb02a1cbb1c5876a3c1a01f79ad15180 (patch) | |
tree | 676d3c5478a7279d3cf510ad3f620ed2d3a76491 /src/stores | |
parent | Add custom recipe limitation (diff) | |
parent | Merge branch 'release/5.2.0-beta.2' (diff) | |
download | ferdium-app-e5fbcfc9eb02a1cbb1c5876a3c1a01f79ad15180.tar.gz ferdium-app-e5fbcfc9eb02a1cbb1c5876a3c1a01f79ad15180.tar.zst ferdium-app-e5fbcfc9eb02a1cbb1c5876a3c1a01f79ad15180.zip |
Merge branch 'develop' into feature/3rd-party-limit
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/GlobalErrorStore.js | 7 | ||||
-rw-r--r-- | src/stores/NewsStore.js | 12 | ||||
-rw-r--r-- | src/stores/RecipesStore.js | 27 | ||||
-rw-r--r-- | src/stores/ServicesStore.js | 32 | ||||
-rw-r--r-- | src/stores/UserStore.js | 3 |
5 files changed, 58 insertions, 23 deletions
diff --git a/src/stores/GlobalErrorStore.js b/src/stores/GlobalErrorStore.js index 90bf751c3..7a85c2daa 100644 --- a/src/stores/GlobalErrorStore.js +++ b/src/stores/GlobalErrorStore.js | |||
@@ -18,8 +18,11 @@ export default class GlobalErrorStore extends Store { | |||
18 | this.error = request.error; | 18 | this.error = request.error; |
19 | 19 | ||
20 | if (request.error.json) { | 20 | if (request.error.json) { |
21 | this.response = await request.error.json(); | 21 | try { |
22 | 22 | this.response = await request.error.json(); | |
23 | } catch (error) { | ||
24 | this.response = {}; | ||
25 | } | ||
23 | if (this.error.status === 401) { | 26 | if (this.error.status === 401) { |
24 | this.actions.user.logout({ serverLogout: true }); | 27 | this.actions.user.logout({ serverLogout: true }); |
25 | } | 28 | } |
diff --git a/src/stores/NewsStore.js b/src/stores/NewsStore.js index 6984425df..86e092592 100644 --- a/src/stores/NewsStore.js +++ b/src/stores/NewsStore.js | |||
@@ -16,6 +16,7 @@ export default class NewsStore extends Store { | |||
16 | 16 | ||
17 | // Register action handlers | 17 | // Register action handlers |
18 | this.actions.news.hide.listen(this._hide.bind(this)); | 18 | this.actions.news.hide.listen(this._hide.bind(this)); |
19 | this.actions.user.logout.listen(this._resetNewsRequest.bind(this)); | ||
19 | } | 20 | } |
20 | 21 | ||
21 | setup() { | 22 | setup() { |
@@ -40,4 +41,15 @@ export default class NewsStore extends Store { | |||
40 | remove(result, n => n.id === newsId); | 41 | remove(result, n => n.id === newsId); |
41 | }); | 42 | }); |
42 | } | 43 | } |
44 | |||
45 | /** | ||
46 | * Reset the news request when current user logs out so that when another user | ||
47 | * logs in again without an app restart, the request will be fetched again and | ||
48 | * the news will be shown to the user. | ||
49 | * | ||
50 | * @private | ||
51 | */ | ||
52 | _resetNewsRequest() { | ||
53 | this.latestNewsRequest.reset(); | ||
54 | } | ||
43 | } | 55 | } |
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 13f929c2f..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 |
@@ -291,7 +280,8 @@ export default class ServicesStore extends Store { | |||
291 | gaEvent('Service', 'clear cache'); | 280 | gaEvent('Service', 'clear cache'); |
292 | } | 281 | } |
293 | 282 | ||
294 | @action _setActive({ serviceId }) { | 283 | @action _setActive({ serviceId, keepActiveRoute }) { |
284 | if (!keepActiveRoute) this.stores.router.push('/'); | ||
295 | const service = this.one(serviceId); | 285 | const service = this.one(serviceId); |
296 | 286 | ||
297 | this.all.forEach((s, index) => { | 287 | this.all.forEach((s, index) => { |
@@ -517,7 +507,16 @@ export default class ServicesStore extends Store { | |||
517 | this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false }); | 507 | this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false }); |
518 | } | 508 | } |
519 | 509 | ||
520 | @action _reorder({ oldIndex, newIndex }) { | 510 | @action _reorder(params) { |
511 | const { workspaces } = this.stores; | ||
512 | if (workspaces.isAnyWorkspaceActive) { | ||
513 | workspaces.reorderServicesOfActiveWorkspace(params); | ||
514 | } else { | ||
515 | this._reorderService(params); | ||
516 | } | ||
517 | } | ||
518 | |||
519 | @action _reorderService({ oldIndex, newIndex }) { | ||
521 | const showDisabledServices = this.stores.settings.all.app.showDisabledServices; | 520 | const showDisabledServices = this.stores.settings.all.app.showDisabledServices; |
522 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); | 521 | const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); |
523 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); | 522 | const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); |
@@ -680,11 +679,6 @@ export default class ServicesStore extends Store { | |||
680 | } | 679 | } |
681 | 680 | ||
682 | // Helper | 681 | // Helper |
683 | _redirectToAddServiceRoute(recipeId) { | ||
684 | const route = `/settings/services/add/${recipeId}`; | ||
685 | this.stores.router.push(route); | ||
686 | } | ||
687 | |||
688 | _initializeServiceRecipeInWebview(serviceId) { | 682 | _initializeServiceRecipeInWebview(serviceId) { |
689 | const service = this.one(serviceId); | 683 | const service = this.one(serviceId); |
690 | 684 | ||
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 31555dd5c..b5423af3b 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -329,8 +329,7 @@ export default class UserStore extends Store { | |||
329 | authToken, | 329 | authToken, |
330 | }); | 330 | }); |
331 | } catch (err) { | 331 | } catch (err) { |
332 | console.error('AccessToken Invalid'); | 332 | this._logout(); |
333 | |||
334 | return false; | 333 | return false; |
335 | } | 334 | } |
336 | } | 335 | } |