aboutsummaryrefslogtreecommitdiff
path: root/src/components/user_autosuggest/user_autosuggest.js
blob: 6612c2f3788c76a02911e35df178c6c4a61fd5ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { VueAutosuggest } from 'vue-autosuggest'
import BasicUserCard from '../basic_user_card/basic_user_card.vue'
import userSearchApi from '../../services/new_api/user_search.js'

export default {
  components: {
    VueAutosuggest,
    BasicUserCard
  },
  data () {
    return {
      results: [],
      timeout: null,
      selected: null,
      debounceMilliseconds: 500,
      inputProps: {
        id: 'autosuggest__input',
        onInputChange: this.fetchResults,
        placeholder: 'Search...',
        class: 'form-control'
      },
      suggestions: []
    }
  },
  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
    }
  }
}