Newer
Older
Eliot Berriot
committed
<template>
<div>
<h2><translate>Search for some music</translate></h2>
Eliot Berriot
committed
<div :class="['ui', {'loading': isLoading }, 'search']">
<div class="ui icon big input">
<i class="search icon"></i>
<input ref="search" class="prompt" :placeholder="labels.searchPlaceholder" v-model.trim="query" type="text" />
Eliot Berriot
committed
</div>
</div>
<template v-if="query.length > 0">
<h3 class="ui title"><translate>Artists</translate></h3>
<div v-if="results.artists.length > 0">
<div class="ui cards">
<artist-card :key="artist.id" v-for="artist in results.artists" :artist="artist" ></artist-card>
Eliot Berriot
committed
</div>
</div>
<p v-else><translate>No artist matched your query</translate></p>
Eliot Berriot
committed
</template>
<template v-if="query.length > 0">
<h3 class="ui title"><translate>Albums</translate></h3>
Eliot Berriot
committed
<div v-if="results.albums.length > 0" class="ui stackable three column grid">
<div class="column" :key="album.id" v-for="album in results.albums">
<album-card class="fluid" :album="album" ></album-card>
</div>
</div>
<p v-else><translate>No album matched your query</translate></p>
Eliot Berriot
committed
</template>
</div>
</template>
<script>
import _ from '@/lodash'
Eliot Berriot
committed
import logger from '@/logging'
import AlbumCard from '@/components/audio/album/Card'
import ArtistCard from '@/components/audio/artist/Card'
export default {
components: {
AlbumCard,
ArtistCard
},
props: {
autofocus: {type: Boolean, default: false}
},
data () {
return {
query: '',
results: {
albums: [],
artists: []
},
Eliot Berriot
committed
}
},
mounted () {
if (this.autofocus) {
this.$refs.search.focus()
}
this.search()
},
searchPlaceholder: this.$gettext('Artist, album, track…')
Eliot Berriot
committed
methods: {
search: _.debounce(function () {
Eliot Berriot
committed
if (this.query.length < 1) {
return
}
var self = this
self.isLoading = true
logger.default.debug('Searching track matching "' + this.query + '"')
let params = {
query: this.query
}
Eliot Berriot
committed
}).then((response) => {
self.results = self.castResults(response.data)
self.isLoading = false
})
Eliot Berriot
committed
castResults (results) {
return {
albums: results.albums,
artists: results.artists