Commit a6707980 authored by SpinShare's avatar SpinShare

added search timeout for less lag during search

parent 84e4bd32
...@@ -50,7 +50,8 @@ ...@@ -50,7 +50,8 @@
searchQuery: "", searchQuery: "",
searchResultsUsers: [], searchResultsUsers: [],
searchResultsSongs: [], searchResultsSongs: [],
apiFinished: false apiFinished: false,
searchTimeout: null
} }
}, },
mounted: function() { mounted: function() {
...@@ -77,24 +78,34 @@ ...@@ -77,24 +78,34 @@
}); });
}, },
search: function() { search: function() {
let ssapi = new SSAPI(process.env.NODE_ENV === 'development'); console.log("[SEARCH] Search Timeout Initiazed...");
this.$data.apiFinished = false;
if(this.$data.searchQuery != "") { if(this.$data.searchTimeout) {
ssapi.search(this.$data.searchQuery).then((data) => { clearTimeout(this.$data.searchTimeout);
if(data.status == 200) { }
this.$data.searchResultsUsers = data.data.users;
this.$data.searchResultsSongs = data.data.songs;
this.$data.apiFinished = true; this.$data.searchTimeout = setTimeout(() => {
} console.log("[SEARCH] Executing Search...");
});
} else {
this.$data.searchResultsUsers = [];
this.$data.searchResultsSongs = [];
let ssapi = new SSAPI(process.env.NODE_ENV === 'development');
this.$data.apiFinished = false; this.$data.apiFinished = false;
}
if(this.$data.searchQuery != "") {
ssapi.search(this.$data.searchQuery).then((data) => {
if(data.status == 200) {
this.$data.searchResultsUsers = data.data.users;
this.$data.searchResultsSongs = data.data.songs;
this.$data.apiFinished = true;
}
});
} else {
this.$data.searchResultsUsers = [];
this.$data.searchResultsSongs = [];
this.$data.apiFinished = false;
}
}, 500);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment