Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: debounce the journal input text entry #1212

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.15.0
2 changes: 1 addition & 1 deletion app/components/find-journal/index.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{! template-lint-disable no-action }}
<PowerSelect
@triggerClass={{if (eq @journalClass "is-invalid") (local-class "is-invalid") (local-class "is-valid")}}
@search={{this.searchJournals}}
@search={{perform this.searchJournals}}
@searchEnabled={{true}}
@selected={{@value}}
@placeholder="Journal"
Expand Down
11 changes: 8 additions & 3 deletions app/components/find-journal/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { dropTask } from 'ember-concurrency-decorators';
import { timeout } from 'ember-concurrency';

const DEBOUNCE_MS = 750;

export default class FindJournal extends Component {
@service store;
Expand All @@ -14,10 +18,11 @@ export default class FindJournal extends Component {
* @param {string} term The search term
* @returns {array} array of Journals
*/
@action
searchJournals(term) {
@dropTask
searchJournals = function* (term) {
yield timeout(DEBOUNCE_MS);
return this.autocomplete.suggest('journal', 'journalName', term);
}
};

@action
onSelect(selected) {
Expand Down