chore: run cargo format

This commit is contained in:
Bnyro 2023-08-07 16:55:14 +02:00
parent 0540bb3ae2
commit 7908213245
15 changed files with 86 additions and 66 deletions

View File

@ -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,
};

View File

@ -25,7 +25,8 @@ pub fn fetch_instances(query_filter: &str) -> std::result::Result<Vec<Instance>,
.filter(|instance| {
instance.software == Some("lemmy".to_owned())
&& instance.domain.clone().contains(&lowercase_query_filter)
}).cloned()
})
.cloned()
.collect::<Vec<Instance>>()),
None => Ok(vec![]),
}

View File

@ -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,
},
};

View File

@ -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<Self> {
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));
}
@ -255,9 +261,9 @@ impl SimpleComponent for CommunityPage {
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);
}

View File

@ -95,9 +95,9 @@ impl FactoryComponent for CommunityRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message {
CommunityRowMsg::OpenCommunity => sender.output(crate::AppMsg::OpenCommunity(
self.community.community.id,
)),
CommunityRowMsg::OpenCommunity => {
sender.output(crate::AppMsg::OpenCommunity(self.community.community.id))
}
}
}
}

View File

@ -1,5 +1,5 @@
use relm4::prelude::*;
use gtk::prelude::*;
use relm4::prelude::*;
#[relm4::widget_template(pub)]
impl WidgetTemplate for LoadingIndicator {

View File

@ -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));
}
}
}

View File

@ -106,9 +106,9 @@ impl FactoryComponent for ModeratesRow {
fn update(&mut self, message: Self::Input, sender: FactorySender<Self>) {
match message {
ModeratesRowMsg::OpenCommunity => sender.output(crate::AppMsg::OpenCommunity(
self.community.community.id,
)),
ModeratesRowMsg::OpenCommunity => {
sender.output(crate::AppMsg::OpenCommunity(self.community.community.id))
}
}
}
}

View File

@ -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;

View File

@ -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<SortDropdown>,
@ -86,11 +92,12 @@ impl SimpleComponent for PostsPage {
root: &Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
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,
));
}
}
}

View File

@ -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);
}
});
}

View File

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

View File

@ -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<Self>,
) -> ComponentParts<Self> {
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);
}
});
}

View File

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