use queryType in populateMultiSearchResults to hide irrelevant

This commit is contained in:
simon 2022-07-20 18:01:57 +07:00
parent b520a9bfb0
commit b77d50d4ed
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 42 additions and 15 deletions

View File

@ -794,8 +794,8 @@ function searchMulti(query) {
var http = new XMLHttpRequest(); var http = new XMLHttpRequest();
http.onreadystatechange = function() { http.onreadystatechange = function() {
if (http.readyState === 4) { if (http.readyState === 4) {
allResults = JSON.parse(http.response).results; response = JSON.parse(http.response);
populateMultiSearchResults(allResults); populateMultiSearchResults(response.results, response.queryType);
} }
}; };
http.open("POST", "/process/", true); http.open("POST", "/process/", true);
@ -811,36 +811,63 @@ function getViewDefaults(view) {
return defaultView; return defaultView;
} }
function populateMultiSearchResults(allResults) { function populateMultiSearchResults(allResults, queryType) {
// videos // videos
var defaultVideo = getViewDefaults("home"); var defaultVideo = getViewDefaults("home");
var allVideos = allResults.video_results; var allVideos = allResults.video_results;
var videoBox = document.getElementById("video-results"); var videoBox = document.getElementById("video-results");
videoBox.innerHTML = ""; videoBox.innerHTML = "";
for (let index = 0; index < allVideos.length; index++) { videoBox.parentElement.style.display = "block";
const video = allVideos[index].source; if (allVideos.length > 0) {
const videoDiv = createVideo(video, defaultVideo); for (let index = 0; index < allVideos.length; index++) {
videoBox.appendChild(videoDiv); const video = allVideos[index].source;
const videoDiv = createVideo(video, defaultVideo);
videoBox.appendChild(videoDiv);
}
} else {
if (queryType === "simple" || queryType == "video") {
videoBox.innerHTML = "<p>No videos found.</p>";
} else {
videoBox.parentElement.style.display = "none";
}
} }
// channels // channels
var defaultChannel = getViewDefaults("channel"); var defaultChannel = getViewDefaults("channel");
var allChannels = allResults.channel_results; var allChannels = allResults.channel_results;
var channelBox = document.getElementById("channel-results"); var channelBox = document.getElementById("channel-results");
channelBox.innerHTML = ""; channelBox.innerHTML = "";
for (let index = 0; index < allChannels.length; index++) { channelBox.parentElement.style.display = "block";
const channel = allChannels[index].source; if (allChannels.length > 0) {
const channelDiv = createChannel(channel, defaultChannel); for (let index = 0; index < allChannels.length; index++) {
channelBox.appendChild(channelDiv); const channel = allChannels[index].source;
const channelDiv = createChannel(channel, defaultChannel);
channelBox.appendChild(channelDiv);
}
} else {
if (queryType === "simple" || queryType == "channel") {
channelBox.innerHTML = "<p>No channels found.</p>";
} else {
channelBox.parentElement.style.display = "none";
}
} }
// playlists // playlists
var defaultPlaylist = getViewDefaults("playlist"); var defaultPlaylist = getViewDefaults("playlist");
var allPlaylists = allResults.playlist_results; var allPlaylists = allResults.playlist_results;
var playlistBox = document.getElementById("playlist-results"); var playlistBox = document.getElementById("playlist-results");
playlistBox.innerHTML = ""; playlistBox.innerHTML = "";
for (let index = 0; index < allPlaylists.length; index++) { playlistBox.parentElement.style.display = "block";
const playlist = allPlaylists[index].source; if (allPlaylists.length > 0) {
const playlistDiv = createPlaylist(playlist, defaultPlaylist); for (let index = 0; index < allPlaylists.length; index++) {
playlistBox.appendChild(playlistDiv); const playlist = allPlaylists[index].source;
const playlistDiv = createPlaylist(playlist, defaultPlaylist);
playlistBox.appendChild(playlistDiv);
}
} else {
if (queryType === "simple" || queryType == "playlist") {
playlistBox.innerHTML = "<p>No playlists found.</p>";
} else {
playlistBox.parentElement.style.display = "none";
}
} }
} }