mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-19 19:23:02 +05:30
(feat): added pages and quick actions as search results
This commit is contained in:
@@ -46,7 +46,7 @@
|
|||||||
<i class="fa-solid fa-chevron-right text-accent_three mx-2 hidden group-hover:block"></i>
|
<i class="fa-solid fa-chevron-right text-accent_three mx-2 hidden group-hover:block"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-xs text-accent_three mt-3 mb-2 mx-1">QUICK SHOTCUTS</p>
|
<p class="text-xs text-accent_three mt-3 mb-2 mx-1">QUICK ACTIONS</p>
|
||||||
<div class="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" onclick="location.href='mailto:hey@neosubhamoy.dev'">
|
<div class="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" onclick="location.href='mailto:hey@neosubhamoy.dev'">
|
||||||
<span class="flex items-center">
|
<span class="flex items-center">
|
||||||
<lord-icon class="mx-1" src="https://cdn.lordicon.com/xtnsvhie.json" target=".resultitem" trigger="hover" colors="primary:#38BDF8" style="width:25px"></lord-icon>
|
<lord-icon class="mx-1" src="https://cdn.lordicon.com/xtnsvhie.json" target=".resultitem" trigger="hover" colors="primary:#38BDF8" style="width:25px"></lord-icon>
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ function inject_search_results (results) {
|
|||||||
results.project.forEach(function(result) {
|
results.project.forEach(function(result) {
|
||||||
let projectDiv = document.createElement("div");
|
let projectDiv = document.createElement("div");
|
||||||
projectDiv.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";
|
projectDiv.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";
|
||||||
projectDiv.setAttribute("onclick", "location.href='" + result.link + "'");
|
projectDiv.setAttribute("onclick", "window.open('" + result.link + "', '_blank')");
|
||||||
|
|
||||||
projectDiv.innerHTML = `
|
projectDiv.innerHTML = `
|
||||||
<span class="flex items-center">
|
<span class="flex items-center">
|
||||||
@@ -178,6 +178,48 @@ function inject_search_results (results) {
|
|||||||
searchRes.appendChild(socialDiv);
|
searchRes.appendChild(socialDiv);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(typeof(results.page) !== 'undefined') {
|
||||||
|
results.page.forEach(function(result) {
|
||||||
|
let pageDiv = document.createElement("div");
|
||||||
|
pageDiv.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";
|
||||||
|
pageDiv.setAttribute("onclick", "location.href='" + result.link + "'");
|
||||||
|
|
||||||
|
pageDiv.innerHTML = `
|
||||||
|
<span class="flex items-center">
|
||||||
|
<lord-icon class="mx-1" src="https://cdn.lordicon.com/${result.icon}" target=".resultitem" trigger="hover" colors="primary:#38BDF8" style="width:25px"></lord-icon>
|
||||||
|
<p class="mx-1">${result.name}</p>
|
||||||
|
</span>
|
||||||
|
<span class="flex items-center mr-1">
|
||||||
|
<span class="px-[1rem] py-[0.05rem] mx-1 text-xs bg-accent_four text-bg_secondary rounded-full group-hover:hidden">${'#' + result.tag}</span>
|
||||||
|
<i class="fa-solid fa-chevron-right text-accent_three mx-2 hidden group-hover:block"></i>
|
||||||
|
</span>
|
||||||
|
`;
|
||||||
|
|
||||||
|
searchRes.appendChild(pageDiv);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(typeof(results.action) !== 'undefined') {
|
||||||
|
results.action.forEach(function(result) {
|
||||||
|
let actionDiv = document.createElement("div");
|
||||||
|
actionDiv.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";
|
||||||
|
actionDiv.setAttribute("onclick", "window.open('" + result.link + "', '_blank')");
|
||||||
|
|
||||||
|
actionDiv.innerHTML = `
|
||||||
|
<span class="flex items-center">
|
||||||
|
<lord-icon class="mx-1" src="https://cdn.lordicon.com/${result.icon}" target=".resultitem" trigger="hover" colors="primary:#38BDF8" style="width:25px"></lord-icon>
|
||||||
|
<p class="mx-1">${result.name}</p>
|
||||||
|
</span>
|
||||||
|
<span class="flex items-center mr-1">
|
||||||
|
<span class="px-[1rem] py-[0.05rem] mx-1 text-xs bg-accent_four text-bg_secondary rounded-full group-hover:hidden">${'#' + result.tag}</span>
|
||||||
|
<i class="fa-solid fa-chevron-right text-accent_three mx-2 hidden group-hover:block"></i>
|
||||||
|
</span>
|
||||||
|
`;
|
||||||
|
|
||||||
|
searchRes.appendChild(actionDiv);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function inject_no_results(results) {
|
function inject_no_results(results) {
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ require 'query_functions.php';
|
|||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
if (isset($_POST['keyword'])) {
|
if (isset($_POST['keyword'])) {
|
||||||
$keyword = $_POST['keyword'];
|
$keyword = $_POST['keyword'];
|
||||||
$results_projects = fetch_search_results_projects($conn, $keyword);
|
$results_array = [
|
||||||
$results_socials = fetch_search_results_socials($conn, $keyword);
|
$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 = [];
|
$results = [];
|
||||||
foreach ([$results_projects, $results_socials] as $array) {
|
foreach ($results_array as $array) {
|
||||||
if (!empty($array)) {
|
if (!empty($array)) {
|
||||||
$results = array_merge($results, $array);
|
$results = array_merge($results, $array);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,4 +83,36 @@ function fetch_search_results_socials($conn, $keyword) {
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//for pages table
|
||||||
|
function fetch_search_results_pages($conn, $keyword) {
|
||||||
|
$sql = "SELECT * FROM pages WHERE name LIKE '%$keyword%'";
|
||||||
|
$result = $conn -> query($sql);
|
||||||
|
if($result -> num_rows > 0) {
|
||||||
|
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||||
|
foreach ($result as &$element) {
|
||||||
|
$element['tag'] = 'page';
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//for quick_actions table
|
||||||
|
function fetch_search_results_quickactions($conn, $keyword) {
|
||||||
|
$sql = "SELECT * FROM quick_actions WHERE name LIKE '%$keyword%'";
|
||||||
|
$result = $conn -> query($sql);
|
||||||
|
if($result -> num_rows > 0) {
|
||||||
|
$result = mysqli_fetch_all($result, MYSQLI_ASSOC);
|
||||||
|
foreach ($result as &$element) {
|
||||||
|
$element['tag'] = 'action';
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user