Replace unneeded if else expressions with set_visible
This commit is contained in:
parent
5e353c27cb
commit
e51da627ea
|
@ -56,14 +56,10 @@ impl FactoryComponent for CommentRow {
|
|||
set_spacing: 10,
|
||||
set_vexpand: false,
|
||||
|
||||
if self.comment.creator.avatar.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
community_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_visible: self.comment.creator.avatar.is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
@ -91,32 +87,24 @@ impl FactoryComponent for CommentRow {
|
|||
#[local_ref]
|
||||
voting_row -> gtk::Box {},
|
||||
|
||||
if settings::get_current_account().jwt.is_some() {
|
||||
gtk::Button {
|
||||
set_icon_name: "mail-replied",
|
||||
connect_clicked => CommentRowMsg::OpenEditor(true),
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
#[watch]
|
||||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
},
|
||||
|
||||
if self.comment.creator.id.0 == settings::get_current_account().id {
|
||||
gtk::Button {
|
||||
set_icon_name: "document-edit",
|
||||
connect_clicked => CommentRowMsg::OpenEditor(false),
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
set_visible: self.comment.creator.id.0 == settings::get_current_account().id,
|
||||
},
|
||||
|
||||
if self.comment.creator.id.0 == settings::get_current_account().id {
|
||||
gtk::Button {
|
||||
set_icon_name: "edit-delete",
|
||||
connect_clicked => CommentRowMsg::DeleteComment,
|
||||
set_visible: self.comment.creator.id.0 == settings::get_current_account().id,
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
},
|
||||
},
|
||||
|
||||
gtk::Separator {}
|
||||
|
|
|
@ -83,11 +83,12 @@ impl SimpleComponent for CommunityPage {
|
|||
},
|
||||
},
|
||||
|
||||
if settings::get_current_account().jwt.is_some() {
|
||||
gtk::Box {
|
||||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_halign: gtk::Align::Center,
|
||||
set_margin_top: 10,
|
||||
#[watch]
|
||||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
|
||||
match model.info.subscribed {
|
||||
SubscribedType::Subscribed => {
|
||||
|
@ -113,9 +114,6 @@ impl SimpleComponent for CommunityPage {
|
|||
set_margin_start: 10,
|
||||
connect_clicked => CommunityInput::OpenCreatePostDialog,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
},
|
||||
|
||||
gtk::Separator {
|
||||
|
|
|
@ -43,14 +43,10 @@ impl FactoryComponent for CommunityRow {
|
|||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
|
||||
if self.community.community.icon.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
community_image -> gtk::Box {
|
||||
set_visible: self.community.community.icon.is_some(),
|
||||
set_hexpand: false,
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
|
|
|
@ -59,18 +59,13 @@ impl FactoryComponent for MentionRow {
|
|||
gtk::Label {
|
||||
set_label: "in",
|
||||
},
|
||||
if self.comment.community.icon.clone().is_some() {
|
||||
gtk::Box {
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_margin_start: 10,
|
||||
set_margin_end: 10,
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
set_visible: self.comment.community.icon.clone().is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
set_label: &self.comment.community.title,
|
||||
connect_clicked => MentionRowMsg::OpenCommunity,
|
||||
|
@ -83,14 +78,10 @@ impl FactoryComponent for MentionRow {
|
|||
set_margin_top: 10,
|
||||
set_vexpand: false,
|
||||
|
||||
if self.comment.creator.avatar.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
creator_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
creator_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_visible: self.comment.creator.avatar.is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
|
|
@ -43,17 +43,11 @@ impl FactoryComponent for ModeratesRow {
|
|||
set_orientation: gtk::Orientation::Horizontal,
|
||||
set_spacing: 10,
|
||||
|
||||
if self.community.community.icon.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {
|
||||
set_height_request: 35,
|
||||
set_width_request: 35,
|
||||
}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
set_size_request: (35, 35),
|
||||
set_hexpand: false,
|
||||
set_visible: self.community.community.icon.is_some(),
|
||||
},
|
||||
|
||||
gtk::Label {
|
||||
|
|
|
@ -64,6 +64,8 @@ impl SimpleComponent for PostPage {
|
|||
set_height_request: 400,
|
||||
set_margin_bottom: 20,
|
||||
set_margin_top: 20,
|
||||
#[watch]
|
||||
set_visible: model.info.post_view.post.thumbnail_url.is_some(),
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
|
@ -88,15 +90,11 @@ impl SimpleComponent for PostPage {
|
|||
set_text: "posted by"
|
||||
},
|
||||
|
||||
if model.info.post_view.creator.avatar.is_some() {
|
||||
gtk::Box {
|
||||
#[local_ref]
|
||||
creator_avatar -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_margin_start: 10,
|
||||
#[local_ref]
|
||||
creator_avatar -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
set_visible: model.info.post_view.creator.avatar.is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
@ -109,14 +107,10 @@ impl SimpleComponent for PostPage {
|
|||
set_text: " in "
|
||||
},
|
||||
|
||||
if model.info.community_view.community.icon.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
community_avatar -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
community_avatar -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_visible: model.info.community_view.community.icon.is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
@ -139,24 +133,20 @@ impl SimpleComponent for PostPage {
|
|||
connect_clicked => PostPageInput::OpenLink,
|
||||
},
|
||||
|
||||
if model.info.post_view.creator.id.0 == settings::get_current_account().id {
|
||||
gtk::Button {
|
||||
set_icon_name: "document-edit",
|
||||
connect_clicked => PostPageInput::OpenEditPostDialog,
|
||||
set_margin_start: 5,
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
#[watch]
|
||||
set_visible: model.info.post_view.creator.id.0 == settings::get_current_account().id,
|
||||
},
|
||||
|
||||
if model.info.post_view.creator.id.0 == settings::get_current_account().id {
|
||||
gtk::Button {
|
||||
set_icon_name: "edit-delete",
|
||||
connect_clicked => PostPageInput::DeletePost,
|
||||
set_margin_start: 5,
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
#[watch]
|
||||
set_visible: model.info.post_view.creator.id.0 == settings::get_current_account().id,
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -174,14 +164,12 @@ impl SimpleComponent for PostPage {
|
|||
#[watch]
|
||||
set_text: &format!("{} comments", model.info.post_view.counts.comments),
|
||||
},
|
||||
if settings::get_current_account().jwt.is_some() {
|
||||
gtk::Button {
|
||||
set_label: "Comment",
|
||||
set_margin_start: 10,
|
||||
connect_clicked => PostPageInput::OpenCreateCommentDialog,
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
#[watch]
|
||||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -208,7 +196,9 @@ impl SimpleComponent for PostPage {
|
|||
.transient_for(root)
|
||||
.launch(EditorType::Comment)
|
||||
.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),
|
||||
});
|
||||
let voting_row = VotingRowModel::builder()
|
||||
|
@ -340,7 +330,7 @@ impl SimpleComponent for PostPage {
|
|||
.body
|
||||
.clone()
|
||||
.unwrap_or(String::from("")),
|
||||
url: reqwest::Url::parse(&url).ok()
|
||||
url: reqwest::Url::parse(&url).ok(),
|
||||
};
|
||||
let sender = self.create_comment_dialog.sender();
|
||||
sender.emit(DialogMsg::UpdateData(data));
|
||||
|
|
|
@ -47,14 +47,10 @@ impl FactoryComponent for PostRow {
|
|||
set_vexpand: false,
|
||||
set_hexpand: true,
|
||||
|
||||
if self.post.community.icon.clone().is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
community_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
community_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_visible: self.post.community.icon.clone().is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
@ -62,15 +58,11 @@ impl FactoryComponent for PostRow {
|
|||
connect_clicked => PostRowMsg::OpenCommunity,
|
||||
},
|
||||
|
||||
if self.post.creator.avatar.clone().is_some() {
|
||||
gtk::Box {
|
||||
#[local_ref]
|
||||
author_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_margin_start: 10,
|
||||
#[local_ref]
|
||||
author_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
set_visible: self.post.creator.avatar.clone().is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
@ -105,14 +97,12 @@ impl FactoryComponent for PostRow {
|
|||
set_halign: gtk::Align::Start,
|
||||
set_text: &format!("{} comments", self.post.counts.comments.clone()),
|
||||
},
|
||||
if self.post.creator.id.0 == settings::get_current_account().id {
|
||||
gtk::Button {
|
||||
set_icon_name: "edit-delete",
|
||||
connect_clicked => PostRowMsg::DeletePost,
|
||||
set_margin_start: 10,
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
#[watch]
|
||||
set_visible: self.post.creator.id.0 == settings::get_current_account().id,
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -40,14 +40,10 @@ impl FactoryComponent for PrivateMessageRow {
|
|||
set_vexpand: false,
|
||||
set_hexpand: true,
|
||||
|
||||
if self.message.creator.avatar.is_some() {
|
||||
gtk::Box {
|
||||
set_hexpand: false,
|
||||
#[local_ref]
|
||||
creator_image -> gtk::Box {}
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
creator_image -> gtk::Box {
|
||||
set_hexpand: false,
|
||||
set_visible: self.message.creator.avatar.is_some(),
|
||||
},
|
||||
|
||||
gtk::Button {
|
||||
|
|
|
@ -49,9 +49,11 @@ impl SimpleComponent for ProfilePage {
|
|||
|
||||
#[local_ref]
|
||||
avatar -> gtk::Box {
|
||||
set_size_request: (100, 100),
|
||||
set_size_request: (150, 150),
|
||||
set_margin_bottom: 20,
|
||||
set_margin_top: 20,
|
||||
#[watch]
|
||||
set_visible: model.info.person_view.person.avatar.is_some(),
|
||||
},
|
||||
gtk::Label {
|
||||
#[watch]
|
||||
|
@ -75,15 +77,12 @@ impl SimpleComponent for ProfilePage {
|
|||
#[watch]
|
||||
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 {
|
||||
set_label: "Send message",
|
||||
connect_clicked => ProfileInput::SendMessageRequest,
|
||||
set_margin_start: 10,
|
||||
set_visible: settings::get_current_account().jwt.is_some(),
|
||||
}
|
||||
} else {
|
||||
gtk::Box {}
|
||||
},
|
||||
},
|
||||
|
||||
gtk::Separator {},
|
||||
|
|
Loading…
Reference in New Issue