2017-08-13 22:46:05 +00:00
|
|
|
<template lang="pug">
|
2017-11-09 10:33:55 +00:00
|
|
|
v-dialog(v-model='show', max-width='650', lazy, absolute, @keydown.esc='close()')
|
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-11-09 10:33:55 +00:00
|
|
|
:append-icon-cb='clear'
|
2017-10-10 23:07:03 +00:00
|
|
|
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-11-09 10:33:55 +00:00
|
|
|
v-flex.elem(xs3, @click='actOnThis(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-11-09 10:33:55 +00:00
|
|
|
v-btn.blue--text.darken-1(flat, @click='close()') Close
|
2017-05-17 21:24:31 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
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 {
|
|
|
|
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-11-09 10:33:55 +00:00
|
|
|
computed: {
|
|
|
|
show: {
|
|
|
|
get () {
|
|
|
|
return this.$store.state.search.search
|
|
|
|
},
|
|
|
|
set (bool) {
|
|
|
|
this.$store.commit('search/show', bool)
|
|
|
|
if (!bool) this.$store.commit('mal/isAdding', bool)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
isSearch () {
|
|
|
|
return !this.$store.state.mal.isAdding
|
|
|
|
}
|
|
|
|
},
|
2017-06-27 18:44:24 +00:00
|
|
|
methods: {
|
2017-11-09 10:33:55 +00:00
|
|
|
close () {
|
|
|
|
this.$store.commit('search/show', false)
|
|
|
|
this.$store.commit('mal/isAdding', false)
|
|
|
|
},
|
2017-10-10 23:07:03 +00:00
|
|
|
clear () {
|
|
|
|
this.searchTerm = ''
|
|
|
|
this.$refs.input.focus()
|
|
|
|
},
|
2017-11-09 10:33:55 +00:00
|
|
|
actOnThis (item) {
|
|
|
|
if (this.isSearch) {
|
|
|
|
this.search(item)
|
|
|
|
} else {
|
|
|
|
this.close()
|
|
|
|
// This might change when I'll work with Kitsu etc...
|
|
|
|
// MAL specific
|
2017-11-10 15:24:31 +00:00
|
|
|
this.$store.commit('mal/setEntry', item)
|
2017-11-09 10:33:55 +00:00
|
|
|
this.$store.commit('mal/showForm', true)
|
|
|
|
}
|
|
|
|
},
|
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-11-09 10:33:55 +00:00
|
|
|
this.close()
|
2017-06-27 18:44:24 +00:00
|
|
|
} else {
|
2017-11-09 10:33:55 +00:00
|
|
|
this.close()
|
2017-06-28 10:42:02 +00:00
|
|
|
|
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-11-23 15:43:50 +00:00
|
|
|
const {data, status} = await this.$axios.get(`searchTermOnMal`, {
|
2017-10-28 01:24:25 +00:00
|
|
|
params: {term}
|
|
|
|
})
|
2017-06-27 18:44:24 +00:00
|
|
|
|
2017-06-28 10:42:02 +00:00
|
|
|
if (status === 200) {
|
2017-11-23 15:43:50 +00:00
|
|
|
this.results = data
|
|
|
|
} else {
|
|
|
|
throw new Error('Error while searching.')
|
2017-06-28 10:42:02 +00:00
|
|
|
}
|
|
|
|
} 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
|
|
|
},
|
2017-11-09 10:33:55 +00:00
|
|
|
show (bool) {
|
2017-10-10 23:07:03 +00:00
|
|
|
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>
|