summaryrefslogtreecommitdiffstats
path: root/core/src/services/UnifiedSearchService.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/services/UnifiedSearchService.js')
-rw-r--r--core/src/services/UnifiedSearchService.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/core/src/services/UnifiedSearchService.js b/core/src/services/UnifiedSearchService.js
index 2e63f19767d..ff9a4aebe2a 100644
--- a/core/src/services/UnifiedSearchService.js
+++ b/core/src/services/UnifiedSearchService.js
@@ -24,15 +24,18 @@ import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
export const defaultLimit = loadState('unified-search', 'limit-default')
+export const activeApp = loadState('core', 'active-app')
/**
* Get the list of available search providers
+ *
+ * @returns {Array}
*/
export async function getTypes() {
try {
const { data } = await axios.get(generateUrl('/search/providers'))
if (Array.isArray(data) && data.length > 0) {
- return data
+ return sortProviders(data)
}
} catch (error) {
console.error(error)
@@ -41,6 +44,29 @@ export async function getTypes() {
}
/**
+ * Sort the providers by the current active app
+ *
+ * @param {Array} providers the providers list
+ * @returns {Array}
+ */
+export function sortProviders(providers) {
+ providers.sort((a, b) => {
+ if (a.id.startsWith(activeApp) && b.id.startsWith(activeApp)) {
+ return a.order - b.order
+ }
+
+ if (a.id.startsWith(activeApp)) {
+ return -1
+ }
+ if (b.id.startsWith(activeApp)) {
+ return 1
+ }
+ return 0
+ })
+ return providers
+}
+
+/**
* Get the list of available search providers
*
* @param {string} type the type to search