Add Sorting to Homepage
This commit is contained in:
parent
1b5a3a59c0
commit
1e7bbb385c
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1062,6 +1062,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
actix-web = "3"
|
actix-web = "3"
|
||||||
actix-files = "0.4.0"
|
actix-files = "0.4.0"
|
||||||
askama = "0.9"
|
askama = "0.9"
|
||||||
|
serde = "1.0.117"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
reqwest = { version = "0.10", features = ["blocking"] }
|
reqwest = { version = "0.10", features = ["blocking"] }
|
||||||
pulldown-cmark = "0.8.0"
|
pulldown-cmark = "0.8.0"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// CRATES
|
// CRATES
|
||||||
use actix_web::{get, HttpResponse, Result};
|
use actix_web::{get, web, HttpResponse, Result};
|
||||||
|
use serde::Deserialize;
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
#[path = "subreddit.rs"] mod subreddit;
|
#[path = "subreddit.rs"] mod subreddit;
|
||||||
@ -12,9 +13,17 @@ struct PopularTemplate {
|
|||||||
sort: String
|
sort: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Params {
|
||||||
|
sort: Option<String>
|
||||||
|
}
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn page() -> Result<HttpResponse> {
|
pub async fn page(params: web::Query<Params>) -> Result<HttpResponse> {
|
||||||
render("popular".to_string(), "hot".to_string()).await
|
match ¶ms.sort {
|
||||||
|
Some(sort) => render("popular".to_string(), sort.to_string()).await,
|
||||||
|
None => render("popular".to_string(), "hot".to_string()).await,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn render(sub_name: String, sort: String) -> Result<HttpResponse> {
|
async fn render(sub_name: String, sort: String) -> Result<HttpResponse> {
|
||||||
|
Loading…
Reference in New Issue
Block a user