mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-08 07:37:45 +00:00
Redesign User/Subreddit About Boxes
This commit is contained in:
parent
280e16bd7f
commit
ace21b21d5
7 changed files with 282 additions and 251 deletions
|
@ -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,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue