From 75bbcefbec714325fd8be13536b55f56bf3538bd Mon Sep 17 00:00:00 2001 From: Matthew Crossman Date: Sat, 30 Jan 2021 16:00:55 +1100 Subject: [PATCH] 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 %} +