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/main.rs b/src/main.rs index 101b2b1..d8a7d05 100644 --- a/src/main.rs +++ b/src/main.rs @@ -323,10 +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/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/settings.rs b/src/settings.rs index 6b65b40..6a65207 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -122,7 +122,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/subreddit.rs b/src/subreddit.rs index 3a07bdc..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(); @@ -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,16 @@ 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()); + // 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()); + } + } // Redirect back to subreddit @@ -326,6 +336,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/src/utils.rs b/src/utils.rs index 32f73a7..b8105c3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -625,6 +625,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, @@ -681,6 +682,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/static/style.css b/static/style.css index 63817d3..8cd1f4b 100644 --- a/static/style.css +++ b/static/style.css @@ -525,12 +525,22 @@ 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); + 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; } @@ -547,6 +557,8 @@ aside { #user_subscription, #sub_filter, #user_filter, +#sub_quicklist, +#user_quicklist, #sub_rss, #user_rss { margin-top: 20px; @@ -556,9 +568,16 @@ aside { margin-bottom: 20px; } +#sub_quicklist button, +#user_quicklist button { + padding: 0px; +} + .subscribe, .unsubscribe, .filter, +.unquick, +.quick, .unfilter { padding: 10px 20px; border-radius: 5px; @@ -570,12 +589,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 */ @@ -2286,4 +2315,4 @@ th { .download:active { background-color: var(--background); -} \ No newline at end of file +} diff --git a/templates/settings.html b/templates/settings.html index 861a9ca..398c2b3 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -158,7 +158,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/subreddit.html b/templates/subreddit.html index 4bda993..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 }}

@@ -134,13 +146,31 @@ {% endif %}
- {% if crate::utils::enable_rss() %} -
- - - +
+ {% if prefs.quicklist.contains(sub.name) %} +
+ +
+ {% else %} +
+ +
+ {% endif %}
- {% endif %}
diff --git a/templates/utils.html b/templates/utils.html index d526e7e..37d6ed8 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 %} + {% if sub.starts_with("u_") -%}{%let sub = format!("u/{}", &sub[2..]) -%}{{ sub }}{% else -%}{{ sub }}{% endif -%} + {% endfor %} + {% endif %}

MAIN FEEDS

Home Popular @@ -48,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 %}