diff --git a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 index bc5f1e91..5c90ae7f 100644 --- a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 +++ b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 @@ -2,52 +2,52 @@ import WizardFieldValidator from "../../wizard/components/validator"; import { deepMerge } from "discourse-common/lib/object"; import { observes } from "discourse-common/utils/decorators"; import { cancel, later } from "@ember/runloop"; -import { A } from '@ember/array'; +import { A } from "@ember/array"; import EmberObject from "@ember/object"; export default WizardFieldValidator.extend({ - similarTopics: [], + similarTopics: [], - validate() { + validate() {}, + @observes("field.value") + customValidate() { + const lastKeyUp = new Date(); + this._lastKeyUp = lastKeyUp; + + // One second from now, check to see if the last key was hit when + // we recorded it. If it was, the user paused typing. + cancel(this._lastKeyTimeout); + this._lastKeyTimeout = later(() => { + if (lastKeyUp !== this._lastKeyUp) { + return; + } + + this.updateSimilarTopics(); + }, 1000); + }, + + updateSimilarTopics() { + this.backendValidate({ + title: this.get("field.value"), + categories: this.get("validation.categories"), + date_after: this.get("validation.date_after"), + }).then((result) => { + const similarTopics = A( + deepMerge(result["topics"], result["similar_topics"]) + ); + similarTopics.forEach(function (topic, index) { + similarTopics[index] = EmberObject.create(topic); + }); + + this.set("similarTopics", similarTopics); + }); + }, + init() { + this._super(...arguments); + }, + actions: { + closeMessage() { + this.set("showMessage", false); }, - @observes("field.value") - customValidate(){ - const lastKeyUp = new Date(); - this._lastKeyUp = lastKeyUp; - - // One second from now, check to see if the last key was hit when - // we recorded it. If it was, the user paused typing. - cancel(this._lastKeyTimeout); - this._lastKeyTimeout = later(() => { - if (lastKeyUp !== this._lastKeyUp) { - return; - } - - this.updateSimilarTopics(); - }, 1000); - }, - - updateSimilarTopics(){ - this.backendValidate({ - title: this.get("field.value"), - categories: this.get('validation.categories'), - date_after: this.get('validation.date_after') - }).then((result) => { - const similarTopics = A(deepMerge(result['topics'], result['similar_topics'])); - similarTopics.forEach(function(topic, index) { - similarTopics[index] = EmberObject.create(topic); - }); - - this.set('similarTopics', similarTopics); - }); - }, - init() { - this._super(...arguments); - - }, - actions: { - closeMessage(){ - this.set('showMessage', false); - } - } -}); \ No newline at end of file + }, +});