Skip to content

Commit

Permalink
Merge branch 'develop' into showUrlOnLinkHover
Browse files Browse the repository at this point in the history
  • Loading branch information
adlk committed Oct 22, 2017
2 parents 80f12d7 + 982c970 commit 4c3aee0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/actions/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export default {
setActive: {
serviceId: PropTypes.string.isRequired,
},
setActiveNext: {},
setActivePrev: {},
showAddServiceInterface: {
recipeId: PropTypes.string.isRequired,
},
Expand Down
12 changes: 12 additions & 0 deletions src/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ export default class AppStore extends Store {
this.actions.service.openDevToolsForActiveService();
});
// Set active the next service
key(
'+pagedown, ctrl+pagedown, +shift+tab, ctrl+shift+tab', () => {
this.actions.service.setActiveNext();
});
// Set active the prev service
key(
'+pageup, ctrl+pageup, +tab, ctrl+tab', () => {
this.actions.service.setActivePrev();
});
this.locale = this._getDefaultLocale();
this._healthCheck();
Expand Down
24 changes: 24 additions & 0 deletions src/stores/ServicesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default class ServicesStore extends Store {
// Register action handlers
this.actions.service.setActive.listen(this._setActive.bind(this));
this.actions.service.setActiveNext.listen(this._setActiveNext.bind(this));
this.actions.service.setActivePrev.listen(this._setActivePrev.bind(this));
this.actions.service.showAddServiceInterface.listen(this._showAddServiceInterface.bind(this));
this.actions.service.createService.listen(this._createService.bind(this));
this.actions.service.createFromLegacyService.listen(this._createFromLegacyService.bind(this));
Expand Down Expand Up @@ -206,6 +208,24 @@ export default class ServicesStore extends Store {
service.isActive = true;
}

@action _setActiveNext() {
const nextIndex = this._wrapIndex(this.enabled.findIndex(service => service.isActive), 1, this.enabled.length);

this.all.forEach((s, index) => {
this.all[index].isActive = false;
});
this.enabled[nextIndex].isActive = true;
}

@action _setActivePrev() {
const prevIndex = this._wrapIndex(this.enabled.findIndex(service => service.isActive), -1, this.enabled.length);

this.all.forEach((s, index) => {
this.all[index].isActive = false;
});
this.enabled[prevIndex].isActive = true;
}

@action _setUnreadMessageCount({ serviceId, count }) {
const service = this.one(serviceId);

Expand Down Expand Up @@ -500,4 +520,8 @@ export default class ServicesStore extends Store {
_reorderAnalytics = debounce(() => {
gaEvent('Service', 'order');
}, 5000);

_wrapIndex(index, delta, size) {
return (((index + delta) % size) + size) % size;
}
}

0 comments on commit 4c3aee0

Please sign in to comment.