2020-06-29 16:49:33 +00:00
|
|
|
<template>
|
2020-09-17 16:11:41 +00:00
|
|
|
<div id="search_tab" class="main_tabcontent" ref="root">
|
2020-09-16 20:22:55 +00:00
|
|
|
<div v-show="!showSearchTab">
|
2020-07-21 09:09:47 +00:00
|
|
|
<h2>{{ $t('search.startSearching') }}</h2>
|
|
|
|
<p>{{ $t('search.description') }}</p>
|
2020-06-29 16:49:33 +00:00
|
|
|
</div>
|
2020-09-16 16:59:25 +00:00
|
|
|
|
2020-09-16 20:22:55 +00:00
|
|
|
<div v-show="showSearchTab">
|
2020-09-16 16:59:25 +00:00
|
|
|
<ul class="section-tabs">
|
|
|
|
<li
|
|
|
|
class="section-tabs__tab"
|
|
|
|
v-for="tab in tabs"
|
|
|
|
:key="tab.name"
|
|
|
|
@click="currentTab = tab"
|
|
|
|
:class="{ active: currentTab.name === tab.name }"
|
|
|
|
>
|
|
|
|
{{ tab.name }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2020-09-17 16:11:41 +00:00
|
|
|
<keep-alive>
|
|
|
|
<component
|
|
|
|
:is="currentTab.component"
|
|
|
|
:results="results"
|
|
|
|
@add-to-queue="addToQueue"
|
|
|
|
@artist-view="artistView"
|
|
|
|
@album-view="albumView"
|
|
|
|
@playlist-view="playlistView"
|
|
|
|
@change-search-tab="changeSearchTab"
|
|
|
|
></component>
|
|
|
|
</keep-alive>
|
2020-06-29 16:49:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-16 16:59:25 +00:00
|
|
|
import BaseLoadingPlaceholder from '@components/BaseLoadingPlaceholder.vue'
|
|
|
|
import ResultsAll from '@components/search/ResultsAll.vue'
|
|
|
|
import ResultsAlbums from '@components/search/ResultsAlbums.vue'
|
|
|
|
import ResultsArtists from '@components/search/ResultsArtists.vue'
|
|
|
|
import ResultsPlaylists from '@components/search/ResultsPlaylists.vue'
|
|
|
|
import ResultsTracks from '@components/search/ResultsTracks.vue'
|
|
|
|
|
2020-07-16 22:11:28 +00:00
|
|
|
import { socket } from '@/utils/socket'
|
2020-09-17 16:11:41 +00:00
|
|
|
import { showView } from '@js/tabs'
|
|
|
|
import { sendAddToQueue } from '@/utils/downloads'
|
|
|
|
import { numberWithDots, convertDuration } from '@/utils/utils'
|
|
|
|
import EventBus from '@/utils/EventBus'
|
2020-06-29 16:49:33 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
BaseLoadingPlaceholder
|
|
|
|
},
|
|
|
|
data() {
|
2020-09-16 16:59:25 +00:00
|
|
|
const $t = this.$t.bind(this)
|
|
|
|
const $tc = this.$tc.bind(this)
|
|
|
|
|
2020-06-29 16:49:33 +00:00
|
|
|
return {
|
2020-09-16 16:59:25 +00:00
|
|
|
currentTab: {
|
|
|
|
name: '',
|
|
|
|
component: {}
|
|
|
|
},
|
|
|
|
tabs: [
|
|
|
|
{
|
|
|
|
name: $t('globals.listTabs.all'),
|
2020-09-16 20:22:55 +00:00
|
|
|
searchType: 'all',
|
2020-09-16 16:59:25 +00:00
|
|
|
component: ResultsAll
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: $tc('globals.listTabs.track', 2),
|
2020-09-16 20:22:55 +00:00
|
|
|
searchType: 'track',
|
2020-09-16 16:59:25 +00:00
|
|
|
component: ResultsTracks
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: $tc('globals.listTabs.album', 2),
|
2020-09-16 20:22:55 +00:00
|
|
|
searchType: 'album',
|
2020-09-16 16:59:25 +00:00
|
|
|
component: ResultsAlbums
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: $tc('globals.listTabs.artist', 2),
|
2020-09-16 20:22:55 +00:00
|
|
|
searchType: 'artist',
|
2020-09-16 16:59:25 +00:00
|
|
|
component: ResultsArtists
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: $tc('globals.listTabs.playlist', 2),
|
2020-09-16 20:22:55 +00:00
|
|
|
searchType: 'playlist',
|
2020-09-16 16:59:25 +00:00
|
|
|
component: ResultsPlaylists
|
|
|
|
}
|
|
|
|
],
|
2020-06-29 16:49:33 +00:00
|
|
|
results: {
|
|
|
|
query: '',
|
|
|
|
allTab: {
|
|
|
|
ORDER: [],
|
|
|
|
TOP_RESULT: [],
|
|
|
|
ALBUM: {},
|
|
|
|
ARTIST: {},
|
|
|
|
TRACK: {},
|
|
|
|
PLAYLIST: {}
|
|
|
|
},
|
|
|
|
trackTab: {
|
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0,
|
|
|
|
loaded: false
|
|
|
|
},
|
|
|
|
albumTab: {
|
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0,
|
|
|
|
loaded: false
|
|
|
|
},
|
|
|
|
artistTab: {
|
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0,
|
|
|
|
loaded: false
|
|
|
|
},
|
|
|
|
playlistTab: {
|
|
|
|
data: [],
|
|
|
|
next: 0,
|
|
|
|
total: 0,
|
|
|
|
loaded: false
|
|
|
|
}
|
2020-09-16 16:59:25 +00:00
|
|
|
}
|
2020-06-29 16:49:33 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-16 20:22:55 +00:00
|
|
|
computed: {
|
|
|
|
showSearchTab() {
|
|
|
|
return this.results.query !== ''
|
2020-09-17 16:11:41 +00:00
|
|
|
},
|
|
|
|
loadedTabs() {
|
|
|
|
const loaded = []
|
|
|
|
|
|
|
|
for (const resultKey in this.results) {
|
|
|
|
if (this.results.hasOwnProperty(resultKey)) {
|
|
|
|
const result = this.results[resultKey]
|
|
|
|
|
|
|
|
if (result.loaded) {
|
|
|
|
loaded.push(resultKey.replace(/Tab/g, ''))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return loaded
|
2020-09-16 20:22:55 +00:00
|
|
|
}
|
|
|
|
},
|
2020-07-06 19:55:28 +00:00
|
|
|
props: {
|
2020-09-17 16:31:07 +00:00
|
|
|
performScrolledSearch: {
|
|
|
|
type: Boolean,
|
2020-07-06 19:55:28 +00:00
|
|
|
required: false
|
|
|
|
}
|
|
|
|
},
|
2020-09-16 20:22:55 +00:00
|
|
|
created() {
|
|
|
|
this.currentTab = this.tabs[0]
|
|
|
|
},
|
2020-07-06 19:55:28 +00:00
|
|
|
mounted() {
|
|
|
|
EventBus.$on('mainSearch:checkLoadMoreContent', this.checkLoadMoreContent)
|
2020-09-17 16:11:41 +00:00
|
|
|
this.$root.$on('mainSearch:showNewResults', this.checkIfShowNewResults)
|
2020-09-24 11:48:37 +00:00
|
|
|
this.$root.$on('mainSearch:updateResults', this.checkIfUpdateResults)
|
2020-07-06 19:55:28 +00:00
|
|
|
|
|
|
|
socket.on('mainSearch', this.handleMainSearch)
|
|
|
|
socket.on('search', this.handleSearch)
|
|
|
|
},
|
2020-06-29 16:49:33 +00:00
|
|
|
methods: {
|
|
|
|
artistView: showView.bind(null, 'artist'),
|
|
|
|
albumView: showView.bind(null, 'album'),
|
|
|
|
playlistView: showView.bind(null, 'playlist'),
|
2020-09-16 20:22:55 +00:00
|
|
|
changeSearchTab(sectionName) {
|
|
|
|
sectionName = sectionName.toLowerCase()
|
|
|
|
|
|
|
|
let newTab = this.tabs.find(tab => {
|
|
|
|
return tab.searchType === sectionName
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!newTab) {
|
|
|
|
console.error(`No tab ${sectionName} found`)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-09-17 16:11:41 +00:00
|
|
|
window.scrollTo(0, 0)
|
2020-09-16 20:22:55 +00:00
|
|
|
this.currentTab = newTab
|
|
|
|
},
|
2020-09-17 16:11:41 +00:00
|
|
|
checkIfShowNewResults(term, mainSelected) {
|
|
|
|
let needToPerformNewSearch = term !== this.results.query || mainSelected == 'search_tab'
|
2020-06-29 16:49:33 +00:00
|
|
|
|
2020-09-17 16:11:41 +00:00
|
|
|
if (needToPerformNewSearch) {
|
|
|
|
this.showNewResults(term)
|
2020-06-29 16:49:33 +00:00
|
|
|
}
|
|
|
|
},
|
2020-09-24 11:48:37 +00:00
|
|
|
checkIfUpdateResults(term, mainSelected) {
|
|
|
|
let needToUpdateSearch = term === this.results.query && this.currentTab.searchType !== 'all'
|
|
|
|
|
|
|
|
if (needToUpdateSearch) {
|
|
|
|
let resetObj = { data: [], next: 0, total: 0, loaded: false }
|
|
|
|
this.results[this.currentTab.searchType+"Tab"] = { ...resetObj }
|
|
|
|
this.search(this.currentTab.searchType)
|
|
|
|
}
|
|
|
|
},
|
2020-09-17 16:11:41 +00:00
|
|
|
showNewResults(term) {
|
|
|
|
socket.emit('mainSearch', { term })
|
2020-09-15 20:44:29 +00:00
|
|
|
|
2020-09-17 16:11:41 +00:00
|
|
|
// Showing loading placeholder
|
|
|
|
this.$root.$emit('updateSearchLoadingState', true)
|
|
|
|
this.currentTab = this.tabs[0]
|
2020-06-29 16:49:33 +00:00
|
|
|
},
|
|
|
|
checkLoadMoreContent(searchSelected) {
|
|
|
|
if (this.results[searchSelected.split('_')[0] + 'Tab'].data.length !== 0) return
|
|
|
|
|
|
|
|
this.search(searchSelected.split('_')[0])
|
|
|
|
},
|
|
|
|
addToQueue(e) {
|
2020-09-17 16:11:41 +00:00
|
|
|
sendAddToQueue(e.currentTarget.dataset.link)
|
2020-06-29 16:49:33 +00:00
|
|
|
},
|
2020-09-17 16:11:41 +00:00
|
|
|
numberWithDots,
|
|
|
|
convertDuration,
|
2020-06-29 16:49:33 +00:00
|
|
|
search(type) {
|
|
|
|
socket.emit('search', {
|
|
|
|
term: this.results.query,
|
2020-09-17 16:31:07 +00:00
|
|
|
type,
|
|
|
|
start: this.results[`${type}Tab`].next,
|
2020-06-29 16:49:33 +00:00
|
|
|
nb: 30
|
|
|
|
})
|
|
|
|
},
|
2020-09-17 16:31:07 +00:00
|
|
|
scrolledSearch() {
|
|
|
|
if (this.currentTab.searchType === 'all') return
|
|
|
|
|
|
|
|
let currentTab = `${this.currentTab.searchType}Tab`
|
2020-06-29 16:49:33 +00:00
|
|
|
|
|
|
|
if (this.results[currentTab].next < this.results[currentTab].total) {
|
2020-09-17 16:31:07 +00:00
|
|
|
this.search(this.currentTab.searchType)
|
2020-06-29 16:49:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
handleMainSearch(result) {
|
|
|
|
// Hiding loading placeholder
|
2020-09-15 20:51:50 +00:00
|
|
|
this.$root.$emit('updateSearchLoadingState', false)
|
2020-06-29 16:49:33 +00:00
|
|
|
|
|
|
|
let resetObj = { data: [], next: 0, total: 0, loaded: false }
|
|
|
|
|
|
|
|
this.results.allTab = result
|
|
|
|
this.results.trackTab = { ...resetObj }
|
|
|
|
this.results.albumTab = { ...resetObj }
|
|
|
|
this.results.artistTab = { ...resetObj }
|
|
|
|
this.results.playlistTab = { ...resetObj }
|
|
|
|
this.results.query = result.QUERY
|
|
|
|
},
|
|
|
|
handleSearch(result) {
|
|
|
|
const { next: nextResult, total, type, data } = result
|
|
|
|
|
|
|
|
let currentTab = type + 'Tab'
|
|
|
|
let next = 0
|
|
|
|
|
|
|
|
if (nextResult) {
|
|
|
|
next = parseInt(nextResult.match(/index=(\d*)/)[1])
|
|
|
|
} else {
|
|
|
|
next = total
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.results[currentTab].total != total) {
|
|
|
|
this.results[currentTab].total = total
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.results[currentTab].next != next) {
|
|
|
|
this.results[currentTab].next = next
|
|
|
|
this.results[currentTab].data = this.results[currentTab].data.concat(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.results[currentTab].loaded = true
|
2020-09-17 16:11:41 +00:00
|
|
|
},
|
|
|
|
isTabLoaded(tab) {
|
|
|
|
return this.loadedTabs.indexOf(tab.searchType) !== -1 || tab.searchType === 'all'
|
2020-06-29 16:49:33 +00:00
|
|
|
}
|
|
|
|
},
|
2020-07-06 19:55:28 +00:00
|
|
|
watch: {
|
2020-09-17 16:31:07 +00:00
|
|
|
performScrolledSearch(needToSearch) {
|
|
|
|
if (!needToSearch) return
|
2020-06-29 16:49:33 +00:00
|
|
|
|
2020-09-17 16:31:07 +00:00
|
|
|
this.scrolledSearch(needToSearch)
|
2020-09-16 20:22:55 +00:00
|
|
|
},
|
|
|
|
currentTab(newTab) {
|
2020-09-17 16:11:41 +00:00
|
|
|
if (this.isTabLoaded(newTab)) return
|
|
|
|
|
2020-09-16 20:22:55 +00:00
|
|
|
this.search(newTab.searchType)
|
2020-07-06 19:55:28 +00:00
|
|
|
}
|
2020-06-29 16:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2020-07-20 20:31:54 +00:00
|
|
|
</style>
|