web search done right
show query in searchbar
Mikkel Denker4bdfe59b36b5
diff --git a/src/frontend/search.rs b/src/frontend/search.rsindex 9a051cc4..441d4318 100644--- a/src/frontend/search.rs+++ b/src/frontend/search.rs@@ -83,6 +83,7 @@ impl From<RetrievedWebpage> for DisplayedWebpage {#[template(path = "search.html", escape = "none")]struct SearchTemplate {search_result: Vec<DisplayedWebpage>,+ query: String,}pub async fn route(@@ -90,8 +91,10 @@ pub async fn route(Extension(state): Extension<Arc<State>>,) -> impl IntoResponse {let mut search_result = Vec::new();+ let mut displayed_query = String::new();if let Some(query) = params.get("q") {+ displayed_query = query.clone();let query = Query::parse(query).expect("Failed to parse query");let ranker = Ranker::new(query.clone());@@ -107,6 +110,9 @@ pub async fn route(.collect();}- let template = SearchTemplate { search_result };+ let template = SearchTemplate {+ search_result,+ query: displayed_query,+ };HtmlTemplate(template)}diff --git a/templates/index.html b/templates/index.htmlindex 3212edff..0112fccd 100644--- a/templates/index.html+++ b/templates/index.html@@ -9,7 +9,7 @@<h3 class="mb-8" style="color: #828282">Completely Open Search Engine</h3>- {% call scope::searchbar("autofocus") %}+ {% call scope::searchbar("autofocus", "") %}</div>diff --git a/templates/search.html b/templates/search.htmlindex da1fbcd6..eddfc000 100644--- a/templates/search.html+++ b/templates/search.html@@ -8,7 +8,7 @@<div class="ml-14 mr-14"><img src="/static/images/logo.svg" /></div>- {% call scope::searchbar("") %}+ {% call scope::searchbar("", query) %}</div><div class="search-result flex flex-col space-y-3 pt-8 pb-8 pl-40">diff --git a/templates/searchbar.html b/templates/searchbar.htmlindex 13e378f3..d824a239 100644--- a/templates/searchbar.html+++ b/templates/searchbar.html@@ -1,4 +1,4 @@-{% macro searchbar(autofocus) %}+{% macro searchbar(autofocus, query) %}<style>@@ -24,8 +24,9 @@<div class="flex ml-4 w-5 items-center"><img class="h-5" loading="lazy" src="/static/images/search.svg" /></div>- <input type="text" {{ autofocus }} name="q" class="flex w-full h-full grow focus:ring-0"- placeholder="Search" style="background-color: transparent; border: none; outline: none;" />+ <input type="text" value="{{ query|escape }}" {{ autofocus }} name="q"+ class="flex w-full h-full grow focus:ring-0" placeholder="Search"+ style="background-color: transparent; border: none; outline: none;" /><div class="flex w-12 h-full justify-center items-center"><button type="submit" class="bg-transparent p-0 m-0" style="border: none">