Add user listing buttons (#400)

* Add user listing buttons

* Update to v0.22

Co-authored-by: spikecodes <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
Nick Lowery 2022-03-13 13:06:27 -06:00 committed by GitHub
parent 388779c1f2
commit 70ff150ab4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 305 additions and 192 deletions

View file

@ -15,8 +15,11 @@ struct UserTemplate {
posts: Vec<Post>,
sort: (String, String),
ends: (String, String),
/// "overview", "comments", or "submitted"
listing: String,
prefs: Preferences,
url: String,
redirect_url: String,
/// Whether the user themself is filtered.
is_filtered: bool,
/// Whether all fetched posts are filtered (to differentiate between no posts fetched in the first place,
@ -26,13 +29,17 @@ struct UserTemplate {
// FUNCTIONS
pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
let listing = req.param("listing").unwrap_or_else(|| "overview".to_string());
// Build the Reddit JSON API path
let path = format!(
"/user/{}.json?{}&raw_json=1",
"/user/{}/{}.json?{}&raw_json=1",
req.param("name").unwrap_or_else(|| "reddit".to_string()),
req.uri().query().unwrap_or_default()
listing,
req.uri().query().unwrap_or_default(),
);
let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str()));
let redirect_url = url[1..].replace('?', "%3F").replace('&', "%26");
// Retrieve other variables from Libreddit request
let sort = param(&path, "sort").unwrap_or_default();
@ -46,8 +53,10 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
posts: Vec::new(),
sort: (sort, param(&path, "t").unwrap_or_default()),
ends: (param(&path, "after").unwrap_or_default(), "".to_string()),
listing,
prefs: Preferences::new(req),
url,
redirect_url,
is_filtered: true,
all_posts_filtered: false,
})
@ -62,8 +71,10 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
posts,
sort: (sort, param(&path, "t").unwrap_or_default()),
ends: (param(&path, "after").unwrap_or_default(), after),
listing,
prefs: Preferences::new(req),
url,
redirect_url,
is_filtered: false,
all_posts_filtered,
})