Skip to content

Commit

Permalink
web client
Browse files Browse the repository at this point in the history
  • Loading branch information
tomfran committed Jan 26, 2024
1 parent 7aca2ca commit 5cc4bfe
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
6 changes: 3 additions & 3 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -115,7 +115,7 @@ struct Document {
#[debug_handler]
async fn post_query(
State(state): State<Arc<AppState>>,
Json(payload): Json<QueryRequest>,
Form(payload): Form<QueryRequest>,
) -> impl IntoResponse {
info!("Query request: {}", payload.query);

Expand Down
30 changes: 25 additions & 5 deletions server/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- htmx -->
<script src="https://unpkg.com/[email protected]"></script>
<script src="https://unpkg.com/htmx.org/dist/ext/json-enc.js"></script>

<!-- css -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<script src="https://cdn.tailwindcss.com"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
Expand Down Expand Up @@ -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' });
});
});
</script>

<title>search-rs</title>
Expand All @@ -68,7 +83,7 @@
<h1 class="text-3xl font-medium mb-10">Index on {{index_path}}</h1>
<input type="text"
class="outline-neutral-300 dark:outline-neutral-900 w-full p-4 rounded-md bg-neutral-100 dark:bg-neutral-800"
placeholder="Enter your search query..." autofocus name="query" hx-post="/query" hx-ext='json-enc'
placeholder="Enter your search query..." autofocus name="query" hx-post="/query"
hx-target=".search-results" hx-trigger="keyup[keyCode==13]">
</div>

Expand All @@ -78,6 +93,11 @@ <h1 class="text-3xl font-medium mb-10">Index on {{index_path}}</h1>
</div>
</div>

<div id="to-top"
class="hidden fixed flex bottom-16 right-16 h-16 w-16 rounded-full justify-center items-center hover:cursor-pointer bg-neutral-100 hover:bg-neutral-200 dark:bg-neutral-800 dark:hover:bg-neutral-700 ">
<i class="fas fa-caret-up text-2xl"></i>
</div>

</body>

</html>
3 changes: 2 additions & 1 deletion server/templates/query.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ <h1 class=" font-light text-md mb-6">
{% for doc in documents %}


<div id="{{doc.path}}" class="toggle-container bg-neutral-100 dark:bg-neutral-800 p-6 rounded-md mb-6">
<div id="{{doc.path}}"
class="toggle-container hover:cursor-pointer bg-neutral-100 dark:bg-neutral-800 hover:bg-neutral-200 hover:dark:bg-neutral-700 p-6 rounded-md mb-6">
<div id="{{doc.path}}_closed">
<h2 class="text-xl font-semibold mb-4">
{{ doc.path }}
Expand Down

0 comments on commit 5cc4bfe

Please sign in to comment.