Add user following functionality

This commit is contained in:
spikecodes 2021-04-06 10:23:05 -07:00
parent 4a42a25ed3
commit b3e4b7bfae
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
6 changed files with 35 additions and 16 deletions

View File

@ -3,7 +3,7 @@ name = "libreddit"
description = " Alternative private front-end to Reddit" description = " Alternative private front-end to Reddit"
license = "AGPL-3.0" license = "AGPL-3.0"
repository = "https://github.com/spikecodes/libreddit" repository = "https://github.com/spikecodes/libreddit"
version = "0.9.0" version = "0.10.0"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"

View File

@ -35,8 +35,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string()); let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string());
let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort)); let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort));
let sub = req.param("sub").map_or( let sub = req.param("sub").unwrap_or(if front_page == "default" || front_page.is_empty() {
if front_page == "default" || front_page.is_empty() {
if subscribed.is_empty() { if subscribed.is_empty() {
"popular".to_string() "popular".to_string()
} else { } else {
@ -44,9 +43,11 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
} }
} else { } else {
front_page.to_owned() front_page.to_owned()
}, });
String::from,
); if req.param("sub").is_some() && sub.starts_with("u_") {
return Ok(redirect(["/user/", &sub[2..]].concat()));
}
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub, sort, req.uri().query().unwrap_or_default()); let path = format!("/r/{}/{}.json?{}&raw_json=1", sub, sort, req.uri().query().unwrap_or_default());

View File

@ -307,7 +307,7 @@ aside {
/* Subscriptions */ /* Subscriptions */
#sub_subscription { #sub_subscription, #user_subscription {
margin-top: 20px; margin-top: 20px;
} }

View File

@ -57,10 +57,10 @@
</form> </form>
{% if prefs.subscriptions.len() > 0 %} {% if prefs.subscriptions.len() > 0 %}
<div class="prefs" id="settings_subs"> <div class="prefs" id="settings_subs">
<p>Subscribed Subreddits</p> <p>Subscribed Feeds</p>
{% for sub in prefs.subscriptions %} {% for sub in prefs.subscriptions %}
<div> <div>
<span>{{ sub }}</span> <span>{% if sub.starts_with("u_") -%}{{ format!("u/{}", &sub[2..]) }}{% else -%}{{ format!("r/{}", sub) }}{% endif -%}</span>
<form action="/r/{{ sub }}/unsubscribe/?redirect=settings" method="POST"> <form action="/r/{{ sub }}/unsubscribe/?redirect=settings" method="POST">
<button class="unsubscribe">Unsubscribe</button> <button class="unsubscribe">Unsubscribe</button>
</form> </form>

View File

@ -75,6 +75,18 @@
<div>{{ user.karma }}</div> <div>{{ user.karma }}</div>
<div>{{ user.created }}</div> <div>{{ user.created }}</div>
</div> </div>
<div id="user_subscription">
{% let name = ["u_", user.name.as_str()].join("") %}
{% if prefs.subscriptions.contains(name) %}
<form action="/r/u_{{ user.name }}/unsubscribe" method="POST">
<button class="unsubscribe">Unfollow</button>
</form>
{% else %}
<form action="/r/u_{{ user.name }}/subscribe" method="POST">
<button class="subscribe">Follow</button>
</form>
{% endif %}
</div>
</div> </div>
</aside> </aside>
</main> </main>

View File

@ -58,7 +58,13 @@
{% macro post_in_list(post) -%} {% macro post_in_list(post) -%}
<div class="post {% if post.flags.stickied %}stickied{% endif %}"> <div class="post {% if post.flags.stickied %}stickied{% endif %}">
<p class="post_header"> <p class="post_header">
<a class="post_subreddit" href="/r/{{ post.community }}">r/{{ post.community }}</a> {% let community -%}
{% if post.community.starts_with("u_") -%}
{% let community = format!("u/{}", &post.community[2..]) -%}
{% else -%}
{% let community = format!("r/{}", post.community) -%}
{% endif -%}
<a class="post_subreddit" href="/{{ community }}">{{ community }}</a>
<span class="dot">&bull;</span> <span class="dot">&bull;</span>
<a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a> <a class="post_author" href="/u/{{ post.author.name }}">u/{{ post.author.name }}</a>
<span class="dot">&bull;</span> <span class="dot">&bull;</span>