From 7908213245f1dfaa2ee323cc2f354f7eafef49ba Mon Sep 17 00:00:00 2001 From: Bnyro Date: Mon, 7 Aug 2023 16:55:14 +0200 Subject: [PATCH] chore: run cargo format --- src/api/community.rs | 7 +++++-- src/api/instances.rs | 3 ++- src/api/user.rs | 5 +++-- src/components/community_page.rs | 30 +++++++++++++++++------------ src/components/community_row.rs | 6 +++--- src/components/loading_indicator.rs | 4 ++-- src/components/mention_row.rs | 4 +--- src/components/moderates_row.rs | 6 +++--- src/components/post_row.rs | 4 +--- src/components/posts_page.rs | 27 ++++++++++++++++++-------- src/components/profile_page.rs | 12 +++++------- src/components/voting_row.rs | 15 ++++++--------- src/dialogs/mod.rs | 2 +- src/dialogs/site_info.rs | 22 ++++++++++++--------- src/main.rs | 5 ++++- 15 files changed, 86 insertions(+), 66 deletions(-) diff --git a/src/api/community.rs b/src/api/community.rs index 0ceb5a1..b0de72a 100644 --- a/src/api/community.rs +++ b/src/api/community.rs @@ -1,5 +1,8 @@ use lemmy_api_common::{ - community::{CommunityResponse, FollowCommunity, GetCommunity, GetCommunityResponse, BlockCommunityResponse, BlockCommunity}, + community::{ + BlockCommunity, BlockCommunityResponse, CommunityResponse, FollowCommunity, GetCommunity, + GetCommunityResponse, + }, lemmy_db_schema::newtypes::CommunityId, }; @@ -42,4 +45,4 @@ pub fn block_community( }; super::post("/community/block", ¶ms) -} \ No newline at end of file +} diff --git a/src/api/instances.rs b/src/api/instances.rs index f317101..620fdca 100644 --- a/src/api/instances.rs +++ b/src/api/instances.rs @@ -25,7 +25,8 @@ pub fn fetch_instances(query_filter: &str) -> std::result::Result, .filter(|instance| { instance.software == Some("lemmy".to_owned()) && instance.domain.clone().contains(&lowercase_query_filter) - }).cloned() + }) + .cloned() .collect::>()), None => Ok(vec![]), } diff --git a/src/api/user.rs b/src/api/user.rs index 0f6d8ab..78b2374 100644 --- a/src/api/user.rs +++ b/src/api/user.rs @@ -1,8 +1,9 @@ use lemmy_api_common::{ lemmy_db_schema::{newtypes::PersonId, CommentSortType}, person::{ - GetPersonDetails, GetPersonDetailsResponse, GetPersonMentions, GetPersonMentionsResponse, - GetReplies, GetRepliesResponse, MarkAllAsRead, BlockPersonResponse, BlockPerson, + BlockPerson, BlockPersonResponse, GetPersonDetails, GetPersonDetailsResponse, + GetPersonMentions, GetPersonMentionsResponse, GetReplies, GetRepliesResponse, + MarkAllAsRead, }, }; diff --git a/src/components/community_page.rs b/src/components/community_page.rs index 48f1068..59dc0b0 100644 --- a/src/components/community_page.rs +++ b/src/components/community_page.rs @@ -4,7 +4,8 @@ use crate::{ }; use gtk::prelude::*; use lemmy_api_common::{ - lemmy_db_schema::{SubscribedType, SortType}, lemmy_db_views::structs::PostView, + lemmy_db_schema::{SortType, SubscribedType}, + lemmy_db_views::structs::PostView, lemmy_db_views_actor::structs::CommunityView, }; use relm4::{factory::FactoryVecDeque, prelude::*}; @@ -12,7 +13,10 @@ use relm4_components::web_image::WebImage; use crate::{api, settings, util::get_web_image_msg}; -use super::{post_row::PostRow, sort_dropdown::{SortDropdown, SortDropdownOutput}}; +use super::{ + post_row::PostRow, + sort_dropdown::{SortDropdown, SortDropdownOutput}, +}; pub struct CommunityPage { info: CommunityView, @@ -165,11 +169,12 @@ impl SimpleComponent for CommunityPage { ) -> relm4::ComponentParts { let avatar = WebImage::builder().launch("".to_string()).detach(); let posts = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender()); - let sort_dropdown = SortDropdown::builder().launch(()).forward(sender.input_sender(), |msg| { - match msg { - SortDropdownOutput::New(sort_order) => CommunityInput::UpdateOrder(sort_order), - } - }); + let sort_dropdown = + SortDropdown::builder() + .launch(()) + .forward(sender.input_sender(), |msg| match msg { + SortDropdownOutput::New(sort_order) => CommunityInput::UpdateOrder(sort_order), + }); let dialog = EditorDialog::builder() .transient_for(root) @@ -215,7 +220,8 @@ impl SimpleComponent for CommunityPage { self.current_posts_page += 1; let page = self.current_posts_page; std::thread::spawn(move || { - let community_posts = api::posts::list_posts(page, Some(name), None, Some(sort_type)); + let community_posts = + api::posts::list_posts(page, Some(name), None, Some(sort_type)); if let Ok(community_posts) = community_posts { sender.input(CommunityInput::DoneFetchPosts(community_posts)); } @@ -250,14 +256,14 @@ impl SimpleComponent for CommunityPage { } CommunityInput::ToggleSubscription => { let community_id = self.info.community.id; - let new_state = matches!(self.info.subscribed, SubscribedType::NotSubscribed); + let new_state = matches!(self.info.subscribed, SubscribedType::NotSubscribed); std::thread::spawn(move || { match api::community::follow_community(community_id, new_state) { Ok(community) => { sender.input(CommunityInput::UpdateSubscriptionState( - community.community_view.subscribed, - )); - }, + community.community_view.subscribed, + )); + } Err(err) => { println!("{}", err); } diff --git a/src/components/community_row.rs b/src/components/community_row.rs index 92c3ab8..b833135 100644 --- a/src/components/community_row.rs +++ b/src/components/community_row.rs @@ -95,9 +95,9 @@ impl FactoryComponent for CommunityRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { - CommunityRowMsg::OpenCommunity => sender.output(crate::AppMsg::OpenCommunity( - self.community.community.id, - )), + CommunityRowMsg::OpenCommunity => { + sender.output(crate::AppMsg::OpenCommunity(self.community.community.id)) + } } } } diff --git a/src/components/loading_indicator.rs b/src/components/loading_indicator.rs index 7b2e3cb..a2716dd 100644 --- a/src/components/loading_indicator.rs +++ b/src/components/loading_indicator.rs @@ -1,5 +1,5 @@ -use relm4::prelude::*; use gtk::prelude::*; +use relm4::prelude::*; #[relm4::widget_template(pub)] impl WidgetTemplate for LoadingIndicator { @@ -19,4 +19,4 @@ impl WidgetTemplate for LoadingIndicator { }, } } -} \ No newline at end of file +} diff --git a/src/components/mention_row.rs b/src/components/mention_row.rs index 73ca660..77bb00e 100644 --- a/src/components/mention_row.rs +++ b/src/components/mention_row.rs @@ -160,9 +160,7 @@ impl FactoryComponent for MentionRow { sender.output(crate::AppMsg::OpenPost(self.comment.post.id)); } MentionRowMsg::OpenCommunity => { - sender.output(crate::AppMsg::OpenCommunity( - self.comment.community.id, - )); + sender.output(crate::AppMsg::OpenCommunity(self.comment.community.id)); } } } diff --git a/src/components/moderates_row.rs b/src/components/moderates_row.rs index 8a46fff..468ec56 100644 --- a/src/components/moderates_row.rs +++ b/src/components/moderates_row.rs @@ -106,9 +106,9 @@ impl FactoryComponent for ModeratesRow { fn update(&mut self, message: Self::Input, sender: FactorySender) { match message { - ModeratesRowMsg::OpenCommunity => sender.output(crate::AppMsg::OpenCommunity( - self.community.community.id, - )), + ModeratesRowMsg::OpenCommunity => { + sender.output(crate::AppMsg::OpenCommunity(self.community.community.id)) + } } } } diff --git a/src/components/post_row.rs b/src/components/post_row.rs index c6c0e5f..a431384 100644 --- a/src/components/post_row.rs +++ b/src/components/post_row.rs @@ -194,9 +194,7 @@ impl FactoryComponent for PostRow { PostRowMsg::OpenPerson => { sender.output(crate::AppMsg::OpenPerson(self.post.creator.id)) } - PostRowMsg::OpenPost => { - sender.output(crate::AppMsg::OpenPost(self.post.post.id)) - } + PostRowMsg::OpenPost => sender.output(crate::AppMsg::OpenPost(self.post.post.id)), PostRowMsg::ToggleSaved => { let post_id = self.post.post.id; let new_state = !self.post.saved; diff --git a/src/components/posts_page.rs b/src/components/posts_page.rs index d38b322..8b4e582 100644 --- a/src/components/posts_page.rs +++ b/src/components/posts_page.rs @@ -1,10 +1,16 @@ use gtk::prelude::*; -use lemmy_api_common::{lemmy_db_schema::{ListingType, SortType}, lemmy_db_views::structs::PostView}; +use lemmy_api_common::{ + lemmy_db_schema::{ListingType, SortType}, + lemmy_db_views::structs::PostView, +}; use relm4::{factory::FactoryVecDeque, prelude::*}; use crate::api; -use super::{post_row::PostRow, sort_dropdown::{SortDropdown, SortDropdownOutput}}; +use super::{ + post_row::PostRow, + sort_dropdown::{SortDropdown, SortDropdownOutput}, +}; pub struct PostsPage { sort_dropdown: Controller, @@ -86,11 +92,12 @@ impl SimpleComponent for PostsPage { root: &Self::Root, sender: ComponentSender, ) -> ComponentParts { - let sort_dropdown = SortDropdown::builder().launch(()).forward(sender.input_sender(), |msg| { - match msg { - SortDropdownOutput::New(sort_order) => PostsPageInput::UpdateOrder(sort_order), - } - }); + let sort_dropdown = + SortDropdown::builder() + .launch(()) + .forward(sender.input_sender(), |msg| match msg { + SortDropdownOutput::New(sort_order) => PostsPageInput::UpdateOrder(sort_order), + }); let posts = FactoryVecDeque::new(gtk::Box::default(), sender.output_sender()); let model = Self { sort_dropdown, @@ -146,7 +153,11 @@ impl SimpleComponent for PostsPage { } PostsPageInput::UpdateOrder(order) => { self.posts_order = order; - sender.input_sender().emit(PostsPageInput::FetchPosts(self.posts_type, order, true)); + sender.input_sender().emit(PostsPageInput::FetchPosts( + self.posts_type, + order, + true, + )); } } } diff --git a/src/components/profile_page.rs b/src/components/profile_page.rs index f6f8501..638e85b 100644 --- a/src/components/profile_page.rs +++ b/src/components/profile_page.rs @@ -239,15 +239,13 @@ impl SimpleComponent for ProfilePage { } }; }); - }, + } ProfileInput::BlockUser => { let person_id = self.info.person_view.person.id; - std::thread::spawn(move || { - match api::user::block_user(person_id, true) { - Ok(_resp) => {} - Err(err) => { - println!("{}", err); - } + std::thread::spawn(move || match api::user::block_user(person_id, true) { + Ok(_resp) => {} + Err(err) => { + println!("{}", err); } }); } diff --git a/src/components/voting_row.rs b/src/components/voting_row.rs index b7f745e..9ad4353 100644 --- a/src/components/voting_row.rs +++ b/src/components/voting_row.rs @@ -106,17 +106,16 @@ impl SimpleComponent for VotingRowModel { match message { VotingRowInput::Vote(vote) => { let mut score = self.stats.own_vote.unwrap_or(0) + vote; - if !(-1..=1).contains(&score) { score = 0 }; + if !(-1..=1).contains(&score) { + score = 0 + }; if settings::get_current_account().jwt.is_none() { return; } let stats = self.stats.clone(); std::thread::spawn(move || { let info = if stats.post_id.is_some() { - let response = api::post::like_post( - PostId(stats.post_id.unwrap()), - score, - ); + let response = api::post::like_post(PostId(stats.post_id.unwrap()), score); match response { Ok(post) => Some(VotingStats::from_post( post.post_view.counts, @@ -128,10 +127,8 @@ impl SimpleComponent for VotingRowModel { } } } else { - let response = api::comment::like_comment( - CommentId(stats.comment_id.unwrap()), - score, - ); + let response = + api::comment::like_comment(CommentId(stats.comment_id.unwrap()), score); match response { Ok(comment) => Some(VotingStats::from_comment( comment.comment_view.counts, diff --git a/src/dialogs/mod.rs b/src/dialogs/mod.rs index 71c2182..c6e3313 100644 --- a/src/dialogs/mod.rs +++ b/src/dialogs/mod.rs @@ -1,3 +1,3 @@ pub mod about; pub mod editor; -pub mod site_info; \ No newline at end of file +pub mod site_info; diff --git a/src/dialogs/site_info.rs b/src/dialogs/site_info.rs index 26ab1e7..fff5d77 100644 --- a/src/dialogs/site_info.rs +++ b/src/dialogs/site_info.rs @@ -1,7 +1,7 @@ +use crate::components::loading_indicator::LoadingIndicator; use gtk::prelude::*; use lemmy_api_common::site::GetSiteResponse; use relm4::prelude::*; -use crate::components::loading_indicator::LoadingIndicator; use crate::api; @@ -54,7 +54,11 @@ impl SimpleComponent for SiteInfo { root: &Self::Root, sender: ComponentSender, ) -> ComponentParts { - let model = Self { visible: false, loading: true, site_info: api::site::default_site_info() }; + let model = Self { + visible: false, + loading: true, + site_info: api::site::default_site_info(), + }; let widgets = view_output!(); ComponentParts { model, widgets } } @@ -64,13 +68,13 @@ impl SimpleComponent for SiteInfo { SiteInfoInput::Fetch => { self.loading = true; self.visible = true; - std::thread::spawn(move || { - match api::site::fetch_site() { - Ok(site_info) => sender.input(SiteInfoInput::Update(site_info)), - Err(err) => { - sender.output_sender().emit(crate::AppMsg::ShowMessage(err.to_string())); - sender.input_sender().emit(SiteInfoInput::Hide); - } + std::thread::spawn(move || match api::site::fetch_site() { + Ok(site_info) => sender.input(SiteInfoInput::Update(site_info)), + Err(err) => { + sender + .output_sender() + .emit(crate::AppMsg::ShowMessage(err.to_string())); + sender.input_sender().emit(SiteInfoInput::Hide); } }); } diff --git a/src/main.rs b/src/main.rs index aadb810..3e23d6a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,10 @@ use components::{ posts_page::{PostsPage, PostsPageInput}, profile_page::{ProfileInput, ProfilePage}, }; -use dialogs::{about::AboutDialog, site_info::{SiteInfo, SiteInfoInput}}; +use dialogs::{ + about::AboutDialog, + site_info::{SiteInfo, SiteInfoInput}, +}; use gtk::prelude::*; use lemmy_api_common::{ community::GetCommunityResponse,