From 1062b9b2fd964af05b69160d65bd8d8a3bbfe9d1 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Thu, 26 Sep 2019 12:56:28 -0600 Subject: [PATCH] Fix search not working on fresh load --- app/appListeners.js | 2 ++ app/views/search/controller.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/appListeners.js b/app/appListeners.js index 7ab5851..2af91f7 100644 --- a/app/appListeners.js +++ b/app/appListeners.js @@ -16,5 +16,7 @@ export const appListeners = (app, state, emitter) => { state.language = newLanguage; emitter.emit('render', () => { }); }); + + emitter.emit('render'); // This should hopefully only run once after the DOM is loaded. It prevents routing issues where 'render' hasn't been defined yet }); } \ No newline at end of file diff --git a/app/views/search/controller.js b/app/views/search/controller.js index fbd7b54..247f040 100644 --- a/app/views/search/controller.js +++ b/app/views/search/controller.js @@ -6,6 +6,8 @@ export class SearchController extends ViewController { // which stores state in this.appState and the view controller's state to this.state super(state, i18n, 'search', { lastSearch: '', + lastSource: 'inventaire', + lastBy: 'title', searchSource: 'inventaire', searchBy: 'title', done: true, @@ -33,7 +35,9 @@ export class SearchController extends ViewController { } get queryIsNew() { - return this.state.lastSearch !== this.appState.query.for.trim(); + return this.state.lastSearch !== this.appState.query.for.trim() + || this.state.lastSource !== this.state.searchSource + || this.state.lastBy !== this.state.searchBy; } get openModal() { @@ -49,6 +53,8 @@ export class SearchController extends ViewController { this.state.done = false; this.emit('render', () => { this.state.lastSearch = this.appState.query.for; + this.state.lastSource = this.state.searchSource; + this.state.lastBy = this.state.searchBy; const searchTerm = this.appState.query.for.trim();