From a0f8a2342f575a88cc006ef64259dd425a41dc2b Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 26 Jan 2024 12:25:00 -0700 Subject: [PATCH] Add a hover menu to see who's in a channel Co-Authored-By: Max Inspired-By: @RemcoSmitsDev --- crates/collab_ui/src/collab_panel.rs | 47 ++++++++++++++++++++++++---- crates/ui/src/components/tooltip.rs | 2 +- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/crates/collab_ui/src/collab_panel.rs b/crates/collab_ui/src/collab_panel.rs index d92ea06ea0..ac7ac8cabc 100644 --- a/crates/collab_ui/src/collab_panel.rs +++ b/crates/collab_ui/src/collab_panel.rs @@ -33,8 +33,8 @@ use smallvec::SmallVec; use std::{mem, sync::Arc}; use theme::{ActiveTheme, ThemeSettings}; use ui::{ - prelude::*, Avatar, AvatarAvailabilityIndicator, Button, Color, ContextMenu, Icon, IconButton, - IconName, IconSize, Label, ListHeader, ListItem, Tooltip, + prelude::*, tooltip_container, Avatar, AvatarAvailabilityIndicator, Button, Color, ContextMenu, + Icon, IconButton, IconName, IconSize, Label, ListHeader, ListItem, Tooltip, }; use util::{maybe, ResultExt, TryFutureExt}; use workspace::{ @@ -367,9 +367,11 @@ impl CollabPanel { if !self.collapsed_sections.contains(&Section::ActiveCall) { let room = room.read(cx); - if let Some(channel_id) = room.channel_id() { - self.entries.push(ListEntry::ChannelNotes { channel_id }); - self.entries.push(ListEntry::ChannelChat { channel_id }); + if query.is_empty() { + if let Some(channel_id) = room.channel_id() { + self.entries.push(ListEntry::ChannelNotes { channel_id }); + self.entries.push(ListEntry::ChannelChat { channel_id }); + } } // Populate the active user. @@ -2539,7 +2541,16 @@ impl CollabPanel { ), ), ) - .tooltip(|cx| Tooltip::text("Join channel", cx)) + .tooltip({ + let channel_store = self.channel_store.clone(); + move |cx| { + cx.new_view(|_| JoinChannelTooltip { + channel_store: channel_store.clone(), + channel_id, + }) + .into() + } + }) } fn render_channel_editor(&self, depth: usize, _cx: &mut ViewContext) -> impl IntoElement { @@ -2817,3 +2828,27 @@ impl Render for DraggedChannelView { .child(Label::new(self.channel.name.clone())) } } + +struct JoinChannelTooltip { + channel_store: Model, + channel_id: ChannelId, +} + +impl Render for JoinChannelTooltip { + fn render(&mut self, cx: &mut ViewContext) -> impl IntoElement { + tooltip_container(cx, |div, cx| { + let participants = self + .channel_store + .read(cx) + .channel_participants(self.channel_id); + + div.child(Label::new("Join Channel")) + .children(participants.iter().map(|participant| { + h_flex() + .gap_2() + .child(Avatar::new(participant.avatar_uri.clone())) + .child(Label::new(participant.github_login.clone())) + })) + }) + } +} diff --git a/crates/ui/src/components/tooltip.rs b/crates/ui/src/components/tooltip.rs index 6db1804740..d31afd1ed2 100644 --- a/crates/ui/src/components/tooltip.rs +++ b/crates/ui/src/components/tooltip.rs @@ -85,7 +85,7 @@ impl Render for Tooltip { } } -fn tooltip_container( +pub fn tooltip_container( cx: &mut ViewContext, f: impl FnOnce(Div, &mut ViewContext) -> Div, ) -> impl IntoElement {