Replace unneeded if else expressions with set_visible

This commit is contained in:
Bnyro 2023-07-02 19:25:27 +02:00
parent 5e353c27cb
commit e51da627ea
9 changed files with 125 additions and 183 deletions

View File

@ -56,14 +56,10 @@ impl FactoryComponent for CommentRow {
set_spacing: 10, set_spacing: 10,
set_vexpand: false, set_vexpand: false,
if self.comment.creator.avatar.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
community_image -> gtk::Box {} community_image -> gtk::Box {
} set_hexpand: false,
} else { set_visible: self.comment.creator.avatar.is_some(),
gtk::Box {}
}, },
gtk::Button { gtk::Button {
@ -91,32 +87,24 @@ impl FactoryComponent for CommentRow {
#[local_ref] #[local_ref]
voting_row -> gtk::Box {}, voting_row -> gtk::Box {},
if settings::get_current_account().jwt.is_some() {
gtk::Button { gtk::Button {
set_icon_name: "mail-replied", set_icon_name: "mail-replied",
connect_clicked => CommentRowMsg::OpenEditor(true), connect_clicked => CommentRowMsg::OpenEditor(true),
} #[watch]
} else { set_visible: settings::get_current_account().jwt.is_some(),
gtk::Box {}
}, },
if self.comment.creator.id.0 == settings::get_current_account().id {
gtk::Button { gtk::Button {
set_icon_name: "document-edit", set_icon_name: "document-edit",
connect_clicked => CommentRowMsg::OpenEditor(false), connect_clicked => CommentRowMsg::OpenEditor(false),
} set_visible: self.comment.creator.id.0 == settings::get_current_account().id,
} else {
gtk::Box {}
}, },
if self.comment.creator.id.0 == settings::get_current_account().id {
gtk::Button { gtk::Button {
set_icon_name: "edit-delete", set_icon_name: "edit-delete",
connect_clicked => CommentRowMsg::DeleteComment, connect_clicked => CommentRowMsg::DeleteComment,
set_visible: self.comment.creator.id.0 == settings::get_current_account().id,
} }
} else {
gtk::Box {}
},
}, },
gtk::Separator {} gtk::Separator {}

View File

@ -83,11 +83,12 @@ impl SimpleComponent for CommunityPage {
}, },
}, },
if settings::get_current_account().jwt.is_some() {
gtk::Box { gtk::Box {
set_orientation: gtk::Orientation::Horizontal, set_orientation: gtk::Orientation::Horizontal,
set_halign: gtk::Align::Center, set_halign: gtk::Align::Center,
set_margin_top: 10, set_margin_top: 10,
#[watch]
set_visible: settings::get_current_account().jwt.is_some(),
match model.info.subscribed { match model.info.subscribed {
SubscribedType::Subscribed => { SubscribedType::Subscribed => {
@ -113,9 +114,6 @@ impl SimpleComponent for CommunityPage {
set_margin_start: 10, set_margin_start: 10,
connect_clicked => CommunityInput::OpenCreatePostDialog, connect_clicked => CommunityInput::OpenCreatePostDialog,
} }
}
} else {
gtk::Box {}
}, },
gtk::Separator { gtk::Separator {

View File

@ -43,14 +43,10 @@ impl FactoryComponent for CommunityRow {
set_orientation: gtk::Orientation::Horizontal, set_orientation: gtk::Orientation::Horizontal,
set_spacing: 10, set_spacing: 10,
if self.community.community.icon.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
community_image -> gtk::Box {} community_image -> gtk::Box {
} set_visible: self.community.community.icon.is_some(),
} else { set_hexpand: false,
gtk::Box {}
}, },
gtk::Label { gtk::Label {

View File

@ -59,18 +59,13 @@ impl FactoryComponent for MentionRow {
gtk::Label { gtk::Label {
set_label: "in", set_label: "in",
}, },
if self.comment.community.icon.clone().is_some() { #[local_ref]
gtk::Box { community_image -> gtk::Box {
set_hexpand: false, set_hexpand: false,
set_margin_start: 10, set_margin_start: 10,
set_margin_end: 10, set_margin_end: 10,
#[local_ref] set_visible: self.comment.community.icon.clone().is_some(),
community_image -> gtk::Box {}
}
} else {
gtk::Box {}
}, },
gtk::Button { gtk::Button {
set_label: &self.comment.community.title, set_label: &self.comment.community.title,
connect_clicked => MentionRowMsg::OpenCommunity, connect_clicked => MentionRowMsg::OpenCommunity,
@ -83,14 +78,10 @@ impl FactoryComponent for MentionRow {
set_margin_top: 10, set_margin_top: 10,
set_vexpand: false, set_vexpand: false,
if self.comment.creator.avatar.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
creator_image -> gtk::Box {} creator_image -> gtk::Box {
} set_hexpand: false,
} else { set_visible: self.comment.creator.avatar.is_some(),
gtk::Box {}
}, },
gtk::Button { gtk::Button {

View File

@ -43,17 +43,11 @@ impl FactoryComponent for ModeratesRow {
set_orientation: gtk::Orientation::Horizontal, set_orientation: gtk::Orientation::Horizontal,
set_spacing: 10, set_spacing: 10,
if self.community.community.icon.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
community_image -> gtk::Box { community_image -> gtk::Box {
set_height_request: 35, set_size_request: (35, 35),
set_width_request: 35, set_hexpand: false,
} set_visible: self.community.community.icon.is_some(),
}
} else {
gtk::Box {}
}, },
gtk::Label { gtk::Label {

View File

@ -64,6 +64,8 @@ impl SimpleComponent for PostPage {
set_height_request: 400, set_height_request: 400,
set_margin_bottom: 20, set_margin_bottom: 20,
set_margin_top: 20, set_margin_top: 20,
#[watch]
set_visible: model.info.post_view.post.thumbnail_url.is_some(),
}, },
gtk::Label { gtk::Label {
#[watch] #[watch]
@ -88,15 +90,11 @@ impl SimpleComponent for PostPage {
set_text: "posted by" set_text: "posted by"
}, },
if model.info.post_view.creator.avatar.is_some() { #[local_ref]
gtk::Box { creator_avatar -> gtk::Box {
set_hexpand: false, set_hexpand: false,
set_margin_start: 10, set_margin_start: 10,
#[local_ref] set_visible: model.info.post_view.creator.avatar.is_some(),
creator_avatar -> gtk::Box {}
}
} else {
gtk::Box {}
}, },
gtk::Button { gtk::Button {
@ -109,14 +107,10 @@ impl SimpleComponent for PostPage {
set_text: " in " set_text: " in "
}, },
if model.info.community_view.community.icon.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
community_avatar -> gtk::Box {} community_avatar -> gtk::Box {
} set_hexpand: false,
} else { set_visible: model.info.community_view.community.icon.is_some(),
gtk::Box {}
}, },
gtk::Button { gtk::Button {
@ -139,24 +133,20 @@ impl SimpleComponent for PostPage {
connect_clicked => PostPageInput::OpenLink, connect_clicked => PostPageInput::OpenLink,
}, },
if model.info.post_view.creator.id.0 == settings::get_current_account().id {
gtk::Button { gtk::Button {
set_icon_name: "document-edit", set_icon_name: "document-edit",
connect_clicked => PostPageInput::OpenEditPostDialog, connect_clicked => PostPageInput::OpenEditPostDialog,
set_margin_start: 5, set_margin_start: 5,
} #[watch]
} else { set_visible: model.info.post_view.creator.id.0 == settings::get_current_account().id,
gtk::Box {}
}, },
if model.info.post_view.creator.id.0 == settings::get_current_account().id {
gtk::Button { gtk::Button {
set_icon_name: "edit-delete", set_icon_name: "edit-delete",
connect_clicked => PostPageInput::DeletePost, connect_clicked => PostPageInput::DeletePost,
set_margin_start: 5, set_margin_start: 5,
} #[watch]
} else { set_visible: model.info.post_view.creator.id.0 == settings::get_current_account().id,
gtk::Box {}
} }
}, },
@ -174,14 +164,12 @@ impl SimpleComponent for PostPage {
#[watch] #[watch]
set_text: &format!("{} comments", model.info.post_view.counts.comments), set_text: &format!("{} comments", model.info.post_view.counts.comments),
}, },
if settings::get_current_account().jwt.is_some() {
gtk::Button { gtk::Button {
set_label: "Comment", set_label: "Comment",
set_margin_start: 10, set_margin_start: 10,
connect_clicked => PostPageInput::OpenCreateCommentDialog, connect_clicked => PostPageInput::OpenCreateCommentDialog,
} #[watch]
} else { set_visible: settings::get_current_account().jwt.is_some(),
gtk::Box {}
} }
}, },
@ -208,7 +196,9 @@ impl SimpleComponent for PostPage {
.transient_for(root) .transient_for(root)
.launch(EditorType::Comment) .launch(EditorType::Comment)
.forward(sender.input_sender(), |msg| match msg { .forward(sender.input_sender(), |msg| match msg {
EditorOutput::CreateRequest(comment, _) => PostPageInput::CreateCommentRequest(comment), EditorOutput::CreateRequest(comment, _) => {
PostPageInput::CreateCommentRequest(comment)
}
EditorOutput::EditRequest(post, _) => PostPageInput::EditPostRequest(post), EditorOutput::EditRequest(post, _) => PostPageInput::EditPostRequest(post),
}); });
let voting_row = VotingRowModel::builder() let voting_row = VotingRowModel::builder()
@ -340,7 +330,7 @@ impl SimpleComponent for PostPage {
.body .body
.clone() .clone()
.unwrap_or(String::from("")), .unwrap_or(String::from("")),
url: reqwest::Url::parse(&url).ok() url: reqwest::Url::parse(&url).ok(),
}; };
let sender = self.create_comment_dialog.sender(); let sender = self.create_comment_dialog.sender();
sender.emit(DialogMsg::UpdateData(data)); sender.emit(DialogMsg::UpdateData(data));

View File

@ -47,14 +47,10 @@ impl FactoryComponent for PostRow {
set_vexpand: false, set_vexpand: false,
set_hexpand: true, set_hexpand: true,
if self.post.community.icon.clone().is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
community_image -> gtk::Box {} community_image -> gtk::Box {
} set_hexpand: false,
} else { set_visible: self.post.community.icon.clone().is_some(),
gtk::Box {}
}, },
gtk::Button { gtk::Button {
@ -62,15 +58,11 @@ impl FactoryComponent for PostRow {
connect_clicked => PostRowMsg::OpenCommunity, connect_clicked => PostRowMsg::OpenCommunity,
}, },
if self.post.creator.avatar.clone().is_some() { #[local_ref]
gtk::Box { author_image -> gtk::Box {
set_hexpand: false, set_hexpand: false,
set_margin_start: 10, set_margin_start: 10,
#[local_ref] set_visible: self.post.creator.avatar.clone().is_some(),
author_image -> gtk::Box {}
}
} else {
gtk::Box {}
}, },
gtk::Button { gtk::Button {
@ -105,14 +97,12 @@ impl FactoryComponent for PostRow {
set_halign: gtk::Align::Start, set_halign: gtk::Align::Start,
set_text: &format!("{} comments", self.post.counts.comments.clone()), set_text: &format!("{} comments", self.post.counts.comments.clone()),
}, },
if self.post.creator.id.0 == settings::get_current_account().id {
gtk::Button { gtk::Button {
set_icon_name: "edit-delete", set_icon_name: "edit-delete",
connect_clicked => PostRowMsg::DeletePost, connect_clicked => PostRowMsg::DeletePost,
set_margin_start: 10, set_margin_start: 10,
} #[watch]
} else { set_visible: self.post.creator.id.0 == settings::get_current_account().id,
gtk::Box {}
} }
}, },

View File

@ -40,14 +40,10 @@ impl FactoryComponent for PrivateMessageRow {
set_vexpand: false, set_vexpand: false,
set_hexpand: true, set_hexpand: true,
if self.message.creator.avatar.is_some() {
gtk::Box {
set_hexpand: false,
#[local_ref] #[local_ref]
creator_image -> gtk::Box {} creator_image -> gtk::Box {
} set_hexpand: false,
} else { set_visible: self.message.creator.avatar.is_some(),
gtk::Box {}
}, },
gtk::Button { gtk::Button {

View File

@ -49,9 +49,11 @@ impl SimpleComponent for ProfilePage {
#[local_ref] #[local_ref]
avatar -> gtk::Box { avatar -> gtk::Box {
set_size_request: (100, 100), set_size_request: (150, 150),
set_margin_bottom: 20, set_margin_bottom: 20,
set_margin_top: 20, set_margin_top: 20,
#[watch]
set_visible: model.info.person_view.person.avatar.is_some(),
}, },
gtk::Label { gtk::Label {
#[watch] #[watch]
@ -75,15 +77,12 @@ impl SimpleComponent for ProfilePage {
#[watch] #[watch]
set_text: &format!("{} posts, {} comments", model.info.person_view.counts.post_count, model.info.person_view.counts.comment_count), set_text: &format!("{} posts, {} comments", model.info.person_view.counts.post_count, model.info.person_view.counts.comment_count),
}, },
if settings::get_current_account().jwt.is_some() {
gtk::Button { gtk::Button {
set_label: "Send message", set_label: "Send message",
connect_clicked => ProfileInput::SendMessageRequest, connect_clicked => ProfileInput::SendMessageRequest,
set_margin_start: 10, set_margin_start: 10,
set_visible: settings::get_current_account().jwt.is_some(),
} }
} else {
gtk::Box {}
},
}, },
gtk::Separator {}, gtk::Separator {},