From fafa8c585236cfac06d576871b1f020755eee9fd Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Sat, 2 Aug 2025 14:58:36 +0200 Subject: [PATCH] fix: search minimum length offset and merge oversight (#47) Fixed merge derp from #46 and minimum search query length offset Reviewed-on: https://codeberg.org/vlw/vlw.se/pulls/47 --- public/assets/js/shell.js | 56 --------------------------------------- public/search.php | 4 +-- 2 files changed, 2 insertions(+), 58 deletions(-) diff --git a/public/assets/js/shell.js b/public/assets/js/shell.js index d37d5ce..d52f843 100644 --- a/public/assets/js/shell.js +++ b/public/assets/js/shell.js @@ -1,68 +1,13 @@ const DEBOUNCE_TIMEOUT_MS = 100; const CLASSNAME_SEARCHBOX_ACTIVE = "searchboxActive"; -<<<<<<< HEAD -// Set global Vegvisir naviation delay for page transition effect -VV.delay = 100; - -// Handle search box open/close buttons -{ - // Open search box - new Elevent("click", document.querySelector(".searchbox-open"), () => { - document.querySelector("header").classList.add(CLASSNAME_SEARCHBOX_ACTIVE); - // Select searchbox inner input element - document.querySelector("searchbox input").focus(); - }); - - // Close searchbox - new Elevent("click", document.querySelector(".searchbox-close"), () => { - // Disable search button interaction while animation is running - // This is required to prevent conflicts with the :hover "peak" transformation - const searchButtonElement = document.querySelector("header button.search"); - const transformDuration = parseInt(window.getComputedStyle(searchButtonElement).getPropertyValue("--transform-duration")); - searchButtonElement.style.setProperty("pointer-events", "none"); - - document.querySelector("header").classList.remove(CLASSNAME_SEARCHBOX_ACTIVE); - - // Wait for the transform animation to finish - setTimeout(() => searchButtonElement.style.removeProperty("pointer-events"), transformDuration); - }); -} - -// Root shell navigation event handlers -{ - // On all top shell navigations - new Elevent(VV.EVENT.START, VV.shell, () => { - // Close searchbox on top shell navigations - document.querySelector("header").classList.remove(CLASSNAME_SEARCHBOX_ACTIVE); - }); -} - -// Handle search logic -{ - const searchResultsElement = document.querySelector("search-results"); - - document.querySelector("header input[type='search']").addEventListener("input", (event) => { - // Debounce user input - clearTimeout(event.target._throttle); - event.target._throttle = setTimeout(() => { - // Navigate search-results element on user input - new VV(searchResultsElement).navigate(`/search?query=${event.target.value}`); - }, 100); - }); -} -======= // Navigate to the start page if the logo in the header is clicked document.querySelector("header .logo").addEventListener("click", () => new VV().navigate("/")); ->>>>>>> chore/v3.2 // Navigate to the start page if the logo in the header is clicked document.querySelector("header .logo").addEventListener("click", () => new VV().navigate("/")); // Scroll page to top on navigation -<<<<<<< HEAD -VV.shell.addEventListener(VV.EVENT.FINISH, () => window.scrollTo({ top: 0 })); -======= VV.shell.addEventListener(VV.EVENT.FINISH, () => window.scrollTo({ top: 0 })); // Open search box @@ -98,4 +43,3 @@ document.querySelector("header input[type='search']").addEventListener("input", new VV(document.querySelector("search-results")).navigate(`/search?q=${event.target.value}`); }, DEBOUNCE_TIMEOUT_MS); }); ->>>>>>> chore/v3.2 diff --git a/public/search.php b/public/search.php index 4f4f7f6..fddd9ca 100644 --- a/public/search.php +++ b/public/search.php @@ -17,7 +17,7 @@ public function __construct() { $this->query = $_GET[GET_KEY_QUERY] ?? ""; - $this->results = strlen($this->query) > MIN_QUERY_LENGTH ? parent::query($this->query, limit: LIMIT_RESULTS) : []; + $this->results = strlen($this->query) >= MIN_QUERY_LENGTH ? parent::query($this->query, limit: LIMIT_RESULTS) : []; } } @@ -88,7 +88,7 @@ - +

Almost there, type at least two letters to search