diff --git a/Cargo.lock b/Cargo.lock index 65722f8..a148983 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -608,7 +608,7 @@ checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" [[package]] name = "libreddit" -version = "0.18.2" +version = "0.19.0" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index 94bc79a..92d2587 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.18.2" +version = "0.19.0" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/search.rs b/src/search.rs index 2ba8d56..aff7173 100644 --- a/src/search.rs +++ b/src/search.rs @@ -16,6 +16,7 @@ struct SearchParams { before: String, after: String, restrict_sr: String, + typed: String, } // STRUCTS @@ -55,10 +56,12 @@ pub async fn find(req: Request) -> Result, String> { return Ok(random); } + let typed = param(&path, "type").unwrap_or_default(); + let sort = param(&path, "sort").unwrap_or_else(|| "relevance".to_string()); // If search is not restricted to this subreddit, show other subreddits in search results - let subreddits = param(&path, "restrict_sr").map_or(search_subreddits(&query).await, |_| Vec::new()); + let subreddits = param(&path, "restrict_sr").map_or(search_subreddits(&query, &typed).await, |_| Vec::new()); let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str())); @@ -74,6 +77,7 @@ pub async fn find(req: Request) -> Result, String> { before: param(&path, "after").unwrap_or_default(), after, restrict_sr: param(&path, "restrict_sr").unwrap_or_default(), + typed, }, prefs: Preferences::new(req), url, @@ -89,8 +93,9 @@ pub async fn find(req: Request) -> Result, String> { } } -async fn search_subreddits(q: &str) -> Vec { - let subreddit_search_path = format!("/subreddits/search.json?q={}&limit=3", q.replace(' ', "+")); +async fn search_subreddits(q: &str, typed: &str) -> Vec { + let limit = if typed == "sr_user" { "50" } else { "3" }; + let subreddit_search_path = format!("/subreddits/search.json?q={}&limit={}", q.replace(' ', "+"), limit); // Send a request to the url json(subreddit_search_path, false).await.unwrap_or_default()["data"]["children"] @@ -101,9 +106,7 @@ async fn search_subreddits(q: &str) -> Vec { .map(|subreddit| { // For each subreddit from subreddit list // Fetch subreddit icon either from the community_icon or icon_img value - let icon = subreddit["data"]["community_icon"] - .as_str() - .map_or_else(|| val(subreddit, "icon_img"), ToString::to_string); + let icon = subreddit["data"]["community_icon"].as_str().map_or_else(|| val(subreddit, "icon_img"), ToString::to_string); Subreddit { name: val(subreddit, "display_name_prefixed"), diff --git a/static/style.css b/static/style.css index 18babad..c1edc5e 100644 --- a/static/style.css +++ b/static/style.css @@ -658,6 +658,13 @@ a.search_subreddit:hover { opacity: 0.5; } +#more_subreddits { + justify-content: center; + color: var(--accent); + font-weight: 600; + text-align: center; +} + /* Post */ .sep { @@ -777,7 +784,7 @@ a.search_subreddit:hover { font-weight: bold; } -.post_media_image, .post .__NoScript_PlaceHolder__, .post_media_video, .gallery { +.post_media_image, .post .__NoScript_PlaceHolder__, .post_media_video, .gallery { max-width: calc(100% - 40px); grid-area: post_media; margin: 15px auto 5px auto; @@ -1044,7 +1051,7 @@ a.search_subreddit:hover { } summary.comment_data { - cursor: pointer; + cursor: pointer; } .moderator, .admin { opacity: 1; } diff --git a/templates/search.html b/templates/search.html index 02f10ef..b7b99c5 100644 --- a/templates/search.html +++ b/templates/search.html @@ -17,6 +17,7 @@ {% endif %} + {% if params.typed == "sr_user" %}{% endif %} {% if params.sort != "new" %}