From 449899962a57fdb8864016791baa9a149b9ca17f Mon Sep 17 00:00:00 2001 From: Matthew Crossman Date: Sat, 30 Jan 2021 22:27:49 +1100 Subject: [PATCH] Change subscription to get. Add subs to settings. --- src/main.rs | 2 +- src/subreddit.rs | 11 ++++++++++- static/style.css | 34 +++++++++++++++++++++++++++++----- templates/settings.html | 20 +++++++++++++++----- templates/subreddit.html | 16 +++++++--------- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7690c11..4cc134d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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}") diff --git a/src/subreddit.rs b/src/subreddit.rs index 8cd46a2..a395740 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -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()) diff --git a/static/style.css b/static/style.css index 61c2e73..674aaf1 100644 --- a/static/style.css +++ b/static/style.css @@ -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) { diff --git a/templates/settings.html b/templates/settings.html index a2514ea..96e397c 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -7,13 +7,9 @@ {% call utils::search("".to_owned(), "", "") %} {% endblock %} -{% block subscriptions %} - {% call utils::sub_list("", "narrow") %} -{% endblock %} - {% block content %}
-
+

Appearance

@@ -52,5 +48,19 @@

Note: settings are saved in browser cookies. Clearing your cookie data will reset them.

+ {% if prefs.subs.len() > 0 %} + + {% endif %} + {% endblock %} diff --git a/templates/subreddit.html b/templates/subreddit.html index 94c94d6..ee6ed93 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -125,15 +125,13 @@
{{ sub.members }}
{{ sub.active }}
- {% if prefs.subs.contains(sub.name) %} -
- -
- {% else %} -
- -
- {% endif %} +
+ {% if prefs.subs.contains(sub.name) %} + + {% else %} + + {% endif %} +