From 75bbcefbec714325fd8be13536b55f56bf3538bd Mon Sep 17 00:00:00 2001 From: Matthew Crossman Date: Sat, 30 Jan 2021 16:00:55 +1100 Subject: [PATCH 01/19] Display sub list from list in cookie. Very basic sub list setup. Cookie must be manually added in devtools. --- src/utils.rs | 2 ++ static/style.css | 48 ++++++++++++++++++++++++++++++++++++++-- templates/base.html | 4 ++++ templates/post.html | 4 ++++ templates/search.html | 4 ++++ templates/settings.html | 4 ++++ templates/subreddit.html | 11 +++++++++ templates/user.html | 4 ++++ templates/utils.html | 12 ++++++++++ templates/wiki.html | 4 ++++ 10 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index f06eb79..8b1df82 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -129,6 +129,7 @@ pub struct Preferences { pub wide: String, pub hide_nsfw: String, pub comment_sort: String, + pub subs: Vec, } // @@ -144,6 +145,7 @@ pub fn prefs(req: HttpRequest) -> Preferences { wide: cookie(&req, "wide"), hide_nsfw: cookie(&req, "hide_nsfw"), comment_sort: cookie(&req, "comment_sort"), + subs: cookie(&req, "subreddits").split(",").map(|s| s.to_string()).collect(), } } diff --git a/static/style.css b/static/style.css index e8594b2..7452fce 100644 --- a/static/style.css +++ b/static/style.css @@ -68,6 +68,7 @@ pre, form, fieldset, table, th, td, select, input { body { background: var(--background); font-size: 15px; + padding-top: 60px; } nav { @@ -108,7 +109,7 @@ main { justify-content: center; max-width: 1000px; padding: 10px 20px; - margin: 60px auto 20px auto + margin: 0 auto; } .wide main { @@ -232,6 +233,45 @@ aside { color: var(--accent); } +/* Subscriptions/Favorites */ + +#sub_subscription { + margin-top: 30px; +} + +#sub_subscription > a { + padding: 10px 20px; + border-radius: 5px; + color: var(--foreground); +} + +#sub_subscription > .add { color: var(--foreground); background-color: var(--accent); } +#sub_subscription > .remove { color: var(--text); background-color: var(--highlighted); } + +#sub_list { + display: flex; + align-items: center; + justify-content: center; + padding: 10px 20px; +} + +#subs { + border-radius: 5px; + box-shadow: var(--shadow); + background: var(--outside); + display: flex; + overflow: auto; +} + +#subs a { + padding: 10px 20px; +} + +#subs > .selected { + background-color: var(--accent); + color: var(--foreground); +} + /* Wiki Pages */ #wiki { @@ -954,10 +994,12 @@ td, th { } @media screen and (max-width: 800px) { + body { padding-top: 100px } + main { flex-direction: column-reverse; padding: 10px; - margin: 100px 0 10px 0; + margin: 0 0 10px 0; max-width: 100%; } @@ -967,6 +1009,8 @@ td, th { width: calc(100% - 20px); } + #sub_list { padding: 10px; } + aside, #subreddit, #user { margin: 0; max-width: 100%; diff --git a/templates/base.html b/templates/base.html index 7764eae..2451508 100644 --- a/templates/base.html +++ b/templates/base.html @@ -26,6 +26,10 @@ {% block search %}{% endblock %} code + + + {% block sub_list %} + {% endblock %} {% block body %} diff --git a/templates/post.html b/templates/post.html index cdddaf2..0d8596b 100644 --- a/templates/post.html +++ b/templates/post.html @@ -13,6 +13,10 @@ {% endblock %} +{% block sub_list %} + {% call utils::sub_list(post.community.as_str()) %} +{% endblock %} + {% macro comment(item) -%}
diff --git a/templates/search.html b/templates/search.html index ecbe340..c244fc3 100644 --- a/templates/search.html +++ b/templates/search.html @@ -3,6 +3,10 @@ {% block title %}Libreddit: search results - {{ params.q }}{% endblock %} +{% block sub_list %} + {% call utils::sub_list("") %} +{% endblock %} + {% block content %}
diff --git a/templates/settings.html b/templates/settings.html index 0dbec00..3fe6910 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -7,6 +7,10 @@ {% call utils::search("".to_owned(), "", "") %} {% endblock %} +{% block sub_list %} + {% call utils::sub_list("") %} +{% endblock %} + {% block content %}
diff --git a/templates/subreddit.html b/templates/subreddit.html index 9a26aaa..eb71961 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -11,6 +11,10 @@ {% call utils::search(["/r/", sub.name.as_str()].concat(), "") %} {% endblock %} +{% block sub_list %} + {% call utils::sub_list(sub.name.as_str()) %} +{% endblock %} + {% block body %}
@@ -121,6 +125,13 @@
{{ sub.members }}
{{ sub.active }}
+
+ {% if prefs.subs.contains(sub.name) %} + + {% else %} + + {% endif %} +
{% endif %} {%- endmacro %} diff --git a/templates/wiki.html b/templates/wiki.html index 0c946d8..882f228 100644 --- a/templates/wiki.html +++ b/templates/wiki.html @@ -10,7 +10,7 @@ {% call utils::search(["/r/", sub.as_str()].concat(), "") %} {% endblock %} -{% block sub_list %} +{% block subscriptions %} {% call utils::sub_list(sub.as_str()) %} {% endblock %} From dc2030e6f3c46a9f8af52d8f93a54dba4b6634b7 Mon Sep 17 00:00:00 2001 From: Matthew Crossman Date: Sat, 30 Jan 2021 21:21:54 +1100 Subject: [PATCH 06/19] Vertical list subscriptions. --- static/style.css | 50 +++++++++++++++++++++++++++++++--------- templates/base.html | 3 ++- templates/post.html | 2 +- templates/search.html | 2 +- templates/settings.html | 2 +- templates/subreddit.html | 2 +- templates/user.html | 2 +- templates/utils.html | 20 ++++++++-------- templates/wiki.html | 2 +- 9 files changed, 58 insertions(+), 27 deletions(-) diff --git a/static/style.css b/static/style.css index 9e57140..61c2e73 100644 --- a/static/style.css +++ b/static/style.css @@ -84,7 +84,7 @@ nav { font-size: 20px; - z-index: 1; + z-index: 2; top: 0; padding: 5px 15px; min-height: 40px; @@ -256,28 +256,49 @@ aside { /* Subscribed subreddit list */ -#subscriptions { +#subscriptions_container { display: flex; max-width: 1000px; margin: 0 auto; - align-items: center; padding: 10px 20px; } -.wide #subscriptions { +#subscriptions_container.narrow { + max-width: 750px; +} + +.wide #subscriptions_container, .wide #subscriptions_container.narrow { max-width: calc(100% - 40px); } +#subscriptions { + display: inline-block; + position: relative; + border-radius: 5px; + background-color: var(--outside); + align-items: center; + box-sizing: border-box; +} + +#subscriptions > summary { + padding: 10px 20px 10px 15px; +} + #sub_list { + position: absolute; + display: flex; + min-width: 100%; border-radius: 5px; box-shadow: var(--shadow); background: var(--outside); - display: flex; + flex-direction: column; overflow: auto; + z-index: 1; } #sub_list > a { padding: 10px 20px; + transition: 0.2s background; } #sub_list > .selected { @@ -285,6 +306,10 @@ aside { color: var(--foreground); } +#sub_list > a:not(.selected):hover { + background-color: var(--foreground); +} + /* Wiki Pages */ #wiki { @@ -505,10 +530,6 @@ a.search_subreddit:hover { .post:not(:last-child) { margin-bottom: 10px; } -.post.highlighted { - margin: 20px 0; -} - .post:hover { background: var(--foreground); } @@ -1022,9 +1043,16 @@ td, th { width: calc(100% - 20px); } - #sub_list { + #subscriptions_container { padding: 10px; - max-width: 100%; + justify-content: center; + } + #subscriptions { position: unset; } + + #sub_list { + left: 10px; + right: 10px; + min-width: auto; } aside, #subreddit, #user { diff --git a/templates/base.html b/templates/base.html index 520b737..e333e05 100644 --- a/templates/base.html +++ b/templates/base.html @@ -23,10 +23,11 @@ v{{ env!("CARGO_PKG_VERSION") }} settings

- {% block subscriptions %}{% endblock %} {% block search %}{% endblock %} code + + {% block subscriptions %}{% endblock %} {% block body %} diff --git a/templates/post.html b/templates/post.html index 619005e..a8db811 100644 --- a/templates/post.html +++ b/templates/post.html @@ -14,7 +14,7 @@ {% endblock %} {% block subscriptions %} - {% call utils::sub_list(post.community.as_str()) %} + {% call utils::sub_list(post.community.as_str(), "narrow") %} {% endblock %} diff --git a/templates/search.html b/templates/search.html index 37edfc6..33e644a 100644 --- a/templates/search.html +++ b/templates/search.html @@ -4,7 +4,7 @@ {% block title %}Libreddit: search results - {{ params.q }}{% endblock %} {% block subscriptions %} - {% call utils::sub_list("") %} + {% call utils::sub_list("", "narrow") %} {% endblock %} {% block content %} diff --git a/templates/settings.html b/templates/settings.html index e0e3bf3..a2514ea 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -8,7 +8,7 @@ {% endblock %} {% block subscriptions %} - {% call utils::sub_list("") %} + {% call utils::sub_list("", "narrow") %} {% endblock %} {% block content %} diff --git a/templates/subreddit.html b/templates/subreddit.html index e3d550d..94c94d6 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -12,7 +12,7 @@ {% endblock %} {% block subscriptions %} - {% call utils::sub_list(sub.name.as_str()) %} + {% call utils::sub_list(sub.name.as_str(), "wide") %} {% endblock %} {% block body %} diff --git a/templates/user.html b/templates/user.html index c19a3ca..2f5f250 100644 --- a/templates/user.html +++ b/templates/user.html @@ -8,7 +8,7 @@ {% block title %}{{ user.name.replace("u/", "") }} (u/{{ user.name }}) - Libreddit{% endblock %} {% block subscriptions %} - {% call utils::sub_list("") %} + {% call utils::sub_list("", "wide") %} {% endblock %} {% block body %} diff --git a/templates/utils.html b/templates/utils.html index f8a0318..f036045 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -40,15 +40,17 @@ {% endfor %} {%- endmacro %} -{% macro sub_list(current) -%} +{% macro sub_list(current, width) -%} {% if prefs.subs.len() > 0 %} -
- subscribed -
- {% for sub in prefs.subs %} - {{ sub }} - {% endfor %} -
-
+
+
+ Subscriptions +
+ {% for sub in prefs.subs %} + {{ sub }} + {% endfor %} +
+
+
{% endif %} {%- endmacro %} diff --git a/templates/wiki.html b/templates/wiki.html index 882f228..0a05fb3 100644 --- a/templates/wiki.html +++ b/templates/wiki.html @@ -11,7 +11,7 @@ {% endblock %} {% block subscriptions %} - {% call utils::sub_list(sub.as_str()) %} + {% call utils::sub_list(sub.as_str(), "narrow") %} {% endblock %} {% block body %} From 449899962a57fdb8864016791baa9a149b9ca17f Mon Sep 17 00:00:00 2001 From: Matthew Crossman Date: Sat, 30 Jan 2021 22:27:49 +1100 Subject: [PATCH 07/19] 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 %} +