diff --git a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 index 2375f434..aa490169 100644 --- a/assets/javascripts/wizard/components/similar-topics-validator.js.es6 +++ b/assets/javascripts/wizard/components/similar-topics-validator.js.es6 @@ -15,8 +15,16 @@ export default WizardFieldValidator.extend({ noSimilarTopics: computed('similarTopics', function() { return this.similarTopics !== null && this.similarTopics.length == 0; }), - showDefault: and('hasNotSearched', 'hasInput'), - + showDefault: computed('hasNotSearched', 'hasInput', 'typing', function() { + return this.hasInput && (this.hasNotSearched || this.typing); + }), + showSimilarTopics: computed('typing', 'hasSimilarTopics', function() { + return this.hasSimilarTopics && !this.typing; + }), + showNoSimilarTopics: computed('typing', 'noSimilarTopics', function() { + return this.noSimilarTopics && !this.typing; + }), + validate() {}, @observes("field.value") @@ -26,6 +34,8 @@ export default WizardFieldValidator.extend({ if (!field.value) return; const value = field.value; + this.set("typing", true); + if (value && value.length < 5) { this.set('similarTopics', null); return; @@ -41,6 +51,7 @@ export default WizardFieldValidator.extend({ if (lastKeyUp !== this._lastKeyUp) { return; } + this.set("typing", false); this.updateSimilarTopics(); }, 1000); diff --git a/assets/javascripts/wizard/components/wizard-similar-topics.js.es6 b/assets/javascripts/wizard/components/wizard-similar-topics.js.es6 new file mode 100644 index 00000000..8bdc1416 --- /dev/null +++ b/assets/javascripts/wizard/components/wizard-similar-topics.js.es6 @@ -0,0 +1,36 @@ +import Component from "@ember/component"; +import { bind } from "@ember/runloop"; +import { observes } from "discourse-common/utils/decorators"; + +export default Component.extend({ + classNames: ['wizard-similar-topics'], + showTopics: true, + + didInsertElement() { + $(document).on("click", bind(this, this.documentClick)); + }, + + willDestroyElement() { + $(document).off("click", bind(this, this.documentClick)); + }, + + documentClick(e) { + if (this._state == "destroying") return; + let $target = $(e.target); + + if (!$target.hasClass('show-topics')) { + this.set('showTopics', false); + } + }, + + @observes('topics') + toggleShowWhenTopicsChange() { + this.set('showTopics', true); + }, + + actions: { + toggleShowTopics() { + this.set('showTopics', true); + } + } +}) \ No newline at end of file diff --git a/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs b/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs index 5fda22b8..c19bc8c2 100644 --- a/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs +++ b/assets/javascripts/wizard/templates/components/similar-topics-validator.hbs @@ -1,13 +1,9 @@ {{#if loading}} -{{else if hasSimilarTopics}} +{{else if showSimilarTopics}} -