From 5cc4bfec1ff8be878b60500917278419c7fb881e Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 26 Jan 2024 17:37:58 +0100 Subject: [PATCH] web client --- server/src/main.rs | 6 +++--- server/templates/index.html | 30 +++++++++++++++++++++++++----- server/templates/query.html | 3 ++- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index a05623d..d12f3a2 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,11 +1,11 @@ use askama::Template; use axum::{ debug_handler, - extract::{Json, State}, + extract::State, http::StatusCode, response::{Html, IntoResponse, Response}, routing::{get, post}, - Router, + Form, Router, }; use log::info; use search::query::Processor; @@ -115,7 +115,7 @@ struct Document { #[debug_handler] async fn post_query( State(state): State>, - Json(payload): Json, + Form(payload): Form, ) -> impl IntoResponse { info!("Query request: {}", payload.query); diff --git a/server/templates/index.html b/server/templates/index.html index 2eebb47..15036e1 100644 --- a/server/templates/index.html +++ b/server/templates/index.html @@ -5,11 +5,8 @@ - - - - + @@ -42,6 +39,24 @@ }); }); }); + + document.addEventListener('DOMContentLoaded', function () { + var goToTopBtn = document.getElementById('to-top'); + + // Show/hide the "Go to Top" button based on scroll position + window.addEventListener('scroll', function () { + if (window.scrollY > 500) { + goToTopBtn.classList.remove('hidden'); + } else { + goToTopBtn.classList.add('hidden'); + } + }); + + // Scroll to the top when the button is clicked + goToTopBtn.addEventListener('click', function () { + window.scrollTo({ top: 0, behavior: 'smooth' }); + }); + }); search-rs @@ -68,7 +83,7 @@

Index on {{index_path}}

@@ -78,6 +93,11 @@

Index on {{index_path}}

+ + \ No newline at end of file diff --git a/server/templates/query.html b/server/templates/query.html index 825a3b4..3874da4 100644 --- a/server/templates/query.html +++ b/server/templates/query.html @@ -23,7 +23,8 @@

{% for doc in documents %} -
+

{{ doc.path }}