From 078d6fe25bcd42abc6373d2a3ff7dd71acb9e5eb Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Fri, 15 Jan 2021 15:05:55 -0800 Subject: [PATCH] Request about pages before posts --- src/subreddit.rs | 23 ++++++++++++----------- src/user.rs | 6 ++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/subreddit.rs b/src/subreddit.rs index 7e68f46..35b4fde 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -34,19 +34,20 @@ pub async fn page(req: HttpRequest) -> HttpResponse { .to_string(); let sort = req.match_info().get("sort").unwrap_or("hot").to_string(); - let sub = if !sub_name.contains('+') && sub_name != "popular" && sub_name != "all" { - subreddit(&sub_name).await.unwrap_or_default() - } else if sub_name.contains('+') { - Subreddit { - name: sub_name, - ..Subreddit::default() - } - } else { - Subreddit::default() - }; - match fetch_posts(&path, String::new()).await { Ok((posts, after)) => { + // If you can get subreddit posts, also request subreddit metadata + let sub = if !sub_name.contains('+') && sub_name != "popular" && sub_name != "all" { + subreddit(&sub_name).await.unwrap_or_default() + } else if sub_name.contains('+') { + Subreddit { + name: sub_name, + ..Subreddit::default() + } + } else { + Subreddit::default() + }; + let s = SubredditTemplate { sub, posts, diff --git a/src/user.rs b/src/user.rs index 9a7502f..be11069 100644 --- a/src/user.rs +++ b/src/user.rs @@ -24,12 +24,14 @@ pub async fn profile(req: HttpRequest) -> HttpResponse { let sort = param(&path, "sort"); let username = req.match_info().get("username").unwrap_or("").to_string(); - // Request user profile data and user posts/comments from Reddit - let user = user(&username).await.unwrap_or_default(); + // Request user posts/comments from Reddit let posts = fetch_posts(&path, "Comment".to_string()).await; match posts { Ok((posts, after)) => { + // If you can get user posts, also request user data + let user = user(&username).await.unwrap_or_default(); + let s = UserTemplate { user, posts,