feat: caching of search tabs already loaded
This commit is contained in:
parent
139ef91b6e
commit
2eec8a5c3f
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="search_tab" class="main_tabcontent" @click="handleSearchTabClick" ref="root">
|
<div id="search_tab" class="main_tabcontent" ref="root">
|
||||||
<div v-show="!showSearchTab">
|
<div v-show="!showSearchTab">
|
||||||
<h2>{{ $t('search.startSearching') }}</h2>
|
<h2>{{ $t('search.startSearching') }}</h2>
|
||||||
<p>{{ $t('search.description') }}</p>
|
<p>{{ $t('search.description') }}</p>
|
||||||
@ -18,15 +18,17 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<component
|
<keep-alive>
|
||||||
:is="currentTab.component"
|
<component
|
||||||
:results="results"
|
:is="currentTab.component"
|
||||||
@add-to-queue="addToQueue"
|
:results="results"
|
||||||
@artist-view="artistView"
|
@add-to-queue="addToQueue"
|
||||||
@album-view="albumView"
|
@artist-view="artistView"
|
||||||
@playlist-view="playlistView"
|
@album-view="albumView"
|
||||||
@change-search-tab="changeSearchTab"
|
@playlist-view="playlistView"
|
||||||
></component>
|
@change-search-tab="changeSearchTab"
|
||||||
|
></component>
|
||||||
|
</keep-alive>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -40,11 +42,10 @@ import ResultsPlaylists from '@components/search/ResultsPlaylists.vue'
|
|||||||
import ResultsTracks from '@components/search/ResultsTracks.vue'
|
import ResultsTracks from '@components/search/ResultsTracks.vue'
|
||||||
|
|
||||||
import { socket } from '@/utils/socket'
|
import { socket } from '@/utils/socket'
|
||||||
import { showView } from '@js/tabs.js'
|
import { showView } from '@js/tabs'
|
||||||
import Downloads from '@/utils/downloads'
|
import { sendAddToQueue } from '@/utils/downloads'
|
||||||
import Utils from '@/utils/utils'
|
import { numberWithDots, convertDuration } from '@/utils/utils'
|
||||||
import { changeTab } from '@js/tabs.js'
|
import EventBus from '@/utils/EventBus'
|
||||||
import EventBus from '@/utils/EventBus.js'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@ -126,6 +127,21 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
showSearchTab() {
|
showSearchTab() {
|
||||||
return this.results.query !== ''
|
return this.results.query !== ''
|
||||||
|
},
|
||||||
|
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
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
@ -139,8 +155,8 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
EventBus.$on('mainSearch:checkLoadMoreContent', this.checkLoadMoreContent)
|
EventBus.$on('mainSearch:checkLoadMoreContent', this.checkLoadMoreContent)
|
||||||
|
this.$root.$on('mainSearch:showNewResults', this.checkIfShowNewResults)
|
||||||
|
|
||||||
this.$root.$on('mainSearch:showNewResults', this.showNewResults)
|
|
||||||
socket.on('mainSearch', this.handleMainSearch)
|
socket.on('mainSearch', this.handleMainSearch)
|
||||||
socket.on('search', this.handleSearch)
|
socket.on('search', this.handleSearch)
|
||||||
},
|
},
|
||||||
@ -148,15 +164,6 @@ export default {
|
|||||||
artistView: showView.bind(null, 'artist'),
|
artistView: showView.bind(null, 'artist'),
|
||||||
albumView: showView.bind(null, 'album'),
|
albumView: showView.bind(null, 'album'),
|
||||||
playlistView: showView.bind(null, 'playlist'),
|
playlistView: showView.bind(null, 'playlist'),
|
||||||
playPausePreview(e) {
|
|
||||||
EventBus.$emit('trackPreview:playPausePreview', e)
|
|
||||||
},
|
|
||||||
previewMouseEnter(e) {
|
|
||||||
EventBus.$emit('trackPreview:previewMouseEnter', e)
|
|
||||||
},
|
|
||||||
previewMouseLeave(e) {
|
|
||||||
EventBus.$emit('trackPreview:previewMouseLeave', e)
|
|
||||||
},
|
|
||||||
changeSearchTab(sectionName) {
|
changeSearchTab(sectionName) {
|
||||||
sectionName = sectionName.toLowerCase()
|
sectionName = sectionName.toLowerCase()
|
||||||
|
|
||||||
@ -169,85 +176,35 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.scrollTo(0, 0)
|
||||||
this.currentTab = newTab
|
this.currentTab = newTab
|
||||||
},
|
},
|
||||||
handleSearchTabClick(event) {
|
checkIfShowNewResults(term, mainSelected) {
|
||||||
const {
|
console.log('check if show new results')
|
||||||
target,
|
|
||||||
target: { id }
|
|
||||||
} = event
|
|
||||||
let selectedTab = null
|
|
||||||
|
|
||||||
switch (id) {
|
|
||||||
case 'search_all_tab':
|
|
||||||
selectedTab = 'main_search'
|
|
||||||
break
|
|
||||||
case 'search_track_tab':
|
|
||||||
selectedTab = 'track_search'
|
|
||||||
break
|
|
||||||
case 'search_album_tab':
|
|
||||||
selectedTab = 'album_search'
|
|
||||||
break
|
|
||||||
case 'search_artist_tab':
|
|
||||||
selectedTab = 'artist_search'
|
|
||||||
break
|
|
||||||
case 'search_playlist_tab':
|
|
||||||
selectedTab = 'playlist_search'
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!selectedTab) return
|
|
||||||
|
|
||||||
console.log('asfsdf')
|
|
||||||
|
|
||||||
changeTab(target, 'search', selectedTab)
|
|
||||||
},
|
|
||||||
handleClickTopResult(event) {
|
|
||||||
let topResultType = this.results.allTab.TOP_RESULT[0].type
|
|
||||||
|
|
||||||
switch (topResultType) {
|
|
||||||
case 'artist':
|
|
||||||
this.artistView(event)
|
|
||||||
break
|
|
||||||
case 'album':
|
|
||||||
this.albumView(event)
|
|
||||||
break
|
|
||||||
case 'playlist':
|
|
||||||
this.playlistView(event)
|
|
||||||
break
|
|
||||||
|
|
||||||
default:
|
|
||||||
break
|
|
||||||
}
|
|
||||||
},
|
|
||||||
showNewResults(term, mainSelected) {
|
|
||||||
console.log('show new results')
|
|
||||||
let needToPerformNewSearch = term !== this.results.query || mainSelected == 'search_tab'
|
let needToPerformNewSearch = term !== this.results.query || mainSelected == 'search_tab'
|
||||||
|
|
||||||
if (needToPerformNewSearch) {
|
if (needToPerformNewSearch) {
|
||||||
// this.showSearchTab = false
|
this.showNewResults(term)
|
||||||
socket.emit('mainSearch', { term })
|
|
||||||
|
|
||||||
// Showing loading placeholder
|
|
||||||
this.$root.$emit('updateSearchLoadingState', true)
|
|
||||||
} else {
|
|
||||||
// this.showSearchTab = true
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
showNewResults(term) {
|
||||||
|
console.log('show new results')
|
||||||
|
socket.emit('mainSearch', { term })
|
||||||
|
|
||||||
|
// Showing loading placeholder
|
||||||
|
this.$root.$emit('updateSearchLoadingState', true)
|
||||||
|
this.currentTab = this.tabs[0]
|
||||||
|
},
|
||||||
checkLoadMoreContent(searchSelected) {
|
checkLoadMoreContent(searchSelected) {
|
||||||
if (this.results[searchSelected.split('_')[0] + 'Tab'].data.length !== 0) return
|
if (this.results[searchSelected.split('_')[0] + 'Tab'].data.length !== 0) return
|
||||||
|
|
||||||
this.search(searchSelected.split('_')[0])
|
this.search(searchSelected.split('_')[0])
|
||||||
},
|
},
|
||||||
addToQueue(e) {
|
addToQueue(e) {
|
||||||
console.log('add to queue')
|
sendAddToQueue(e.currentTarget.dataset.link)
|
||||||
Downloads.sendAddToQueue(e.currentTarget.dataset.link)
|
|
||||||
},
|
},
|
||||||
numberWithDots: Utils.numberWithDots,
|
numberWithDots,
|
||||||
convertDuration: Utils.convertDuration,
|
convertDuration,
|
||||||
search(type) {
|
search(type) {
|
||||||
console.log('search')
|
console.log('search')
|
||||||
socket.emit('search', {
|
socket.emit('search', {
|
||||||
@ -306,6 +263,9 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.results[currentTab].loaded = true
|
this.results[currentTab].loaded = true
|
||||||
|
},
|
||||||
|
isTabLoaded(tab) {
|
||||||
|
return this.loadedTabs.indexOf(tab.searchType) !== -1 || tab.searchType === 'all'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@ -315,6 +275,8 @@ export default {
|
|||||||
this.scrolledSearch(newType)
|
this.scrolledSearch(newType)
|
||||||
},
|
},
|
||||||
currentTab(newTab) {
|
currentTab(newTab) {
|
||||||
|
if (this.isTabLoaded(newTab)) return
|
||||||
|
|
||||||
this.search(newTab.searchType)
|
this.search(newTab.searchType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ export function changeTab(sidebarEl, section, tabName) {
|
|||||||
window.windows_stack = []
|
window.windows_stack = []
|
||||||
window.currentStack = {}
|
window.currentStack = {}
|
||||||
|
|
||||||
console.log(Array.from(arguments))
|
|
||||||
|
|
||||||
// * Only in section search
|
// * Only in section search
|
||||||
updateTabLink(section)
|
updateTabLink(section)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { socket } from '@/utils/socket'
|
import { socket } from '@/utils/socket'
|
||||||
|
|
||||||
function sendAddToQueue(url, bitrate = null) {
|
export function sendAddToQueue(url, bitrate = null) {
|
||||||
if (!url) return
|
if (!url) return
|
||||||
|
|
||||||
socket.emit('addToQueue', { url, bitrate }, () => {})
|
socket.emit('addToQueue', { url, bitrate }, () => {})
|
||||||
|
Loading…
Reference in New Issue
Block a user