Reduce post padding

This commit is contained in:
spikecodes
2021-01-21 21:25:51 -08:00
parent 758b627660
commit 2270b6cf95
4 changed files with 10 additions and 17 deletions

View File

@ -1,5 +1,5 @@
// CRATES
use crate::utils::{error, fetch_posts, param, prefs, request, val, Post, Preferences, cookie};
use crate::utils::{cookie, error, fetch_posts, param, prefs, request, val, Post, Preferences};
use actix_web::{HttpRequest, HttpResponse};
use askama::Template;

View File

@ -98,7 +98,7 @@ async fn subreddit(sub: &str) -> Result<Subreddit, String> {
let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64;
// Fetch subreddit icon either from the community_icon or icon_img value
let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or("").split('?').collect::<Vec<&str>>()[0];
let community_icon: &str = res["data"]["community_icon"].as_str().map_or("", |s| s.split('?').collect::<Vec<&str>>()[0]);
let icon = if community_icon.is_empty() { val(&res, "icon_img") } else { community_icon.to_string() };
let sub = Subreddit {

View File

@ -286,7 +286,7 @@ pub fn time(created: f64) -> (String, String) {
// val() function used to parse JSON from Reddit APIs
pub fn val(j: &Value, k: &str) -> String {
String::from(j["data"][k].as_str().unwrap_or_default())
j["data"][k].as_str().unwrap_or_default().to_string()
}
// Fetch posts of a user or subreddit and return a vector of posts and the "after" value