aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2019-06-13 13:22:27 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2019-06-13 13:22:27 +0200
commitf65677735b02326870ada2100b55222fa69a401d (patch)
tree53adfc38c0a493e5e8fef3211d0e82b7d164d9ff /src/stores
parentEnforce service limit (diff)
parentMerge branch 'release/5.2.0-beta.2' (diff)
downloadferdium-app-f65677735b02326870ada2100b55222fa69a401d.tar.gz
ferdium-app-f65677735b02326870ada2100b55222fa69a401d.tar.zst
ferdium-app-f65677735b02326870ada2100b55222fa69a401d.zip
Merge branch 'develop' into feature/service-limit
Diffstat (limited to 'src/stores')
-rw-r--r--src/stores/GlobalErrorStore.js7
-rw-r--r--src/stores/NewsStore.js12
-rw-r--r--src/stores/RecipesStore.js27
-rw-r--r--src/stores/ServicesStore.js32
-rw-r--r--src/stores/UserStore.js3
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 349de2c9b..ee47bf6db 100644
--- a/src/stores/ServicesStore.js
+++ b/src/stores/ServicesStore.js
@@ -149,18 +149,7 @@ export default class ServicesStore extends Store {
149 } 149 }
150 150
151 async _showAddServiceInterface({ recipeId }) { 151 async _showAddServiceInterface({ recipeId }) {
152 const recipesStore = this.stores.recipes; 152 this.stores.router.push(`/settings/services/add/${recipeId}`);
153
154 if (recipesStore.isInstalled(recipeId)) {
155 debug(`Recipe ${recipeId} is installed`);
156 this._redirectToAddServiceRoute(recipeId);
157 } else {
158 debug(`Recipe ${recipeId} is not installed`);
159 // We access the RecipeStore action directly
160 // returns Promise instead of action
161 await this.stores.recipes._install({ recipeId });
162 this._redirectToAddServiceRoute(recipeId);
163 }
164 } 153 }
165 154
166 // Actions 155 // Actions
@@ -294,7 +283,8 @@ export default class ServicesStore extends Store {
294 gaEvent('Service', 'clear cache'); 283 gaEvent('Service', 'clear cache');
295 } 284 }
296 285
297 @action _setActive({ serviceId }) { 286 @action _setActive({ serviceId, keepActiveRoute }) {
287 if (!keepActiveRoute) this.stores.router.push('/');
298 const service = this.one(serviceId); 288 const service = this.one(serviceId);
299 289
300 this.all.forEach((s, index) => { 290 this.all.forEach((s, index) => {
@@ -520,7 +510,16 @@ export default class ServicesStore extends Store {
520 this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false }); 510 this.actions.ui.toggleServiceUpdatedInfoBar({ visible: false });
521 } 511 }
522 512
523 @action _reorder({ oldIndex, newIndex }) { 513 @action _reorder(params) {
514 const { workspaces } = this.stores;
515 if (workspaces.isAnyWorkspaceActive) {
516 workspaces.reorderServicesOfActiveWorkspace(params);
517 } else {
518 this._reorderService(params);
519 }
520 }
521
522 @action _reorderService({ oldIndex, newIndex }) {
524 const showDisabledServices = this.stores.settings.all.app.showDisabledServices; 523 const showDisabledServices = this.stores.settings.all.app.showDisabledServices;
525 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]); 524 const oldEnabledSortIndex = showDisabledServices ? oldIndex : this.all.indexOf(this.enabled[oldIndex]);
526 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]); 525 const newEnabledSortIndex = showDisabledServices ? newIndex : this.all.indexOf(this.enabled[newIndex]);
@@ -683,11 +682,6 @@ export default class ServicesStore extends Store {
683 } 682 }
684 683
685 // Helper 684 // Helper
686 _redirectToAddServiceRoute(recipeId) {
687 const route = `/settings/services/add/${recipeId}`;
688 this.stores.router.push(route);
689 }
690
691 _initializeServiceRecipeInWebview(serviceId) { 685 _initializeServiceRecipeInWebview(serviceId) {
692 const service = this.one(serviceId); 686 const service = this.one(serviceId);
693 687
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 }