mirror of https://github.com/Kylart/KawAnime.git
Fixed problem on click search where the selected item was not the one given in the end
This commit is contained in:
parent
aaff5ae8db
commit
3277f84a8d
|
@ -18,12 +18,11 @@
|
|||
v-flex(xs12)
|
||||
v-layout(row, wrap, justify-center)
|
||||
template(v-if='results.length', v-for='item in results')
|
||||
v-flex.elem(xs3, @click='search(item.name)')
|
||||
v-flex.elem(xs3, @click='search(item)')
|
||||
v-layout.elem-content.elevation-3(
|
||||
wrap,
|
||||
justify-center,
|
||||
v-ripple='true',
|
||||
@click.all='search(item.name)'
|
||||
v-ripple='true'
|
||||
)
|
||||
v-flex(xs8)
|
||||
img.elem-picture(:src='item.image_url', height='140')
|
||||
|
@ -50,16 +49,16 @@
|
|||
this.searchTerm = ''
|
||||
this.$refs.input.focus()
|
||||
},
|
||||
async search (name) {
|
||||
this.searchTerm = name
|
||||
async search (item) {
|
||||
this.searchTerm = item.name
|
||||
|
||||
if (this.$store.state.search.info.info.title === name) {
|
||||
if (this.$store.state.search.info.info.title === item.name) {
|
||||
this.$store.commit('search/showInfo', true)
|
||||
this.searchShow = false
|
||||
} else {
|
||||
this.searchShow = false
|
||||
|
||||
this.$store.dispatch('search/fromName', name)
|
||||
this.$store.dispatch('search/fromUrl', item)
|
||||
}
|
||||
},
|
||||
quickSearch: _.debounce(
|
||||
|
@ -68,7 +67,9 @@
|
|||
|
||||
if (term && term.length > 2) {
|
||||
try {
|
||||
const {data, status} = await axios.get(`searchTermOnMal?term=${term}`)
|
||||
const {data, status} = await axios.get(`searchTermOnMal`, {
|
||||
params: {term}
|
||||
})
|
||||
|
||||
if (status === 200) {
|
||||
this.results = data.categories[0].items
|
||||
|
|
|
@ -48,7 +48,7 @@
|
|||
"horrible-api": "^1.0.5",
|
||||
"lodash": "^4.17.4",
|
||||
"lru-cache": "^4.0.2",
|
||||
"mal-scraper": "^1.4.1",
|
||||
"mal-scraper": "^1.5.0",
|
||||
"moment": "^2.19.1",
|
||||
"nyaapi": "^1.2.2",
|
||||
"progress-bar-webpack-plugin": "^1.10.0",
|
||||
|
|
|
@ -223,7 +223,9 @@ let routes = [
|
|||
},
|
||||
(app) => {
|
||||
app.get('/getInfoFromMal', ({query}, res) => {
|
||||
search.searchOnMal(query, res)
|
||||
query.url
|
||||
? search.fromUrl(query, res)
|
||||
: search.fromName(query, res)
|
||||
})
|
||||
},
|
||||
/* istanbul ignore next */ (app) => {
|
||||
|
|
|
@ -22,7 +22,7 @@ const searchTerm = (query, res) => {
|
|||
})
|
||||
}
|
||||
|
||||
const searchOnMal = (query, res) => {
|
||||
const fromName = (query, res) => {
|
||||
malScraper.getInfoFromName(query.term).then((data) => {
|
||||
res.type('application/json')
|
||||
res.status(200).send(JSON.stringify(data))
|
||||
|
@ -32,7 +32,18 @@ const searchOnMal = (query, res) => {
|
|||
})
|
||||
}
|
||||
|
||||
const fromUrl = (query, res) => {
|
||||
malScraper.getInfoFromUrl(query.url).then((data) => {
|
||||
res.type('application/json')
|
||||
res.status(200).send(JSON.stringify(data))
|
||||
}).catch(/* istanbul ignore next */(err) => {
|
||||
console.log(err.message)
|
||||
res.status(204).send()
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
searchTerm,
|
||||
searchOnMal
|
||||
fromName,
|
||||
fromUrl
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import {axios} from '../../utils'
|
||||
|
||||
export default {
|
||||
async fromName ({commit, state}, name) {
|
||||
async fromUrl ({commit, state}, item) {
|
||||
const {name, url} = item
|
||||
|
||||
if (name === state.info.term) {
|
||||
commit('showInfo', true)
|
||||
} else {
|
||||
|
@ -9,9 +11,7 @@ export default {
|
|||
commit('setInfoLoading', true)
|
||||
commit('showInfo', true)
|
||||
const {data, status} = await axios.get(`getInfoFromMal`, {
|
||||
params: {
|
||||
term: name
|
||||
}
|
||||
params: {url}
|
||||
})
|
||||
|
||||
commit('setInfoLoading', false)
|
||||
|
|
|
@ -404,13 +404,24 @@ test('/searchTermOnMal route exits and return 10 elements', async t => {
|
|||
t.is(data.categories[0].items.length, 10)
|
||||
})
|
||||
|
||||
test('/getInfoFromMal route exits and return an object with name', async t => {
|
||||
test('/getInfoFromMal route exits if given name and return an object with name', async t => {
|
||||
const { data, status } = await axios.get(`${uri}/getInfoFromMal?term=sakura trick`)
|
||||
|
||||
t.is(status, 200)
|
||||
t.is(data.title, 'Sakura Trick')
|
||||
})
|
||||
|
||||
test('/getInfoFromMal route exits if given url and return an object with name', async t => {
|
||||
const { data, status } = await axios.get(`${uri}/getInfoFromMal`, {
|
||||
params: {
|
||||
url: 'https://myanimelist.net/anime/20047/Sakura_Trick'
|
||||
}
|
||||
})
|
||||
|
||||
t.is(status, 200)
|
||||
t.is(data.title, 'Sakura Trick')
|
||||
})
|
||||
|
||||
test('/_env route exits and return string containing platform\'s name', async t => {
|
||||
const { data, status } = await axios.get(`${uri}/_env`)
|
||||
|
||||
|
|
Loading…
Reference in New Issue