Stickied Posts
This commit is contained in:
parent
f65ee2eb6a
commit
aa9aad6743
7 changed files with 26 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
// CRATES
|
||||
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post};
|
||||
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Flags, Params, Post};
|
||||
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
|
@ -130,7 +130,10 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
|||
"white".to_string()
|
||||
},
|
||||
),
|
||||
flags: Flags {
|
||||
nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
stickied: post_data["data"]["stickied"].as_bool().unwrap_or(false)
|
||||
},
|
||||
media: media.1,
|
||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||
};
|
||||
|
|
10
src/utils.rs
10
src/utils.rs
|
@ -13,6 +13,11 @@ use base64::encode;
|
|||
//
|
||||
// Post flair with text, background color and foreground color
|
||||
pub struct Flair(pub String, pub String, pub String);
|
||||
// Post flags with nsfw and stickied
|
||||
pub struct Flags {
|
||||
pub nsfw: bool,
|
||||
pub stickied: bool
|
||||
}
|
||||
|
||||
// Post containing content, metadata and media
|
||||
pub struct Post {
|
||||
|
@ -25,7 +30,7 @@ pub struct Post {
|
|||
pub score: String,
|
||||
pub post_type: String,
|
||||
pub flair: Flair,
|
||||
pub nsfw: bool,
|
||||
pub flags: Flags,
|
||||
pub media: String,
|
||||
pub time: String,
|
||||
}
|
||||
|
@ -171,7 +176,10 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
|||
"white".to_string()
|
||||
},
|
||||
),
|
||||
flags: Flags {
|
||||
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
stickied: post["data"]["stickied"].as_bool().unwrap_or(false)
|
||||
},
|
||||
url: val(post, "permalink").await,
|
||||
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
||||
});
|
||||
|
|
|
@ -237,6 +237,12 @@ aside {
|
|||
font-weight: bold;
|
||||
}
|
||||
|
||||
.stickied {
|
||||
--accent: #5cff85;
|
||||
border: 1px solid #5cff85;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.post_subreddit {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<div class="post">
|
||||
<div class="post_left">
|
||||
<p class="post_score">{{ post.score }}</p>
|
||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
</div>
|
||||
<div class="post_right">
|
||||
<p>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
<div class="post highlighted">
|
||||
<div class="post_left">
|
||||
<p class="post_score">{{ post.score }}</p>
|
||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
</div>
|
||||
<div class="post_right">
|
||||
<p>
|
||||
|
|
|
@ -22,10 +22,10 @@
|
|||
</select>{% endif %}<input id="sort_submit" type="submit" value="→">
|
||||
</form>
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<div class="post {% if post.flags.stickied %}stickied{% endif %}">
|
||||
<div class="post_left">
|
||||
<p class="post_score">{{ post.score }}</p>
|
||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
</div>
|
||||
<div class="post_right">
|
||||
<p>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class='post'>
|
||||
<div class="post_left">
|
||||
<p class="post_score">{{ post.score }}</p>
|
||||
{% if post.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
{% if post.flags.nsfw %}<div class="nsfw">NSFW</div>{% endif %}
|
||||
</div>
|
||||
<div class="post_right">
|
||||
<p>
|
||||
|
|
Loading…
Reference in a new issue