Filter out empty projects in contacts panel

This commit is contained in:
Nathan Sobo 2022-05-09 20:57:41 -06:00
parent ef868ff023
commit 4e9924c717
2 changed files with 126 additions and 113 deletions

View file

@ -501,6 +501,12 @@ impl Contact {
}
Ok(Self { user, projects })
}
pub fn non_empty_projects(&self) -> impl Iterator<Item = &ProjectMetadata> {
self.projects
.iter()
.filter(|project| !project.worktree_root_names.is_empty())
}
}
async fn fetch_avatar(http: &dyn HttpClient, url: &str) -> Result<Arc<ImageData>> {

View file

@ -149,7 +149,7 @@ impl ContactsPanel {
theme: &theme::ContactsPanel,
cx: &mut LayoutContext,
) -> ElementBox {
let project_count = contact.projects.len();
let project_count = contact.non_empty_projects().count();
let font_cache = cx.font_cache();
let line_height = theme.unshared_project.name.text.line_height(font_cache);
let cap_height = theme.unshared_project.name.text.cap_height(font_cache);
@ -188,17 +188,21 @@ impl ContactsPanel {
.with_height(theme.row_height)
.boxed(),
)
.with_children(contact.projects.iter().enumerate().map(|(ix, project)| {
.with_children(
contact
.non_empty_projects()
.enumerate()
.map(|(ix, project)| {
let project_id = project.id;
Flex::row()
.with_child(
Canvas::new(move |bounds, _, cx| {
let start_x =
bounds.min_x() + (bounds.width() / 2.) - (tree_branch_width / 2.);
let start_x = bounds.min_x() + (bounds.width() / 2.)
- (tree_branch_width / 2.);
let end_x = bounds.max_x();
let start_y = bounds.min_y();
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
let end_y =
bounds.min_y() + baseline_offset - (cap_height / 2.);
cx.scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
@ -271,7 +275,9 @@ impl ContactsPanel {
.aligned()
.left()
.contained()
.with_margin_right(style.guest_avatar_spacing)
.with_margin_right(
style.guest_avatar_spacing,
)
.boxed()
})
},
@ -302,7 +308,8 @@ impl ContactsPanel {
.constrained()
.with_height(theme.unshared_project.height)
.boxed()
}))
}),
)
.boxed()
}