Redesign User/Subreddit About Boxes

This commit is contained in:
spikecodes 2020-12-23 22:16:04 -08:00
parent 280e16bd7f
commit ace21b21d5
7 changed files with 282 additions and 251 deletions

View file

@ -2,6 +2,7 @@
use crate::utils::{fetch_posts, format_url, nested_val, request, ErrorTemplate, Params, Post, User};
use actix_web::{http::StatusCode, web, HttpResponse, Result};
use askama::Template;
use chrono::{TimeZone, Utc};
// STRUCTS
#[derive(Template)]
@ -62,11 +63,15 @@ async fn user(name: &String) -> Result<User, &'static str> {
// Otherwise, grab the JSON output from the request
let res = req.unwrap();
// Grab creation date as unix timestamp
let created: i64 = res["data"]["created"].as_f64().unwrap().round() as i64;
// Parse the JSON output into a User struct
Ok(User {
name: name.to_string(),
icon: format_url(nested_val(&res, "subreddit", "icon_img").await).await,
karma: res["data"]["total_karma"].as_i64().unwrap(),
created: Utc.timestamp(created, 0).format("%b %e, %Y").to_string(),
banner: nested_val(&res, "subreddit", "banner_img").await,
description: nested_val(&res, "subreddit", "public_description").await,
})