From 94e67ff11894c13bf34f1b31802a1497caa03897 Mon Sep 17 00:00:00 2001 From: taehoon Date: Tue, 2 Apr 2019 12:31:45 -0400 Subject: [PATCH] rewrite USerAutoSuggest without any dependency --- .../user_autosuggest/user_autosuggest.js | 37 +++----- .../user_autosuggest/user_autosuggest.vue | 94 +++---------------- 2 files changed, 29 insertions(+), 102 deletions(-) diff --git a/src/components/user_autosuggest/user_autosuggest.js b/src/components/user_autosuggest/user_autosuggest.js index 6612c2f3..eff6ef75 100644 --- a/src/components/user_autosuggest/user_autosuggest.js +++ b/src/components/user_autosuggest/user_autosuggest.js @@ -1,41 +1,34 @@ -import { VueAutosuggest } from 'vue-autosuggest' import BasicUserCard from '../basic_user_card/basic_user_card.vue' import userSearchApi from '../../services/new_api/user_search.js' +const debounceMilliseconds = 500 + export default { components: { - VueAutosuggest, BasicUserCard }, data () { return { + query: '', results: [], - timeout: null, - selected: null, - debounceMilliseconds: 500, - inputProps: { - id: 'autosuggest__input', - onInputChange: this.fetchResults, - placeholder: 'Search...', - class: 'form-control' - }, - suggestions: [] + timeout: null + } + }, + watch: { + query (val) { + this.fetchResults(val) } }, methods: { fetchResults (query) { clearTimeout(this.timeout) this.timeout = setTimeout(() => { - userSearchApi.search({query, store: this.$store}) - .then((data) => { this.suggestions = [{ data }] }) - }, this.debounceMilliseconds) - }, - clickHandler (item) { - return false - }, - clickUserHandler () { - console.log('clickUserHandler') - return false + this.results = [] + if (query) { + userSearchApi.search({query, store: this.$store}) + .then((data) => { this.results = data }) + } + }, debounceMilliseconds) } } } diff --git a/src/components/user_autosuggest/user_autosuggest.vue b/src/components/user_autosuggest/user_autosuggest.vue index 48fe350d..04e38a60 100644 --- a/src/components/user_autosuggest/user_autosuggest.vue +++ b/src/components/user_autosuggest/user_autosuggest.vue @@ -1,93 +1,27 @@