2017-08-13 22:46:05 +00:00
|
|
|
<template lang="pug">
|
2017-10-08 23:36:53 +00:00
|
|
|
v-dialog(v-model='searchShow', max-width='650', lazy, absolute, @keydown.esc='searchShow = false')
|
2017-09-17 17:31:01 +00:00
|
|
|
v-btn(icon, slot='activator')
|
2017-08-13 22:46:05 +00:00
|
|
|
v-icon search
|
|
|
|
v-card.pr-4
|
|
|
|
v-card-title.headline Which anime are you looking for?
|
|
|
|
v-card-text
|
|
|
|
v-layout(wrap, justify-center)
|
|
|
|
v-flex(xs6)
|
|
|
|
v-text-field(
|
|
|
|
name='search-name',
|
|
|
|
label='Anime name',
|
|
|
|
v-model='searchTerm',
|
2017-09-15 21:08:48 +00:00
|
|
|
append-icon='close',
|
2017-10-10 23:07:03 +00:00
|
|
|
:append-icon-cb="clear"
|
|
|
|
dark, ref='input'
|
2017-08-13 22:46:05 +00:00
|
|
|
)
|
|
|
|
v-flex(xs12)
|
|
|
|
v-layout(row, wrap, justify-center)
|
|
|
|
template(v-if='results.length', v-for='item in results')
|
2017-10-28 01:24:25 +00:00
|
|
|
v-flex.elem(xs3, @click='search(item)')
|
2017-08-13 22:46:05 +00:00
|
|
|
v-layout.elem-content.elevation-3(
|
|
|
|
wrap,
|
|
|
|
justify-center,
|
2017-10-28 01:24:25 +00:00
|
|
|
v-ripple='true'
|
2017-08-13 22:46:05 +00:00
|
|
|
)
|
|
|
|
v-flex(xs8)
|
|
|
|
img.elem-picture(:src='item.image_url', height='140')
|
|
|
|
v-flex.elem-name(xs10) {{ item.name }}
|
|
|
|
v-card-actions
|
|
|
|
v-spacer
|
2017-10-11 14:10:18 +00:00
|
|
|
v-btn.blue--text.darken-1(flat, @click='searchShow = false') Close
|
2017-05-17 21:24:31 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2017-06-27 18:44:24 +00:00
|
|
|
import axios from 'axios'
|
2017-06-28 10:42:02 +00:00
|
|
|
import _ from 'lodash'
|
2017-05-17 21:24:31 +00:00
|
|
|
|
2017-06-27 18:44:24 +00:00
|
|
|
export default {
|
2017-05-17 21:37:10 +00:00
|
|
|
data () {
|
2017-06-27 18:44:24 +00:00
|
|
|
return {
|
|
|
|
searchShow: false,
|
|
|
|
searchTerm: '',
|
2017-08-02 19:12:47 +00:00
|
|
|
results: []
|
2017-06-27 18:44:24 +00:00
|
|
|
}
|
2017-05-17 21:24:31 +00:00
|
|
|
},
|
2017-06-27 18:44:24 +00:00
|
|
|
methods: {
|
2017-10-10 23:07:03 +00:00
|
|
|
clear () {
|
|
|
|
this.searchTerm = ''
|
|
|
|
this.$refs.input.focus()
|
|
|
|
},
|
2017-10-28 01:24:25 +00:00
|
|
|
async search (item) {
|
|
|
|
this.searchTerm = item.name
|
2017-06-28 10:42:02 +00:00
|
|
|
|
2017-10-28 01:24:25 +00:00
|
|
|
if (this.$store.state.search.info.info.title === item.name) {
|
2017-09-20 08:28:08 +00:00
|
|
|
this.$store.commit('search/showInfo', true)
|
2017-06-27 18:44:24 +00:00
|
|
|
this.searchShow = false
|
|
|
|
} else {
|
2017-06-28 10:42:02 +00:00
|
|
|
this.searchShow = false
|
|
|
|
|
2017-10-28 01:24:25 +00:00
|
|
|
this.$store.dispatch('search/fromUrl', item)
|
2017-06-27 18:44:24 +00:00
|
|
|
}
|
2017-06-28 10:42:02 +00:00
|
|
|
},
|
|
|
|
quickSearch: _.debounce(
|
|
|
|
async function () {
|
|
|
|
const term = this.searchTerm
|
2017-06-27 18:44:24 +00:00
|
|
|
|
2017-09-15 21:08:48 +00:00
|
|
|
if (term && term.length > 2) {
|
2017-06-28 10:42:02 +00:00
|
|
|
try {
|
2017-10-28 01:24:25 +00:00
|
|
|
const {data, status} = await axios.get(`searchTermOnMal`, {
|
|
|
|
params: {term}
|
|
|
|
})
|
2017-06-27 18:44:24 +00:00
|
|
|
|
2017-06-28 10:42:02 +00:00
|
|
|
if (status === 200) {
|
|
|
|
this.results = data.categories[0].items
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2017-10-10 23:07:03 +00:00
|
|
|
console.log((new Date()).toLocaleTimeString(), e.message)
|
2017-06-28 10:42:02 +00:00
|
|
|
this.$store.commit('setInfoSnackbar', e.message)
|
2017-06-27 18:44:24 +00:00
|
|
|
}
|
2017-06-28 10:42:02 +00:00
|
|
|
} else {
|
|
|
|
this.results = []
|
2017-06-27 18:44:24 +00:00
|
|
|
}
|
2017-06-28 10:42:02 +00:00
|
|
|
},
|
2017-08-02 19:57:41 +00:00
|
|
|
300)
|
2017-06-28 10:42:02 +00:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
async searchTerm () {
|
|
|
|
this.quickSearch()
|
2017-10-10 23:07:03 +00:00
|
|
|
},
|
|
|
|
searchShow (bool) {
|
|
|
|
if (bool) {
|
|
|
|
this.$nextTick(() => {
|
|
|
|
this.$refs.input.focus()
|
|
|
|
})
|
|
|
|
}
|
2017-06-27 18:44:24 +00:00
|
|
|
}
|
2017-05-17 21:24:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2017-10-11 14:10:18 +00:00
|
|
|
<style lang="stylus" scoped>
|
2017-06-27 18:44:24 +00:00
|
|
|
.elem
|
2017-10-11 14:10:18 +00:00
|
|
|
margin-top 10px
|
|
|
|
padding-left 10px
|
2017-05-17 21:24:31 +00:00
|
|
|
|
2017-06-27 18:44:24 +00:00
|
|
|
.elem-content
|
2017-10-11 14:10:18 +00:00
|
|
|
margin 0
|
|
|
|
height 100%
|
|
|
|
position relative
|
|
|
|
margin-left 10%
|
|
|
|
width 100%
|
|
|
|
background-color rgb(60, 60, 60)
|
|
|
|
padding-bottom 5px
|
2017-06-27 18:44:24 +00:00
|
|
|
|
|
|
|
.elem-name
|
2017-10-11 14:10:18 +00:00
|
|
|
font-size 16px
|
|
|
|
text-align center
|
2017-06-28 10:42:02 +00:00
|
|
|
|
|
|
|
.elem-picture
|
2017-10-11 14:10:18 +00:00
|
|
|
max-width 90%
|
2017-05-17 21:37:10 +00:00
|
|
|
</style>
|