aboutsummaryrefslogtreecommitdiff
path: root/src/components/search_bar/search_bar.js
blob: 551649c7040cdd876843c31ff00152ad91ad3afc (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
import { library } from '@fortawesome/fontawesome-svg-core'
import {
  faTimes,
  faSearch
} from '@fortawesome/free-solid-svg-icons'

library.add(
  faTimes,
  faSearch
)

const SearchBar = {
  data: () => ({
    searchTerm: undefined,
    hidden: true,
    error: false
  }),
  watch: {
    '$route': function (route) {
      if (route.name === 'search') {
        this.searchTerm = route.query.query
      }
    }
  },
  methods: {
    find (searchTerm) {
      this.$router.push({ name: 'search', query: { query: searchTerm } })
      this.$refs.searchInput.focus()
    },
    toggleHidden () {
      this.hidden = !this.hidden
      this.$emit('toggled', this.hidden)
      this.$nextTick(() => {
        if (!this.hidden) {
          this.$refs.searchInput.focus()
        }
      })
    }
  }
}

export default SearchBar