From eb71f7118644846b7b443bd632a7ebef71d8db1f Mon Sep 17 00:00:00 2001 From: vantezzen Date: Sun, 13 Oct 2019 11:40:22 +0200 Subject: Sort services in QuickSwitch by last used --- src/features/quickSwitch/Component.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/features/quickSwitch') diff --git a/src/features/quickSwitch/Component.js b/src/features/quickSwitch/Component.js index 7b76553b2..583c7184c 100644 --- a/src/features/quickSwitch/Component.js +++ b/src/features/quickSwitch/Component.js @@ -119,10 +119,27 @@ export default @injectSheet(styles) @inject('stores', 'actions') @observer class // Get currently shown services services() { - let services = this.props.stores.services.allDisplayed; + let services = []; if (this.state.search) { - // Apply simple search algorythm + // Apply simple search algorythm to list of all services + services = this.props.stores.services.allDisplayed; services = services.filter(service => service.name.toLowerCase().includes(this.state.search.toLowerCase())); + } else { + // Add last used services to services array + for (const service of this.props.stores.services.lastUsedServices) { + if (this.props.stores.services.one(service)) { + services.push( + this.props.stores.services.one(service), + ); + } + } + + // Add all other services in the default order + for (const service of this.props.stores.services.allDisplayed) { + if (!services.includes(service)) { + services.push(service); + } + } } return services; -- cgit v1.2.3-70-g09d2