Implement search on front end

This commit is contained in:
Toby Zerner
2015-06-03 18:10:56 +09:30
parent ea510b5ea0
commit 5d89618bbd
18 changed files with 717 additions and 202 deletions

View File

@ -0,0 +1,22 @@
import highlight from 'flarum/helpers/highlight';
import avatar from 'flarum/helpers/avatar';
export default class UsersSearchResults {
search(string) {
return app.store.find('users', {q: string, page: {limit: 5}});
}
view(string) {
var results = app.store.all('users').filter(user => user.username().toLowerCase().substr(0, string.length) === string);
return results.length ? [
m('li.dropdown-header', 'Users'),
results.map(user => m('li.user-search-result', {'data-index': 'users'+user.id()},
m('a', {
href: app.route.user(user),
config: m.route
}, avatar(user), highlight(user.username(), string))
))
] : '';
}
}