all repos — searchix @ 5b9e67fd5129dec75169a1a070c70f910dff6da2

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: frontend search implementation

Alan Pearce
commit

5b9e67fd5129dec75169a1a070c70f910dff6da2

parent

a2c97c10ee0a01277c51f85b15bdf8ee821f96db

1 file changed, 26 insertions(+), 0 deletions(-)

changed files
A frontend/static/search.js
@@ -0,0 +1,26 @@
+const search = document.getElementById("search"); +const results = document.getElementById("results"); +search.addEventListener("submit", function (ev) { + const url = new URL(this.action); + url.search = new URLSearchParams(new FormData(this)).toString(); + const res = fetch(url, { + headers: { + fetch: "true", + }, + }) + .then(function (res) { + window.history.pushState(null, null, url); + if (res.ok) { + return res.text(); + } else { + throw new Error(res.statusText); + } + }) + .then(function (html) { + results.innerHTML = html; + }) + .catch(function (error) { + console.error("fetch failed", error); + }); + ev.preventDefault(); +});