diff --git a/api/update/GET.php b/api/update/GET.php index 84ea0aa..b78e20d 100644 --- a/api/update/GET.php +++ b/api/update/GET.php @@ -5,16 +5,22 @@ use Reflect\Rules\{Ruleset, Rules, Type}; use VLW\API\API; - use VLW\Helpers\{GenerateTimeline, Forgejo}; + use VLW\Helpers\{ + Forgejo, + GenerateSearch, + GenerateTimeline + }; require_once Path::root("src/API/API.php"); require_once Path::root("src/Helpers/Forgejo.php"); + require_once Path::root("src/Helpers/GenerateSearch.php"); require_once Path::root("src/Helpers/GenerateTimeline.php"); enum ServiceEnum: string { use xEnum; case ALL = "all"; + case SEARCH = "search"; case FORGEJO = "forgejo"; case TIMELINE = "timeline"; } @@ -35,6 +41,9 @@ case ServiceEnum::FORGEJO->value: return new Response($this->update_forgejo()); + case ServiceEnum::SEARCH->value: + return new Response($this->update_search()); + case ServiceEnum::TIMELINE->value: return new Response($this->update_timeline()); @@ -42,14 +51,19 @@ default: return new Response( $this->update_timeline() && + $this->update_search() && $this->update_forgejo() ); } } - + private function update_timeline(): bool { return new GenerateTimeline()->generate(); } + + private function update_search(): bool { + return new GenerateSearch()->generate(); + } private function update_forgejo(): bool { return new Forgejo()->update(); diff --git a/public/assets/js/shell.js b/public/assets/js/shell.js index 0fd8c22..8282749 100644 --- a/public/assets/js/shell.js +++ b/public/assets/js/shell.js @@ -37,6 +37,6 @@ document.querySelector("header input[type='search']").addEventListener("input", clearTimeout(event.target._throttle); event.target._throttle = setTimeout(() => { // Navigate search-results element on user input - new VV(document.querySelector("search-results")).navigate(`/search?query=${event.target.value}`); + new VV(document.querySelector("search-results")).navigate(`/search?q=${event.target.value}`); }, DEBOUNCE_TIMEOUT_MS); }); \ No newline at end of file diff --git a/public/search.php b/public/search.php index 2e95513..4f4f7f6 100644 --- a/public/search.php +++ b/public/search.php @@ -7,8 +7,9 @@ require_once VV::root("src/Database/Tables/Search/Search.php"); require_once VV::root("src/Database/Models/Search/Search.php"); - const LIMIT_RESULTS = 10; - const GET_KEY_QUERY = "q"; + const GET_KEY_QUERY = "q"; + const LIMIT_RESULTS = 10; + const MIN_QUERY_LENGTH = 2; $search = new class extends Search { public readonly string $query; @@ -16,7 +17,7 @@ public function __construct() { $this->query = $_GET[GET_KEY_QUERY] ?? ""; - $this->results = parent::query($this->query, limit: LIMIT_RESULTS); + $this->results = strlen($this->query) > MIN_QUERY_LENGTH ? parent::query($this->query, limit: LIMIT_RESULTS) : []; } } @@ -40,7 +41,7 @@ -value, $_GET)): ?> + results): ?>
@@ -90,7 +91,7 @@
-

Almost, type at least two letters to search

+

Almost there, type at least two letters to search

diff --git a/public/work/timeline.php b/public/work/timeline.php index f7672f1..432196a 100644 --- a/public/work/timeline.php +++ b/public/work/timeline.php @@ -109,7 +109,7 @@
actions() as $action): ?> - id}" ?>">