create basic quicklist functionality

This commit is contained in:
ayaka 2024-12-22 04:04:43 +13:00
parent e478575706
commit 9856b7fd47
6 changed files with 26 additions and 3 deletions

View File

@ -96,6 +96,10 @@ pub struct Config {
#[serde(alias = "LIBREDDIT_DEFAULT_FILTERS")]
pub(crate) default_filters: Option<String>,
#[serde(rename = "REDLIB_DEFAULT_QUICKLIST")]
#[serde(alias = "LIBREDDIT_DEFAULT_QUICKLIST")]
pub(crate) default_quicklist: Option<String>,
#[serde(rename = "REDLIB_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")]
#[serde(alias = "LIBREDDIT_DEFAULT_DISABLE_VISIT_REDDIT_CONFIRMATION")]
pub(crate) default_disable_visit_reddit_confirmation: Option<String>,
@ -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<String> {
"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() {

View File

@ -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(),

View File

@ -121,7 +121,7 @@ fn set_cookies_method(req: Request<Body>, remove_cookies: bool) -> Response<Body
let mut response = redirect(&path);
for name in [PREFS.to_vec(), vec!["subscriptions", "filters"]].concat() {
for name in [PREFS.to_vec(), vec!["subscriptions", "filters", "quicklist"]].concat() {
match form.get(name) {
Some(value) => response.insert_cookie(
Cookie::build((name.to_owned(), value.clone()))

View File

@ -624,6 +624,7 @@ pub struct Preferences {
pub comment_sort: String,
pub post_sort: String,
pub subscriptions: Vec<String>,
pub quicklist: Vec<String>,
pub filters: Vec<String>,
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"),
}

View File

@ -153,7 +153,7 @@
</form>
<div id="settings_note">
<p><b>Note:</b> settings and subscriptions are saved in browser cookies. Clearing your cookies will reset them.</p><br>
<p>You can restore your current settings and subscriptions after clearing your cookies using <a href="/settings/restore/?theme={{ prefs.theme }}&mascot={{ prefs.mascot }}&front_page={{ prefs.front_page }}&layout={{ prefs.layout }}&wide={{ prefs.wide }}&post_sort={{ prefs.post_sort }}&comment_sort={{ prefs.comment_sort }}&show_nsfw={{ prefs.show_nsfw }}&use_hls={{ prefs.use_hls }}&ffmpeg_video_downloads={{ prefs.ffmpeg_video_downloads }}&hide_hls_notification={{ prefs.hide_hls_notification }}&hide_awards={{ prefs.hide_awards }}&fixed_navbar={{ prefs.fixed_navbar }}&hide_sidebar_and_summary={{ prefs.hide_sidebar_and_summary}}&subscriptions={{ prefs.subscriptions.join("%2B") }}&filters={{ prefs.filters.join("%2B") }}">this link</a>.</p>
<p>You can restore your current settings and subscriptions after clearing your cookies using <a href="/settings/restore/?theme={{ prefs.theme }}&mascot={{ prefs.mascot }}&front_page={{ prefs.front_page }}&layout={{ prefs.layout }}&wide={{ prefs.wide }}&post_sort={{ prefs.post_sort }}&comment_sort={{ prefs.comment_sort }}&show_nsfw={{ prefs.show_nsfw }}&use_hls={{ prefs.use_hls }}&ffmpeg_video_downloads={{ prefs.ffmpeg_video_downloads }}&hide_hls_notification={{ prefs.hide_hls_notification }}&hide_awards={{ prefs.hide_awards }}&fixed_navbar={{ prefs.fixed_navbar }}&hide_sidebar_and_summary={{ prefs.hide_sidebar_and_summary}}&subscriptions={{ prefs.subscriptions.join("%2B") }}&filters={{ prefs.filters.join("%2B") }}&quicklist={{ prefs.quicklist.join("%2B") }}">this link</a>.</p>
</div>
{% if prefs.subscriptions.len() > 0 %}
<div class="prefs" id="settings_subs">

View File

@ -41,6 +41,12 @@
<details id="feeds">
<summary>Feeds</summary>
<div id="feed_list">
{% if prefs.quicklist.len() > 0 %}
<p>QUICK ACCESS FEEDS</p>
{% for sub in prefs.quicklist %}
<a href="/r/{{ sub }}" {% if sub == current %}class="selected"{% endif %}>{{ sub }}</a>
{% endfor %}
{% endif %}
<p>MAIN FEEDS</p>
<a href="/">Home</a>
<a href="/r/popular">Popular</a>