2020-04-28 18:42:22 +00:00
|
|
|
import { socket } from '../socket.js'
|
|
|
|
import { artistView, albumView, playlistView } from '../tabs.js'
|
|
|
|
import Downloads from '../downloads.js'
|
|
|
|
import QualityModal from '../quality-modal.js'
|
|
|
|
import TrackPreview from '../track-preview.js'
|
|
|
|
import Utils from '../utils.js'
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-22 20:06:59 +00:00
|
|
|
const MainSearch = new Vue({
|
2020-04-21 20:20:19 +00:00
|
|
|
data: {
|
|
|
|
names: {
|
|
|
|
TOP_RESULT: 'Top Result',
|
|
|
|
TRACK: 'Tracks',
|
|
|
|
ARTIST: 'Artists',
|
|
|
|
ALBUM: 'Albums',
|
|
|
|
PLAYLIST: 'Playlists'
|
|
|
|
},
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-22 20:06:59 +00:00
|
|
|
artistView,
|
|
|
|
albumView,
|
|
|
|
playlistView,
|
2020-04-28 18:42:22 +00:00
|
|
|
playPausePreview: TrackPreview.playPausePreview,
|
|
|
|
previewMouseEnter: TrackPreview.previewMouseEnter,
|
|
|
|
previewMouseLeave: TrackPreview.previewMouseLeave,
|
2020-04-22 20:06:59 +00:00
|
|
|
handleClickTopResult(event) {
|
|
|
|
let topResultType = this.results.allTab.TOP_RESULT[0].type
|
|
|
|
|
|
|
|
switch (topResultType) {
|
|
|
|
case 'artist':
|
2020-04-23 19:26:47 +00:00
|
|
|
this.artistView(event)
|
2020-04-22 20:06:59 +00:00
|
|
|
break
|
|
|
|
case 'album':
|
2020-04-23 19:26:47 +00:00
|
|
|
this.albumView(event)
|
2020-04-22 20:06:59 +00:00
|
|
|
break
|
|
|
|
case 'playlist':
|
2020-04-23 19:26:47 +00:00
|
|
|
this.playlistView(event)
|
2020-04-22 20:06:59 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
},
|
2020-04-21 20:20:19 +00:00
|
|
|
changeSearchTab(section) {
|
|
|
|
if (section != 'TOP_RESULT') {
|
|
|
|
document.getElementById(`search_${section.toLowerCase()}_tab`).click()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
addToQueue: function (e) {
|
2020-04-22 20:06:59 +00:00
|
|
|
Downloads.sendAddToQueue(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
|
|
|
openQualityModal: function (e) {
|
2020-04-22 20:06:59 +00:00
|
|
|
QualityModal.open(e.currentTarget.dataset.link)
|
2020-04-21 20:20:19 +00:00
|
|
|
},
|
2020-04-28 18:42:22 +00:00
|
|
|
numberWithDots: Utils.numberWithDots,
|
2020-04-26 12:27:54 +00:00
|
|
|
convertDuration: Utils.convertDuration,
|
2020-04-22 20:06:59 +00:00
|
|
|
search(type) {
|
|
|
|
socket.emit('search', {
|
|
|
|
term: this.results.query,
|
|
|
|
type: type,
|
|
|
|
start: this.results[type + 'Tab'].next,
|
|
|
|
nb: 30
|
|
|
|
})
|
|
|
|
},
|
|
|
|
scrolledSearch(type) {
|
|
|
|
if (this.results[type + 'Tab'].next < this.results[type + 'Tab'].total) {
|
|
|
|
socket.emit('search', {
|
|
|
|
term: this.results.query,
|
|
|
|
type: type,
|
|
|
|
start: this.results[type + 'Tab'].next,
|
|
|
|
nb: 30
|
|
|
|
})
|
|
|
|
}
|
2020-04-23 19:26:47 +00:00
|
|
|
},
|
|
|
|
handleMainSearch(result) {
|
|
|
|
let resetObj = { data: [], next: 0, total: 0, loaded: false }
|
|
|
|
this.results.allTab = result
|
|
|
|
this.results.query = result.QUERY
|
|
|
|
this.results.trackTab = { ...resetObj }
|
|
|
|
this.results.albumTab = { ...resetObj }
|
|
|
|
this.results.artistTab = { ...resetObj }
|
|
|
|
this.results.playlistTab = { ...resetObj }
|
|
|
|
document.getElementById('search_all_tab').click()
|
|
|
|
document.getElementById('search_tab_content').style.display = 'block'
|
|
|
|
document.getElementById('main_search_tablink').click()
|
|
|
|
},
|
|
|
|
handleSearch(result) {
|
|
|
|
let next = 0
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:26:47 +00:00
|
|
|
if (result.next) {
|
|
|
|
next = parseInt(result.next.match(/index=(\d*)/)[1])
|
|
|
|
} else {
|
|
|
|
next = result.total
|
|
|
|
}
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:26:47 +00:00
|
|
|
if (this.results[result.type + 'Tab'].total != result.total) {
|
|
|
|
this.results[result.type + 'Tab'].total = result.total
|
|
|
|
}
|
2020-04-21 20:20:19 +00:00
|
|
|
|
2020-04-23 19:26:47 +00:00
|
|
|
if (this.results[result.type + 'Tab'].next != next) {
|
|
|
|
this.results[result.type + 'Tab'].next = next
|
|
|
|
this.results[result.type + 'Tab'].data = this.results[result.type + 'Tab'].data.concat(result.data)
|
|
|
|
}
|
|
|
|
this.results[result.type + 'Tab'].loaded = true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
socket.on('mainSearch', this.handleMainSearch)
|
|
|
|
socket.on('search', this.handleSearch)
|
2020-04-21 20:20:19 +00:00
|
|
|
}
|
2020-04-23 19:26:47 +00:00
|
|
|
}).$mount('#search_tab')
|
2020-04-22 20:06:59 +00:00
|
|
|
|
|
|
|
export default MainSearch
|