mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-27 02:48:34 +00:00
Filter out empty projects in contacts panel
This commit is contained in:
parent
ef868ff023
commit
4e9924c717
2 changed files with 126 additions and 113 deletions
|
@ -501,6 +501,12 @@ impl Contact {
|
||||||
}
|
}
|
||||||
Ok(Self { user, projects })
|
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>> {
|
async fn fetch_avatar(http: &dyn HttpClient, url: &str) -> Result<Arc<ImageData>> {
|
||||||
|
|
|
@ -149,7 +149,7 @@ impl ContactsPanel {
|
||||||
theme: &theme::ContactsPanel,
|
theme: &theme::ContactsPanel,
|
||||||
cx: &mut LayoutContext,
|
cx: &mut LayoutContext,
|
||||||
) -> ElementBox {
|
) -> ElementBox {
|
||||||
let project_count = contact.projects.len();
|
let project_count = contact.non_empty_projects().count();
|
||||||
let font_cache = cx.font_cache();
|
let font_cache = cx.font_cache();
|
||||||
let line_height = theme.unshared_project.name.text.line_height(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);
|
let cap_height = theme.unshared_project.name.text.cap_height(font_cache);
|
||||||
|
@ -188,121 +188,128 @@ impl ContactsPanel {
|
||||||
.with_height(theme.row_height)
|
.with_height(theme.row_height)
|
||||||
.boxed(),
|
.boxed(),
|
||||||
)
|
)
|
||||||
.with_children(contact.projects.iter().enumerate().map(|(ix, project)| {
|
.with_children(
|
||||||
let project_id = project.id;
|
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 end_x = bounds.max_x();
|
||||||
|
let start_y = bounds.min_y();
|
||||||
|
let end_y =
|
||||||
|
bounds.min_y() + baseline_offset - (cap_height / 2.);
|
||||||
|
|
||||||
Flex::row()
|
cx.scene.push_quad(gpui::Quad {
|
||||||
.with_child(
|
bounds: RectF::from_points(
|
||||||
Canvas::new(move |bounds, _, cx| {
|
vec2f(start_x, start_y),
|
||||||
let start_x =
|
vec2f(
|
||||||
bounds.min_x() + (bounds.width() / 2.) - (tree_branch_width / 2.);
|
start_x + tree_branch_width,
|
||||||
let end_x = bounds.max_x();
|
if ix + 1 == project_count {
|
||||||
let start_y = bounds.min_y();
|
end_y
|
||||||
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
|
} else {
|
||||||
|
bounds.max_y()
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
background: Some(tree_branch_color),
|
||||||
|
border: gpui::Border::default(),
|
||||||
|
corner_radius: 0.,
|
||||||
|
});
|
||||||
|
cx.scene.push_quad(gpui::Quad {
|
||||||
|
bounds: RectF::from_points(
|
||||||
|
vec2f(start_x, end_y),
|
||||||
|
vec2f(end_x, end_y + tree_branch_width),
|
||||||
|
),
|
||||||
|
background: Some(tree_branch_color),
|
||||||
|
border: gpui::Border::default(),
|
||||||
|
corner_radius: 0.,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.constrained()
|
||||||
|
.with_width(host_avatar_height)
|
||||||
|
.boxed(),
|
||||||
|
)
|
||||||
|
.with_child({
|
||||||
|
let is_host = Some(contact.user.id) == current_user_id;
|
||||||
|
let is_guest = !is_host
|
||||||
|
&& project
|
||||||
|
.guests
|
||||||
|
.iter()
|
||||||
|
.any(|guest| Some(guest.id) == current_user_id);
|
||||||
|
let is_shared = project.is_shared;
|
||||||
|
let app_state = app_state.clone();
|
||||||
|
|
||||||
cx.scene.push_quad(gpui::Quad {
|
MouseEventHandler::new::<ContactsPanel, _, _>(
|
||||||
bounds: RectF::from_points(
|
project_id as usize,
|
||||||
vec2f(start_x, start_y),
|
cx,
|
||||||
vec2f(
|
|mouse_state, _| {
|
||||||
start_x + tree_branch_width,
|
let style = match (project.is_shared, mouse_state.hovered) {
|
||||||
if ix + 1 == project_count {
|
(false, false) => &theme.unshared_project,
|
||||||
end_y
|
(false, true) => &theme.hovered_unshared_project,
|
||||||
} else {
|
(true, false) => &theme.shared_project,
|
||||||
bounds.max_y()
|
(true, true) => &theme.hovered_shared_project,
|
||||||
},
|
};
|
||||||
),
|
|
||||||
),
|
|
||||||
background: Some(tree_branch_color),
|
|
||||||
border: gpui::Border::default(),
|
|
||||||
corner_radius: 0.,
|
|
||||||
});
|
|
||||||
cx.scene.push_quad(gpui::Quad {
|
|
||||||
bounds: RectF::from_points(
|
|
||||||
vec2f(start_x, end_y),
|
|
||||||
vec2f(end_x, end_y + tree_branch_width),
|
|
||||||
),
|
|
||||||
background: Some(tree_branch_color),
|
|
||||||
border: gpui::Border::default(),
|
|
||||||
corner_radius: 0.,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.constrained()
|
|
||||||
.with_width(host_avatar_height)
|
|
||||||
.boxed(),
|
|
||||||
)
|
|
||||||
.with_child({
|
|
||||||
let is_host = Some(contact.user.id) == current_user_id;
|
|
||||||
let is_guest = !is_host
|
|
||||||
&& project
|
|
||||||
.guests
|
|
||||||
.iter()
|
|
||||||
.any(|guest| Some(guest.id) == current_user_id);
|
|
||||||
let is_shared = project.is_shared;
|
|
||||||
let app_state = app_state.clone();
|
|
||||||
|
|
||||||
MouseEventHandler::new::<ContactsPanel, _, _>(
|
Flex::row()
|
||||||
project_id as usize,
|
.with_child(
|
||||||
cx,
|
Label::new(
|
||||||
|mouse_state, _| {
|
project.worktree_root_names.join(", "),
|
||||||
let style = match (project.is_shared, mouse_state.hovered) {
|
style.name.text.clone(),
|
||||||
(false, false) => &theme.unshared_project,
|
)
|
||||||
(false, true) => &theme.hovered_unshared_project,
|
.aligned()
|
||||||
(true, false) => &theme.shared_project,
|
.left()
|
||||||
(true, true) => &theme.hovered_shared_project,
|
.contained()
|
||||||
};
|
.with_style(style.name.container)
|
||||||
|
.boxed(),
|
||||||
Flex::row()
|
)
|
||||||
.with_child(
|
.with_children(project.guests.iter().filter_map(
|
||||||
Label::new(
|
|participant| {
|
||||||
project.worktree_root_names.join(", "),
|
participant.avatar.clone().map(|avatar| {
|
||||||
style.name.text.clone(),
|
Image::new(avatar)
|
||||||
)
|
.with_style(style.guest_avatar)
|
||||||
.aligned()
|
.aligned()
|
||||||
.left()
|
.left()
|
||||||
.contained()
|
.contained()
|
||||||
.with_style(style.name.container)
|
.with_margin_right(
|
||||||
.boxed(),
|
style.guest_avatar_spacing,
|
||||||
)
|
)
|
||||||
.with_children(project.guests.iter().filter_map(
|
.boxed()
|
||||||
|participant| {
|
})
|
||||||
participant.avatar.clone().map(|avatar| {
|
},
|
||||||
Image::new(avatar)
|
))
|
||||||
.with_style(style.guest_avatar)
|
.contained()
|
||||||
.aligned()
|
.with_style(style.container)
|
||||||
.left()
|
.constrained()
|
||||||
.contained()
|
.with_height(style.height)
|
||||||
.with_margin_right(style.guest_avatar_spacing)
|
.boxed()
|
||||||
.boxed()
|
},
|
||||||
})
|
)
|
||||||
},
|
.with_cursor_style(if is_host || is_shared {
|
||||||
))
|
CursorStyle::PointingHand
|
||||||
.contained()
|
} else {
|
||||||
.with_style(style.container)
|
CursorStyle::Arrow
|
||||||
.constrained()
|
})
|
||||||
.with_height(style.height)
|
.on_click(move |_, cx| {
|
||||||
.boxed()
|
if !is_host && !is_guest {
|
||||||
},
|
cx.dispatch_global_action(JoinProject {
|
||||||
)
|
project_id,
|
||||||
.with_cursor_style(if is_host || is_shared {
|
app_state: app_state.clone(),
|
||||||
CursorStyle::PointingHand
|
});
|
||||||
} else {
|
}
|
||||||
CursorStyle::Arrow
|
})
|
||||||
})
|
.flex(1., true)
|
||||||
.on_click(move |_, cx| {
|
.boxed()
|
||||||
if !is_host && !is_guest {
|
})
|
||||||
cx.dispatch_global_action(JoinProject {
|
.constrained()
|
||||||
project_id,
|
.with_height(theme.unshared_project.height)
|
||||||
app_state: app_state.clone(),
|
.boxed()
|
||||||
});
|
}),
|
||||||
}
|
)
|
||||||
})
|
|
||||||
.flex(1., true)
|
|
||||||
.boxed()
|
|
||||||
})
|
|
||||||
.constrained()
|
|
||||||
.with_height(theme.unshared_project.height)
|
|
||||||
.boxed()
|
|
||||||
}))
|
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue