From 77f6147b157eafa6203eb84a5407478fa8c9373d Mon Sep 17 00:00:00 2001 From: Hermann <blumh@ethz.ch> Date: Tue, 15 May 2018 14:38:54 +0200 Subject: [PATCH] working changes on refreshing searches in lists --- src/listcontroller.js | 11 +++++++++-- src/views/selectList.js | 9 +++++---- src/views/tableView.js | 9 +-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/listcontroller.js b/src/listcontroller.js index 87530ac..e7c36ad 100644 --- a/src/listcontroller.js +++ b/src/listcontroller.js @@ -1,5 +1,7 @@ +import m from 'mithril'; import Stream from 'mithril/stream'; import { ResourceHandler } from './auth'; +import { debounce } from './utils'; export default class DatalistController { constructor(resource, query = {}, searchKeys = false, onlineSearch = true) { @@ -16,6 +18,11 @@ export default class DatalistController { // we can tell infinite scroll that the data-version has changed. this.stateCounter = Stream(0); this.refresh(); + this.debouncedSearch = debounce((search) => { + this.setSearch(search); + this.refresh(); + m.redraw(); + }, 100); } refresh() { @@ -83,10 +90,10 @@ export default class DatalistController { if (this.onlineSearch) { this.search = search; this.query.search = search; - this.refresh(); + //this.refresh(); } else if (this.clientSearchKeys.length > 0) { this.search = search; - this.refresh(); + //this.refresh(); } } diff --git a/src/views/selectList.js b/src/views/selectList.js index c7ed8d5..6fdc6c5 100644 --- a/src/views/selectList.js +++ b/src/views/selectList.js @@ -26,6 +26,7 @@ class SearchField { const ExitButton = attrs.onCancel ? { view() { return m(Button, { + element: 'div', label: 'Cancel', className: 'blue-button', events: { onclick: attrs.onCancel }, @@ -83,7 +84,7 @@ export default class SelectList { } onupdate({ attrs: { selection = null } }) { - console.log(selection); + //console.log(selection); if (selection) this.selected = selection; } @@ -142,6 +143,7 @@ export default class SelectList { }) : '', ]) : m(SearchField, Object.assign({}, { style: { background: 'rgb(78, 242, 167)' }, + onCancel, onChange: ({ value, focus }) => { // onChange is called either if the value or focus fo the SearchField // changes. @@ -165,11 +167,10 @@ export default class SelectList { // So, we make sure this state change is due to value change and // not due to focus change. this.searchValue = value; - controller.setSearch(value); - setTimeout(() => { controller.refresh(); }, 500); + //controller.setSearch(value); + controller.debouncedSearch(value); } }, - onCancel, })), (this.showList && !this.selected) ? m(List, { style: { height: '400px', 'background-color': 'white' }, diff --git a/src/views/tableView.js b/src/views/tableView.js index 3189fa1..37019a6 100644 --- a/src/views/tableView.js +++ b/src/views/tableView.js @@ -87,10 +87,6 @@ export default class TableView { tableHeight = false, }, }) { - const updateList = debounce(() => { - controller.refresh(); - }, 500); - return m('div.tabletool', [ m(Toolbar, { className: 'toolbar', @@ -99,10 +95,7 @@ export default class TableView { m(Search, { textfield: { label: 'Search', - onChange: ({ value }) => { - controller.setSearch(value); - updateList(); - }, + onChange: ({ value }) => { controller.debouncedSearch(value); }, }, fullWidth: false, }), -- GitLab