aboutsummaryrefslogtreecommitdiff
path: root/src/components/lists_user_search/lists_user_search.js
blob: c92ec0eee27df132fbd18f2566cb924ac93fdbf8 (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
42
43
44
45
46
47
48
49
50
51
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faSearch,
  faChevronLeft
} from '@fortawesome/free-solid-svg-icons'
import { debounce } from 'lodash'
import Checkbox from '../checkbox/checkbox.vue'

library.add(
  faSearch,
  faChevronLeft
)

const ListsUserSearch = {
  components: {
    Checkbox
  },
  emits: ['loading', 'loadingDone', 'results'],
  data () {
    return {
      loading: false,
      query: '',
      followingOnly: true
    }
  },
  methods: {
    onInput: debounce(function () {
      this.search(this.query)
    }, 2000),
    search (query) {
      if (!query) {
        this.loading = false
        return
      }

      this.loading = true
      this.$emit('loading')
      this.userIds = []
      this.$store.dispatch('search', { q: query, resolve: true, type: 'accounts', following: this.followingOnly })
        .then(data => {
          this.$emit('results', data.accounts.map(a => a.id))
        })
        .finally(() => {
          this.loading = false
          this.$emit('loadingDone')
        })
    }
  }
}

export default ListsUserSearch