1
0
mirror of https://github.com/flarum/core.git synced 2025-10-11 06:54:26 +02:00

Actually list users returned from the API when searching

This commit is contained in:
Toby Zerner
2017-11-20 10:37:21 +10:30
parent 0aa74c987c
commit 7796580210
2 changed files with 85 additions and 23 deletions

View File

@@ -9,18 +9,27 @@ import username from 'flarum/helpers/username';
* @implements SearchSource
*/
export default class UsersSearchResults {
constructor() {
this.results = {};
}
search(query) {
return app.store.find('users', {
filter: {q: query},
page: {limit: 5}
}).then(results => {
this.results[query] = results;
m.redraw();
});
}
view(query) {
query = query.toLowerCase();
const results = app.store.all('users')
.filter(user => [user.username(), user.displayName()].some(value => value.toLowerCase().substr(0, query.length) === query));
const results = (this.results[query] || [])
.concat(app.store.all('users').filter(user => [user.username(), user.displayName()].some(value => value.toLowerCase().substr(0, query.length) === query)))
.filter((e, i, arr) => arr.lastIndexOf(e) === i)
.sort((a, b) => a.displayName().localeCompare(b.displayName()));
if (!results.length) return '';