mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 23:29:57 +08:00
Implement search on front end
This commit is contained in:
22
js/forum/src/components/users-search-results.js
Normal file
22
js/forum/src/components/users-search-results.js
Normal 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))
|
||||
))
|
||||
] : '';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user