wip: searching logic; wip: memorization of the last tab searched

This commit is contained in:
Roberto Tonino
2020-11-24 22:17:47 +01:00
parent b5ff097286
commit b2eb08722c
6 changed files with 185 additions and 220 deletions

View File

@@ -4,11 +4,9 @@ import { socket } from '@/utils/socket'
const searchResult = ref({})
const lastTermSearched = ref(null)
function performSearch(searchTerm) {
function performMainSearch(searchTerm) {
if (searchTerm === lastTermSearched.value) return
// TODO Handle multiple, subsequent calls
// TODO Caching
socket.emit('mainSearch', { term: searchTerm })
socket.on('mainSearch', data => {
@@ -22,26 +20,6 @@ function performSearch(searchTerm) {
export function useMainSearch() {
return {
searchResult,
performSearch
performMainSearch
}
}
// socket.on('mainSearch', saveMainSearchResult)
// saveMainSearchResult(searchResult) {
// // Hide loading placeholder
// this.$root.$emit('updateSearchLoadingState', false)
// this.results.query = searchResult.QUERY
// this.results.allTab = searchResult
// this.results.allTab.TRACK.hasLoaded = true
// this.results.allTab.ALBUM.hasLoaded = true
// this.results.allTab.ARTIST.hasLoaded = true
// this.results.allTab.PLAYLIST.hasLoaded = true
// this.results.trackTab = { ...resetObj }
// this.results.albumTab = { ...resetObj }
// this.results.artistTab = { ...resetObj }
// this.results.playlistTab = { ...resetObj }
// },

27
src/use/search.js Normal file
View File

@@ -0,0 +1,27 @@
import { ref, computed } from '@vue/composition-api'
import { socket } from '@/utils/socket'
const result = ref({})
function performSearch({ term, type, start = 0, nb = 30 }) {
console.log('perform search!')
socket.emit('search', {
term,
type,
start,
nb
})
socket.on('search', data => {
result.value = data
socket.off('search')
})
}
export function useSearch() {
return {
result,
performSearch
}
}