Change subscription to get. Add subs to settings.

This commit is contained in:
Matthew Crossman 2021-01-30 22:27:49 +11:00
parent dc2030e6f3
commit 449899962a
No known key found for this signature in database
GPG Key ID: C6B942B019794CC2
5 changed files with 62 additions and 21 deletions

View File

@ -100,7 +100,7 @@ async fn main() -> std::io::Result<()> {
.route("/", web::get().to(subreddit::page))
.route("/{sort:hot|new|top|rising|controversial}/", web::get().to(subreddit::page))
// Handle subscribe/unsubscribe
.route("/{action:subscribe|unsubscribe}/", web::post().to(subreddit::subscriptions))
.route("/{action:subscribe|unsubscribe}/", web::get().to(subreddit::subscriptions))
// View post on subreddit
.service(
web::scope("/comments/{id}/{title}")

View File

@ -103,7 +103,16 @@ pub async fn subscriptions(req: HttpRequest) -> HttpResponse {
}
// Redirect back to subreddit
let path = format!("/r/{}", sub);
// check for redirect parameter if unsubscribing from outside sidebar
let redirect_path = param(&format!("{}?{}", req.path(), req.query_string()), "redirect");
let path;
if redirect_path.len() > 1 && redirect_path.chars().nth(0).unwrap() == '/' {
path = redirect_path;
} else {
path = format!("/r/{}", sub);
}
res
.content_type("text/html")
.set_header("Location", path.to_string())

View File

@ -239,7 +239,7 @@ aside {
margin-top: 20px;
}
#sub_subscription > input {
#sub_subscription > a {
padding: 10px 20px;
border-radius: 5px;
}
@ -876,7 +876,7 @@ a.search_subreddit:hover {
opacity: 0.75;
}
#prefs {
.prefs {
display: flex;
flex-direction: column;
justify-content: space-between;
@ -886,7 +886,7 @@ a.search_subreddit:hover {
border-radius: 5px;
}
#prefs > div {
.prefs > div {
display: flex;
justify-content: space-between;
width: 100%;
@ -894,11 +894,11 @@ a.search_subreddit:hover {
align-items: center;
}
#prefs > div:not(:last-of-type) {
.prefs > div:not(:last-of-type) {
margin-bottom: 10px;
}
#prefs select {
.prefs select {
border-radius: 5px;
box-shadow: var(--shadow);
margin-left: 20px;
@ -917,6 +917,30 @@ input[type="submit"] {
-webkit-appearance: none;
-moz-appearance: none;
}
#settings_subs {
list-style: none;
padding: 0;
}
#settings_subs > li {
display: flex;
margin: 10px 0;
}
#settings_subs > li:last-of-type { margin-bottom: 0; }
#settings_subs > li > span {
padding: 10px 0;
margin-right: auto;
}
#settings_subs > li > a {
margin-left: 30px;
padding: 10px 20px;
border-radius: 5px;
background-color: var(--highlighted);
}
/* Markdown */
.md > *:not(:first-child) {

View File

@ -7,13 +7,9 @@
{% call utils::search("".to_owned(), "", "") %}
{% endblock %}
{% block subscriptions %}
{% call utils::sub_list("", "narrow") %}
{% endblock %}
{% block content %}
<form id="settings" action="/settings" method="POST">
<div id="prefs">
<div class="prefs">
<p>Appearance</p>
<div id="theme">
<label for="theme">Theme:</label>
@ -52,5 +48,19 @@
</div>
<p id="settings_note"><b>Note:</b> settings are saved in browser cookies. Clearing your cookie data will reset them.</p>
<input id="save" type="submit" value="Save">
{% if prefs.subs.len() > 0 %}
<aside class="prefs">
<p>Subscribed Subreddits</p>
<ul id="settings_subs">
{% for sub in prefs.subs %}
<li>
<span>{{ sub }}</span>
<a href="/r/{{ sub }}/unsubscribe/?redirect=/settings">Unsubscribe</a>
</li>
{% endfor %}
</ul>
</aside>
{% endif %}
</form>
{% endblock %}

View File

@ -125,17 +125,15 @@
<div>{{ sub.members }}</div>
<div>{{ sub.active }}</div>
</div>
<div id="sub_subscription">
{% if prefs.subs.contains(sub.name) %}
<form id="sub_subscription" action="/r/{{ sub.name }}/unsubscribe" method="POST">
<input class="subscribe remove" type="submit" value="Unsubscribe">
</form>
<a href="/r/{{ sub.name }}/unsubscribe" class="subscribe remove">Unsubscribe</a>
{% else %}
<form id="sub_subscription" action="/r/{{ sub.name }}/subscribe" method="POST">
<input class="subscribe add" type="submit" value="Subscribe">
</form>
<a href="/r/{{ sub.name }}/subscribe" class="subscribe add">Subscribe</a>
{% endif %}
</div>
</div>
</div>
<details class="panel" id="sidebar">
<summary id="sidebar_label">Sidebar</summary>
<div id="sidebar_contents">{{ sub.info }}</div>