fix: scrolled search

This commit is contained in:
Roberto Tonino 2020-09-17 18:31:07 +02:00
parent 2eec8a5c3f
commit 2ffafb7616
3 changed files with 32 additions and 43 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,9 @@
<template>
<!-- <section id="content" @scroll="handleContentScroll" ref="content"> -->
<section id="content">
<section id="content" @scroll="$route.name === 'Search' ? handleContentScroll($event) : null" ref="content">
<div id="container">
<BaseLoadingPlaceholder id="search_placeholder" text="Searching..." :hidden="!loading" />
<router-view v-show="!loading"></router-view>
<router-view v-show="!loading" :perform-scrolled-search="performScrolledSearch"></router-view>
</div>
</section>
</template>
@ -50,31 +49,23 @@ export default {
BaseLoadingPlaceholder
},
data: () => ({
newScrolled: null,
performScrolledSearch: false,
loading: false
}),
mounted() {
this.$root.$on('updateSearchLoadingState', loading => {
this.loading = loading
})
},
methods: {
handleContentScroll: debounce(async function () {
if (this.$refs.content.scrollTop + this.$refs.content.clientHeight < this.$refs.content.scrollHeight) return
this.performScrolledSearch = true
await this.$nextTick()
this.performScrolledSearch = false
}, 100)
}
// methods: {
// handleContentScroll: debounce(async function () {
// if (this.$refs.content.scrollTop + this.$refs.content.clientHeight < this.$refs.content.scrollHeight) return
// if (
// main_selected !== 'search_tab' ||
// ['track_search', 'album_search', 'artist_search', 'playlist_search'].indexOf(window.search_selected) === -1
// ) {
// return
// }
// this.newScrolled = window.search_selected.split('_')[0]
// await this.$nextTick()
// this.newScrolled = null
// }, 100)
// }
}
</script>

View File

@ -145,8 +145,8 @@ export default {
}
},
props: {
scrolledSearchType: {
type: String,
performScrolledSearch: {
type: Boolean,
required: false
}
},
@ -206,24 +206,22 @@ export default {
numberWithDots,
convertDuration,
search(type) {
console.log('search')
console.log('search method called')
socket.emit('search', {
term: this.results.query,
type: type,
start: this.results[type + 'Tab'].next,
type,
start: this.results[`${type}Tab`].next,
nb: 30
})
},
scrolledSearch(type) {
let currentTab = type + 'Tab'
scrolledSearch() {
if (this.currentTab.searchType === 'all') return
let currentTab = `${this.currentTab.searchType}Tab`
if (this.results[currentTab].next < this.results[currentTab].total) {
socket.emit('search', {
term: this.results.query,
type: type,
start: this.results[currentTab].next,
nb: 30
})
this.search(this.currentTab.searchType)
}
},
handleMainSearch(result) {
@ -269,10 +267,10 @@ export default {
}
},
watch: {
scrolledSearchType(newType) {
if (!newType) return
performScrolledSearch(needToSearch) {
if (!needToSearch) return
this.scrolledSearch(newType)
this.scrolledSearch(needToSearch)
},
currentTab(newTab) {
if (this.isTabLoaded(newTab)) return