1
0
mirror of https://github.com/flarum/core.git synced 2025-10-12 15:34:26 +02:00

Roughly implement routes and data preloading

Only preloading data for basic requests w/o query params, at least for
the moment - if we have to preload for something like
/?q=test&sort=newest, we end up having to duplicate a whole lot of
logic between JS/PHP.
This commit is contained in:
Toby Zerner
2015-06-18 17:41:37 +09:30
parent c2da4a946f
commit 822a216cc9
11 changed files with 126 additions and 26 deletions

View File

@@ -23,7 +23,7 @@ export default class SearchBox extends Component {
constructor(props) {
super(props);
this.value = m.prop(this.getCurrentSearch() || '');
this.value = m.prop();
this.hasFocus = m.prop(false);
this.sources = this.sourceItems().toArray();
@@ -40,10 +40,16 @@ export default class SearchBox extends Component {
}
getCurrentSearch() {
return typeof app.current.searching === 'function' && app.current.searching();
return app.current && typeof app.current.searching === 'function' && app.current.searching();
}
view() {
// Initialize value in the view rather than the constructor so that we have
// access to app.current.
if (typeof this.value() === 'undefined') {
this.value(this.getCurrentSearch() || '');
}
var currentSearch = this.getCurrentSearch();
return m('div.search-box.dropdown', {
@@ -104,7 +110,7 @@ export default class SearchBox extends Component {
case 13: // Return
this.$('input').blur();
this.getItem(this.index()).find('a')[0].dispatchEvent(new Event('click'));
m.route(this.getItem(this.index()).find('a').attr('href'));
break;
case 27: // Escape