swap quote search to trigram ilike, search ui stub, more
This commit is contained in:
@@ -22,6 +22,7 @@ pub mod add;
|
||||
#[derive(Deserialize)]
|
||||
pub struct PageQuery {
|
||||
page: Option<i64>,
|
||||
s: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn page(
|
||||
@@ -39,10 +40,20 @@ pub async fn page(
|
||||
let per_page = 10;
|
||||
let offset = (page - 1) * per_page;
|
||||
|
||||
let quotes = Quote::get_chronological_offset(&mut *conn, offset, per_page).await?;
|
||||
let search = query.s.as_deref().unwrap_or("");
|
||||
let quotes = match search {
|
||||
"" => Quote::get_chronological_offset(&mut *conn, offset, per_page).await?,
|
||||
_ => Quote::get_by_search_query(&mut *conn, search, offset, per_page).await?,
|
||||
};
|
||||
let total_quotes = Quote::total_count(&mut *conn).await?;
|
||||
let total_pages = (total_quotes as f64 / per_page as f64).ceil() as i64;
|
||||
|
||||
let s_qs = if search.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!("&s={}", search)
|
||||
};
|
||||
|
||||
Ok(base(
|
||||
"Quotes | Mnemosyne",
|
||||
html!(
|
||||
@@ -59,8 +70,10 @@ pub async fn page(
|
||||
span class="text-neutral-300 group-hover:text-neutral-200" {"Add quote"}
|
||||
}
|
||||
}
|
||||
input class="border w-full border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-950/50 p-2 rounded"
|
||||
placeholder="Search not yet implemented.";
|
||||
form method="get" action="/quotes" {
|
||||
input type="text" name="s" class="border w-full border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-950/50 p-2 rounded"
|
||||
placeholder="Search quotes..." value={(search)};
|
||||
}
|
||||
div class="my-2 w-full" {
|
||||
p class="ml-auto w-fit text-neutral-500 text-sm flex items-center" {
|
||||
span class="scale-[.6]" {(PreEscaped(icons::CALENDAR_ARROW_DOWN))}
|
||||
@@ -74,7 +87,7 @@ pub async fn page(
|
||||
|
||||
div class="flex justify-between items-center mt-4 text-neutral-400" {
|
||||
@if page > 1 {
|
||||
a href=(format!("/quotes?page={}", (page - 1).max(1))) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
a href=(format!("/quotes?page={}{}", (page - 1).max(1), s_qs)) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
"Previous"
|
||||
}
|
||||
} @else {
|
||||
@@ -86,7 +99,7 @@ pub async fn page(
|
||||
}
|
||||
|
||||
@if page < total_pages {
|
||||
a href=(format!("/quotes?page={}", page + 1)) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
a href=(format!("/quotes?page={}{}", page + 1, s_qs)) class="px-4 py-2 border border-neutral-200/25 hover:border-neutral-200/45 bg-neutral-200/5 hover:bg-neutral-200/15 rounded" {
|
||||
"Next"
|
||||
}
|
||||
} @else {
|
||||
|
||||
Reference in New Issue
Block a user