From 9856b7fd473df6146143b8f88b7b7db6153f6ba5 Mon Sep 17 00:00:00 2001 From: ayaka Date: Sun, 22 Dec 2024 04:04:43 +1300 Subject: [PATCH 1/4] create basic quicklist functionality --- src/config.rs | 12 ++++++++++++ src/instance_info.rs | 5 ++++- src/settings.rs | 2 +- src/utils.rs | 2 ++ templates/settings.html | 2 +- templates/utils.html | 6 ++++++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index a7319d0..1c1adbe 100644 --- a/src/config.rs +++ b/src/config.rs @@ -96,6 +96,10 @@ pub struct Config { #[serde(alias = "LIBREDDIT_DEFAULT_FILTERS")] pub(crate) default_filters: Option, + #[serde(rename = "REDLIB_DEFAULT_QUICKLIST")] + #[serde(alias = "LIBREDDIT_DEFAULT_QUICKLIST")] + pub(crate) default_quicklist: Option, + #[serde(rename = "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")] #[serde(alias = "LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")] pub(crate) default_disable_visit_reddit_confirmation: Option, @@ -160,6 +164,7 @@ impl Config { default_hide_score: parse("REDLIB_DEFAULT_HIDE_SCORE"), default_subscriptions: parse("REDLIB_DEFAULT_SUBSCRIPTIONS"), default_filters: parse("REDLIB_DEFAULT_FILTERS"), + default_quicklist: parse("REDLIB_DEFAULT_QUICKLIST"), default_disable_visit_reddit_confirmation: parse("REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION"), banner: parse("REDLIB_BANNER"), robots_disable_indexing: parse("REDLIB_ROBOTS_DISABLE_INDEXING"), @@ -191,6 +196,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_DEFAULT_HIDE_SCORE" => config.default_hide_score.clone(), "REDLIB_DEFAULT_SUBSCRIPTIONS" => config.default_subscriptions.clone(), "REDLIB_DEFAULT_FILTERS" => config.default_filters.clone(), + "REDLIB_DEFAULT_QUICKLIST" => config.default_quicklist.clone(), "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION" => config.default_disable_visit_reddit_confirmation.clone(), "REDLIB_BANNER" => config.banner.clone(), "REDLIB_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(), @@ -271,6 +277,12 @@ fn test_default_filters() { assert_eq!(get_setting("REDLIB_DEFAULT_FILTERS"), Some("news+bestof".into())); } +#[test] +#[sealed_test(env = [("REDLIB_DEFAULT_QUICKLIST", "news+popular")])] +fn test_default_quicklist() { + assert_eq!(get_setting("REDLIB_DEFAULT_QUICKLIST"), Some("news+popular".into())); +} + #[test] #[sealed_test] fn test_pushshift() { diff --git a/src/instance_info.rs b/src/instance_info.rs index f73a468..a3bf32d 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -152,6 +152,7 @@ impl InstanceInfo { ["Hide HLS notification", &convert(&self.config.default_hide_hls_notification)], ["Subscriptions", &convert(&self.config.default_subscriptions)], ["Filters", &convert(&self.config.default_filters)], + ["Quick Access Feeds", &convert(&self.config.default_quicklist)], ]) .with_header_row(["Default preferences"]), ); @@ -189,7 +190,8 @@ impl InstanceInfo { Default use FFmpeg: {:?}\n Default hide HLS notification: {:?}\n Default subscriptions: {:?}\n - Default filters: {:?}\n", + Default filters: {:?}\n + Default quicklist: {:?}\n", self.package_name, self.crate_version, self.git_commit, @@ -218,6 +220,7 @@ impl InstanceInfo { self.config.default_hide_hls_notification, self.config.default_subscriptions, self.config.default_filters, + self.config.default_quicklist, ) } StringType::Html => self.to_table(), diff --git a/src/settings.rs b/src/settings.rs index c7882a1..0ee2f6f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -121,7 +121,7 @@ fn set_cookies_method(req: Request, remove_cookies: bool) -> Response response.insert_cookie( Cookie::build((name.to_owned(), value.clone())) diff --git a/src/utils.rs b/src/utils.rs index 5b72a89..68d2ccf 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -624,6 +624,7 @@ pub struct Preferences { pub comment_sort: String, pub post_sort: String, pub subscriptions: Vec, + pub quicklist: Vec, pub filters: Vec, pub hide_awards: String, pub hide_score: String, @@ -679,6 +680,7 @@ impl Preferences { post_sort: setting(req, "post_sort"), subscriptions: setting(req, "subscriptions").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), filters: setting(req, "filters").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), + quicklist: setting(req, "quicklist").split('+').map(String::from).filter(|s| !s.is_empty()).collect(), hide_awards: setting(req, "hide_awards"), hide_score: setting(req, "hide_score"), } diff --git a/templates/settings.html b/templates/settings.html index 00b2220..f61a548 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -153,7 +153,7 @@

Note: settings and subscriptions are saved in browser cookies. Clearing your cookies will reset them.


-

You can restore your current settings and subscriptions after clearing your cookies using this link.

+

You can restore your current settings and subscriptions after clearing your cookies using this link.

{% if prefs.subscriptions.len() > 0 %}
diff --git a/templates/utils.html b/templates/utils.html index d526e7e..44bea0a 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -41,6 +41,12 @@
Feeds
+ {% if prefs.quicklist.len() > 0 %} +

QUICK ACCESS FEEDS

+ {% for sub in prefs.quicklist %} + {{ sub }} + {% endfor %} + {% endif %}

MAIN FEEDS

Home Popular From ad39254ddc529ac73721e7b0edf0476e3cdf247c Mon Sep 17 00:00:00 2001 From: ayaka Date: Sun, 22 Dec 2024 04:25:54 +1300 Subject: [PATCH 2/4] fix followed user rendering --- templates/utils.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/utils.html b/templates/utils.html index 44bea0a..37d6ed8 100644 --- a/templates/utils.html +++ b/templates/utils.html @@ -44,7 +44,7 @@ {% if prefs.quicklist.len() > 0 %}

QUICK ACCESS FEEDS

{% for sub in prefs.quicklist %} - {{ sub }} + {% if sub.starts_with("u_") -%}{%let sub = format!("u/{}", &sub[2..]) -%}{{ sub }}{% else -%}{{ sub }}{% endif -%} {% endfor %} {% endif %}

MAIN FEEDS

@@ -54,7 +54,7 @@ {% if prefs.subscriptions.len() > 0 %}

REDDIT FEEDS

{% for sub in prefs.subscriptions %} - {{ sub }} + {% if sub.starts_with("u_") -%}{%let sub = format!("u/{}", &sub[2..]) -%}{{ sub }}{% else -%}{{ sub }}{% endif -%} {% endfor %} {% endif %}
From 85dab5e0706e8fc240a7401c8140b824c0835b63 Mon Sep 17 00:00:00 2001 From: ayaka Date: Mon, 6 Jan 2025 09:32:52 +1300 Subject: [PATCH 3/4] add quicklist to subreddit --- src/main.rs | 2 ++ src/subreddit.rs | 21 ++++++++++++++++++++- static/style.css | 31 ++++++++++++++++++++++++++++--- templates/subreddit.html | 25 +++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 101b2b1..a5ced89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -327,6 +327,8 @@ async fn main() { app.at("/r/:sub/unsubscribe").post(|r| subreddit::subscriptions_filters(r).boxed()); app.at("/r/:sub/filter").post(|r| subreddit::subscriptions_filters(r).boxed()); app.at("/r/:sub/unfilter").post(|r| subreddit::subscriptions_filters(r).boxed()); + app.at("/r/:sub/quicklist").post(|r| subreddit::subscriptions_filters(r).boxed()); + app.at("/r/:sub/unquicklist").post(|r| subreddit::subscriptions_filters(r).boxed()); app.at("/r/:sub/comments/:id").get(|r| post::item(r).boxed()); app.at("/r/:sub/comments/:id/:title").get(|r| post::item(r).boxed()); diff --git a/src/subreddit.rs b/src/subreddit.rs index 3a07bdc..759aaea 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -229,6 +229,7 @@ pub async fn subscriptions_filters(req: Request) -> Result, let preferences = Preferences::new(&req); let mut sub_list = preferences.subscriptions; let mut filters = preferences.filters; + let mut quicklist = preferences.quicklist; // Retrieve list of posts for these subreddits to extract display names @@ -290,7 +291,14 @@ pub async fn subscriptions_filters(req: Request) -> Result, } else if action.contains(&"unfilter".to_string()) { // Remove sub name from filtered list filters.retain(|s| s.to_lowercase() != part.to_lowercase()); - } + } else if action.contains(&"quicklist".to_string()) && !quicklist.contains(&part.to_owned()) { + // Add each sub name to the filtered list + quicklist.push(part.to_owned()); + } else if action.contains(&"unquicklist".to_string()) { + // Remove sub name from filtered list + quicklist.retain(|s| s.to_lowercase() != part.to_lowercase()); + } + } // Redirect back to subreddit @@ -326,6 +334,17 @@ pub async fn subscriptions_filters(req: Request) -> Result, .into(), ); } + if quicklist.is_empty() { + response.remove_cookie("quicklist".to_string()); + } else { + response.insert_cookie( + Cookie::build(("quicklist", quicklist.join("+"))) + .path("/") + .http_only(true) + .expires(OffsetDateTime::now_utc() + Duration::weeks(52)) + .into(), + ); + } Ok(response) } diff --git a/static/style.css b/static/style.css index 990ddf4..77e2caa 100644 --- a/static/style.css +++ b/static/style.css @@ -429,7 +429,7 @@ a:hover { } svg { - stroke: var(--text); + color: var(--text); } img[src=""] { @@ -523,9 +523,16 @@ aside { margin-bottom: 20px; } +#sub_actions { + display: grid; + grid-template-columns: auto 2fr 1fr; + grid-template-rows: 1fr; + grid-column-gap: 0px; + grid-row-gap: 0px; +} + #user_details, #sub_details, -#sub_actions, #user_actions { display: grid; grid-template-columns: repeat(2, 1fr); @@ -545,6 +552,8 @@ aside { #user_subscription, #sub_filter, #user_filter, +#sub_quicklist, +#user_quicklist, #sub_rss, #user_rss { margin-top: 20px; @@ -554,9 +563,15 @@ aside { margin-bottom: 20px; } +#sub_quicklist button { + padding: 0px; +} + .subscribe, .unsubscribe, .filter, +.unquick, +.quick, .unfilter { padding: 10px 20px; border-radius: 5px; @@ -568,12 +583,22 @@ aside { color: var(--foreground); background-color: var(--accent); } +.quick { + color: var(--foreground); + background-color: var(--accent); + height: 18px; +} .unsubscribe, .unfilter { color: var(--text); background-color: var(--highlighted); } +.unquick { + color: var(--text); + background-color: var(--highlighted); + height: 18px; +} /* Feeds */ @@ -2283,4 +2308,4 @@ th { .download:active { background-color: var(--background); -} \ No newline at end of file +} diff --git a/templates/subreddit.html b/templates/subreddit.html index 4bda993..5d4b2dd 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -134,6 +134,31 @@ {% endif %}
+
+ {% if prefs.quicklist.contains(sub.name) %} +
+ +
+ {% else %} +
+ +
+ {% endif %} +
{% if crate::utils::enable_rss() %}
From 836cb15946bfab591fa275b9b704a498c2f03e49 Mon Sep 17 00:00:00 2001 From: ayaka Date: Mon, 6 Jan 2025 12:33:49 +1300 Subject: [PATCH 4/4] minimum viable product --- src/main.rs | 12 +++++------ src/subreddit.rs | 6 ++++-- static/style.css | 8 +++++-- templates/subreddit.html | 19 ++++++++++------- templates/user.html | 45 ++++++++++++++++++++++++++++++++-------- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/src/main.rs b/src/main.rs index a5ced89..d8a7d05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -323,12 +323,12 @@ async fn main() { .at("/r/u_:name") .get(|r| async move { Ok(redirect(&format!("/user/{}", r.param("name").unwrap_or_default()))) }.boxed()); - app.at("/r/:sub/subscribe").post(|r| subreddit::subscriptions_filters(r).boxed()); - app.at("/r/:sub/unsubscribe").post(|r| subreddit::subscriptions_filters(r).boxed()); - app.at("/r/:sub/filter").post(|r| subreddit::subscriptions_filters(r).boxed()); - app.at("/r/:sub/unfilter").post(|r| subreddit::subscriptions_filters(r).boxed()); - app.at("/r/:sub/quicklist").post(|r| subreddit::subscriptions_filters(r).boxed()); - app.at("/r/:sub/unquicklist").post(|r| subreddit::subscriptions_filters(r).boxed()); + app.at("/r/:sub/subscribe").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); + app.at("/r/:sub/unsubscribe").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); + app.at("/r/:sub/filter").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); + app.at("/r/:sub/unfilter").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); + app.at("/r/:sub/quicklist").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); + app.at("/r/:sub/unquicklist").post(|r| subreddit::subscriptions_filters_quicklists(r).boxed()); app.at("/r/:sub/comments/:id").get(|r| post::item(r).boxed()); app.at("/r/:sub/comments/:id/:title").get(|r| post::item(r).boxed()); diff --git a/src/subreddit.rs b/src/subreddit.rs index 759aaea..5f964ef 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -211,8 +211,8 @@ pub fn can_access_quarantine(req: &Request, sub: &str) -> bool { setting(req, &format!("allow_quaran_{}", sub.to_lowercase())).parse().unwrap_or_default() } -// Sub, filter, unfilter, or unsub by setting subscription cookie using response "Set-Cookie" header -pub async fn subscriptions_filters(req: Request) -> Result, String> { +// Sub, filter, unfilter, quicklist, unquicklist or unsub by setting subscription cookie using response "Set-Cookie" header +pub async fn subscriptions_filters_quicklists(req: Request) -> Result, String> { let sub = req.param("sub").unwrap_or_default(); let action: Vec = req.uri().path().split('/').map(String::from).collect(); @@ -294,6 +294,8 @@ pub async fn subscriptions_filters(req: Request) -> Result, } else if action.contains(&"quicklist".to_string()) && !quicklist.contains(&part.to_owned()) { // Add each sub name to the filtered list quicklist.push(part.to_owned()); + // Reorder quicklist alphabetically + quicklist.sort_by_key(|a| a.to_lowercase()); } else if action.contains(&"unquicklist".to_string()) { // Remove sub name from filtered list quicklist.retain(|s| s.to_lowercase() != part.to_lowercase()); diff --git a/static/style.css b/static/style.css index 77e2caa..9e171ac 100644 --- a/static/style.css +++ b/static/style.css @@ -535,7 +535,10 @@ aside { #sub_details, #user_actions { display: grid; - grid-template-columns: repeat(2, 1fr); + grid-template-columns: auto 2fr 1fr; + grid-template-rows: 1fr; + grid-column-gap: 0px; + grid-row-gap: 0px; } @media screen and (max-width: 279px) { #sub_actions { display: unset; } @@ -563,7 +566,8 @@ aside { margin-bottom: 20px; } -#sub_quicklist button { +#sub_quicklist button, +#user_quicklist button { padding: 0px; } diff --git a/templates/subreddit.html b/templates/subreddit.html index 5d4b2dd..5584863 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -104,6 +104,18 @@ Icon for r/{{ sub.name }}

{{ sub.title }}

r/{{ sub.name }}

+ {% if crate::utils::enable_rss() %} +
+ + + {% endif %}

{{ sub.description }}

@@ -159,13 +171,6 @@ {% endif %}
- {% if crate::utils::enable_rss() %} - - {% endif %}