From 348a8d7ea190bae40eba0d2e0ebce95b380c20e8 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Sun, 19 Nov 2023 20:46:14 +0530 Subject: [PATCH] (feat): added profiles to search results --- htdocs/assets/js/floatingbar-config.js | 31 ++++++++++++++++++++++++++ htdocs/core/handle_search.php | 3 ++- htdocs/core/query_functions.php | 16 +++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/htdocs/assets/js/floatingbar-config.js b/htdocs/assets/js/floatingbar-config.js index 94a4985..a268c3e 100644 --- a/htdocs/assets/js/floatingbar-config.js +++ b/htdocs/assets/js/floatingbar-config.js @@ -241,6 +241,37 @@ function inject_search_results (results, keyword) { searchRes.appendChild(actionDiv); }); } + + if(typeof(results.profile) !== 'undefined') { + let profileDivTitle = document.createElement("p"); + profileDivTitle.className = "text-xs text-accent_three mt-3 mb-2 mx-1"; + profileDivTitle.innerHTML = "PROFILES"; + searchRes.appendChild(profileDivTitle); + + results.profile.forEach(function(result) { + let profileDiv = document.createElement("div"); + profileDiv.className = "group resultitem w-full flex justify-between items-center my-1 p-1 cursor-pointer hover:bg-bg_third transition transform duration-200 rounded-lg"; + profileDiv.setAttribute("onclick", "window.open('" + result.link + "', '_blank')"); + + profileDiv.innerHTML = ` + + + ${result.name.toLowerCase().replace(/\s/g, '')} + + +
${result.name}
+

${result.description}

+
+
+ + ${'#' + result.tag} + + + `; + + searchRes.appendChild(profileDiv); + }); + } } function inject_no_results(results, keyword) { diff --git a/htdocs/core/handle_search.php b/htdocs/core/handle_search.php index 4e14d76..1ecba21 100644 --- a/htdocs/core/handle_search.php +++ b/htdocs/core/handle_search.php @@ -17,7 +17,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $results_projects = fetch_search_results_projects($conn, $keyword), $results_socials = fetch_search_results_socials($conn, $keyword), $results_pages = fetch_search_results_pages($conn, $keyword), - $results_quickactions = fetch_search_results_quickactions($conn, $keyword) + $results_quickactions = fetch_search_results_quickactions($conn, $keyword), + $results_profiles = fetch_search_results_profiles($conn, $keyword) ]; $results = []; diff --git a/htdocs/core/query_functions.php b/htdocs/core/query_functions.php index aa0ff90..4fba194 100644 --- a/htdocs/core/query_functions.php +++ b/htdocs/core/query_functions.php @@ -115,4 +115,20 @@ function fetch_search_results_quickactions($conn, $keyword) { return array(); } } + +//for quick_actions table +function fetch_search_results_profiles($conn, $keyword) { + $sql = "SELECT * FROM profile WHERE name LIKE '%$keyword%' OR stag LIKE '%$keyword%'"; + $result = $conn -> query($sql); + if($result -> num_rows > 0) { + $result = mysqli_fetch_all($result, MYSQLI_ASSOC); + foreach ($result as &$element) { + $element['tag'] = 'profile'; + } + return $result; + } + else { + return array(); + } +} ?> \ No newline at end of file