You've already forked AstralRinth
forked from didirus/AstralRinth
Tweak styles for narrower screens, add indicator for no results
Makes the styles of search results work better with narrower screens. The category badges on each result collapse to just an icon (with title text) when the screen is too narrow. Adds a text label for the Forge/Fabric icons. Adds a message for when a query returns no results.
This commit is contained in:
@@ -81,11 +81,16 @@ impl Document for SearchMod {
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct SearchRequest {
|
||||
q: Option<String>,
|
||||
f: Option<String>,
|
||||
v: Option<String>,
|
||||
o: Option<String>,
|
||||
s: Option<String>,
|
||||
#[serde(rename = "q")]
|
||||
query: Option<String>,
|
||||
#[serde(rename = "f")]
|
||||
filters: Option<String>,
|
||||
#[serde(rename = "v")]
|
||||
version: Option<String>,
|
||||
#[serde(rename = "o")]
|
||||
offset: Option<String>,
|
||||
#[serde(rename = "s")]
|
||||
index: Option<String>,
|
||||
}
|
||||
|
||||
#[post("search")]
|
||||
@@ -93,12 +98,11 @@ pub async fn search_post(
|
||||
web::Query(info): web::Query<SearchRequest>,
|
||||
hb: Data<Handlebars<'_>>,
|
||||
) -> HttpResponse {
|
||||
let results = search(web::Query(info));
|
||||
|
||||
let results = search(&info);
|
||||
let data = json!({
|
||||
"query": info,
|
||||
"results": results,
|
||||
});
|
||||
|
||||
let body = hb.render("search-results", &data).unwrap();
|
||||
|
||||
HttpResponse::Ok().body(body)
|
||||
@@ -109,9 +113,10 @@ pub async fn search_get(
|
||||
web::Query(info): web::Query<SearchRequest>,
|
||||
hb: Data<Handlebars<'_>>,
|
||||
) -> HttpResponse {
|
||||
let results = search(web::Query(info));
|
||||
let results = search(&info);
|
||||
|
||||
let data = json!({
|
||||
"query": info,
|
||||
"results": results,
|
||||
});
|
||||
|
||||
@@ -120,40 +125,40 @@ pub async fn search_get(
|
||||
HttpResponse::Ok().body(body)
|
||||
}
|
||||
|
||||
fn search(web::Query(info): web::Query<SearchRequest>) -> Vec<SearchMod> {
|
||||
fn search(info: &SearchRequest) -> Vec<SearchMod> {
|
||||
let client = Client::new("http://localhost:7700", "");
|
||||
|
||||
let search_query: String;
|
||||
let mut filters = "".to_string();
|
||||
let search_query: &str;
|
||||
let mut filters = String::new();
|
||||
let mut offset = 0;
|
||||
let mut index = "relevance".to_string();
|
||||
let mut index = "relevance";
|
||||
|
||||
match info.q {
|
||||
match info.query.as_ref() {
|
||||
Some(q) => search_query = q,
|
||||
None => search_query = "{}{}{}".to_string(),
|
||||
None => search_query = "{}{}{}",
|
||||
}
|
||||
|
||||
if let Some(f) = info.f {
|
||||
filters = f;
|
||||
if let Some(f) = info.filters.as_ref() {
|
||||
filters = f.clone();
|
||||
}
|
||||
|
||||
if let Some(v) = info.v {
|
||||
if let Some(v) = info.version.as_ref() {
|
||||
if filters.is_empty() {
|
||||
filters = v;
|
||||
filters = v.clone();
|
||||
} else {
|
||||
filters = format!("({}) AND ({})", filters, v);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(o) = info.o {
|
||||
if let Some(o) = info.offset.as_ref() {
|
||||
offset = o.parse().unwrap();
|
||||
}
|
||||
|
||||
if let Some(s) = info.s {
|
||||
if let Some(s) = info.index.as_ref() {
|
||||
index = s;
|
||||
}
|
||||
|
||||
let mut query = Query::new(&search_query).with_limit(10).with_offset(offset);
|
||||
let mut query = Query::new(search_query).with_limit(10).with_offset(offset);
|
||||
|
||||
if !filters.is_empty() {
|
||||
query = query.with_filters(&filters);
|
||||
|
||||
Reference in New Issue
Block a user