feat(channels): Teams list header with filter and new items like Teams
- search button opens "Filter by channel name" (team or channel name), Unread pill - new items menu with New channel for the open team - "..." gets Collapse all sections Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -0,0 +1,119 @@
1
use store::SidebarTeam;
2
3
pub const CHANNEL_FILTER_PLACEHOLDER: &str = "Filter by channel name";
4
pub const UNREAD_PILL: &str = "Unread";
5
6
#[derive(Debug, Clone, Default, PartialEq, Eq)]
7
pub struct ChannelFilter {
8
pub text: String,
9
pub unread_only: bool,
10
}
11
12
impl ChannelFilter {
13
pub fn is_active(&self) -> bool {
14
self.unread_only || !self.text.trim().is_empty()
15
}
16
17
pub fn apply(&self, teams: &[SidebarTeam]) -> Vec<SidebarTeam> {
18
let needle = self.text.trim().to_lowercase();
19
teams
20
.iter()
21
.filter_map(|entry| {
22
let team_matches = needle.is_empty() || entry.team.name.to_lowercase().contains(&needle);
23
let channels: Vec<_> = entry
24
.channels
25
.iter()
26
.filter(|channel| team_matches || channel.name.to_lowercase().contains(&needle))
27
.filter(|channel| !self.unread_only || channel.unread)
28
.cloned()
29
.collect();
30
(!channels.is_empty()).then(|| SidebarTeam {
31
channels,
32
hidden: false,
33
hidden_channel_ids: Vec::new(),
34
..entry.clone()
35
})
36
})
37
.collect()
38
}
39
}
40
41
#[cfg(test)]
42
mod tests {
43
use std::collections::HashMap;
44
45
use store::{ChannelRecord, TeamRecord, TeamRights};
46
47
use super::*;
48
49
fn channel(id: &str, name: &str, unread: bool) -> ChannelRecord {
50
ChannelRecord {
51
id: id.to_owned(),
52
team_id: "t".to_owned(),
53
name: name.to_owned(),
54
membership_type: None,
55
last_message_at: None,
56
unread,
57
}
58
}
59
60
fn team(name: &str, channels: Vec<ChannelRecord>) -> SidebarTeam {
61
SidebarTeam {
62
team: TeamRecord {
63
id: name.to_owned(),
64
name: name.to_owned(),
65
},
66
channels,
67
hidden: true,
68
rights: TeamRights::default(),
69
hidden_channel_ids: vec!["c2".to_owned()],
70
notifications: HashMap::new(),
71
mentions: HashMap::new(),
72
}
73
}
74
75
fn names(teams: &[SidebarTeam]) -> Vec<(String, Vec<String>)> {
76
teams
77
.iter()
78
.map(|entry| {
79
let channels = entry.channels.iter().map(|channel| channel.name.clone()).collect();
80
(entry.team.name.clone(), channels)
81
})
82
.collect()
83
}
84
85
#[test]
86
fn text_matches_channel_names_or_the_whole_team() {
87
let teams = vec![
88
team("Platform", vec![channel("c1", "General", false), channel("c2", "Releases", true)]),
89
team("Release crew", vec![channel("c3", "General", false)]),
90
];
91
let filter = ChannelFilter {
92
text: " release".to_owned(),
93
unread_only: false,
94
};
95
let filtered = filter.apply(&teams);
96
assert_eq!(
97
names(&filtered),
98
[
99
("Platform".to_owned(), vec!["Releases".to_owned()]),
100
("Release crew".to_owned(), vec!["General".to_owned()]),
101
]
102
);
103
assert!(filtered.iter().all(|entry| !entry.hidden && entry.hidden_channel_ids.is_empty()));
104
}
105
106
#[test]
107
fn unread_keeps_only_unread_channels() {
108
let teams = vec![
109
team("Platform", vec![channel("c1", "General", false), channel("c2", "Releases", true)]),
110
team("Quiet", vec![channel("c3", "General", false)]),
111
];
112
let filter = ChannelFilter {
113
text: String::new(),
114
unread_only: true,
115
};
116
assert_eq!(names(&filter.apply(&teams)), [("Platform".to_owned(), vec!["Releases".to_owned()])]);
117
assert!(!ChannelFilter::default().is_active());
118
}
119
}
@@ -0,0 +1,119 @@1
use store::SidebarTeam;2
3
pub const CHANNEL_FILTER_PLACEHOLDER: &str = "Filter by channel name";4
pub const UNREAD_PILL: &str = "Unread";5
6
#[derive(Debug, Clone, Default, PartialEq, Eq)]7
pub struct ChannelFilter {8
pub text: String,9
pub unread_only: bool,10
}11
12
impl ChannelFilter {13
pub fn is_active(&self) -> bool {14
self.unread_only || !self.text.trim().is_empty()15
}16
17
pub fn apply(&self, teams: &[SidebarTeam]) -> Vec<SidebarTeam> {18
let needle = self.text.trim().to_lowercase();19
teams20
.iter()21
.filter_map(|entry| {22
let team_matches = needle.is_empty() || entry.team.name.to_lowercase().contains(&needle);23
let channels: Vec<_> = entry24
.channels25
.iter()26
.filter(|channel| team_matches || channel.name.to_lowercase().contains(&needle))27
.filter(|channel| !self.unread_only || channel.unread)28
.cloned()29
.collect();30
(!channels.is_empty()).then(|| SidebarTeam {31
channels,32
hidden: false,33
hidden_channel_ids: Vec::new(),34
..entry.clone()35
})36
})37
.collect()38
}39
}40
41
#[cfg(test)]42
mod tests {43
use std::collections::HashMap;44
45
use store::{ChannelRecord, TeamRecord, TeamRights};46
47
use super::*;48
49
fn channel(id: &str, name: &str, unread: bool) -> ChannelRecord {50
ChannelRecord {51
id: id.to_owned(),52
team_id: "t".to_owned(),53
name: name.to_owned(),54
membership_type: None,55
last_message_at: None,56
unread,57
}58
}59
60
fn team(name: &str, channels: Vec<ChannelRecord>) -> SidebarTeam {61
SidebarTeam {62
team: TeamRecord {63
id: name.to_owned(),64
name: name.to_owned(),65
},66
channels,67
hidden: true,68
rights: TeamRights::default(),69
hidden_channel_ids: vec!["c2".to_owned()],70
notifications: HashMap::new(),71
mentions: HashMap::new(),72
}73
}74
75
fn names(teams: &[SidebarTeam]) -> Vec<(String, Vec<String>)> {76
teams77
.iter()78
.map(|entry| {79
let channels = entry.channels.iter().map(|channel| channel.name.clone()).collect();80
(entry.team.name.clone(), channels)81
})82
.collect()83
}84
85
#[test]86
fn text_matches_channel_names_or_the_whole_team() {87
let teams = vec![88
team("Platform", vec![channel("c1", "General", false), channel("c2", "Releases", true)]),89
team("Release crew", vec![channel("c3", "General", false)]),90
];91
let filter = ChannelFilter {92
text: " release".to_owned(),93
unread_only: false,94
};95
let filtered = filter.apply(&teams);96
assert_eq!(97
names(&filtered),98
[99
("Platform".to_owned(), vec!["Releases".to_owned()]),100
("Release crew".to_owned(), vec!["General".to_owned()]),101
]102
);103
assert!(filtered.iter().all(|entry| !entry.hidden && entry.hidden_channel_ids.is_empty()));104
}105
106
#[test]107
fn unread_keeps_only_unread_channels() {108
let teams = vec![109
team("Platform", vec![channel("c1", "General", false), channel("c2", "Releases", true)]),110
team("Quiet", vec![channel("c3", "General", false)]),111
];112
let filter = ChannelFilter {113
text: String::new(),114
unread_only: true,115
};116
assert_eq!(names(&filter.apply(&teams)), [("Platform".to_owned(), vec!["Releases".to_owned()])]);117
assert!(!ChannelFilter::default().is_active());118
}119
}@@ -12,6 +12,7 @@ pub mod card_refresh;
12
12
pub mod card_state;
13
13
pub mod channel_menu;
14
14
pub mod chat_actions;
15
pub mod channel_filter;
15
16
pub mod chat_filter;
16
17
pub mod find_in_chat;
17
18
pub mod forward_selection;
@@ -12,6 +12,7 @@ pub mod card_refresh;12
pub mod card_state;12
pub mod card_state;13
pub mod channel_menu;13
pub mod channel_menu;14
pub mod chat_actions;14
pub mod chat_actions;15
pub mod channel_filter;15
pub mod chat_filter;16
pub mod chat_filter;16
pub mod find_in_chat;17
pub mod find_in_chat;17
pub mod forward_selection;18
pub mod forward_selection;@@ -48,6 +48,7 @@ use crate::theme;
48
48
use app_ui_kit::layout::SIDEBAR_WIDTH;
49
49
use gpui_kit::component::input::InputState;
50
50
51
pub(crate) mod channel_filter_bar;
51
52
pub(crate) mod chat_filter_bar;
52
53
53
54
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";
@@ -352,6 +353,10 @@ pub struct SidebarView {
352
353
channels_scroll: ScrollHandle,
353
354
chat_filter: ChatFilter,
354
355
filter_box_open: bool,
356
channel_filter: crate::channel_filter::ChannelFilter,
357
channel_filter_open: bool,
358
channel_filter_input: Option<Entity<InputState>>,
359
channel_filter_subscription: Option<Subscription>,
355
360
more_filters_open: bool,
356
361
filter_input: Option<Entity<InputState>>,
357
362
filter_subscription: Option<Subscription>,
@@ -473,6 +478,10 @@ impl SidebarView {
473
478
channels_scroll: ScrollHandle::new(),
474
479
chat_filter: ChatFilter::default(),
475
480
filter_box_open: false,
481
channel_filter: Default::default(),
482
channel_filter_open: false,
483
channel_filter_input: None,
484
channel_filter_subscription: None,
476
485
more_filters_open: false,
477
486
filter_input: None,
478
487
filter_subscription: None,
@@ -696,6 +705,15 @@ impl SidebarView {
696
705
fn channel_list_menu_button(&self, cx: &mut Context<Self>) -> impl IntoElement {
697
706
let state = self.state.clone();
698
707
let read_only = self.state.read(cx).mode.read_only;
708
let view = cx.entity().downgrade();
709
let team_ids: Vec<String> = self
710
.state
711
.read(cx)
712
.sidebar
713
.teams
714
.iter()
715
.map(|entry| entry.team.id.clone())
716
.collect();
699
717
Button::new("channel-list-more")
700
718
.icon(IconName::Ellipsis)
701
719
.ghost()
@@ -703,7 +721,7 @@ impl SidebarView {
703
721
.rounded(px(8.))
704
722
.tooltip("More options")
705
723
.dropdown_menu(move |menu, _, _| {
706
let state = state.clone();
724
let (state, view, team_ids) = (state.clone(), view.clone(), team_ids.clone());
707
725
menu.item(
708
726
PopupMenuItem::new(MARK_ALL_READ_LABEL)
709
727
.icon(menu_icon(IconName::CheckCheck))
@@ -712,6 +730,15 @@ impl SidebarView {
712
730
state.update(cx, |state, cx| state.mark_all_channels_read(cx));
713
731
}),
714
732
)
733
.item(
734
PopupMenuItem::new(COLLAPSE_ALL_LABEL)
735
.icon(menu_icon(IconName::ChevronsDownUp))
736
.on_click(move |_, _, cx| {
737
let team_ids = team_ids.clone();
738
view.update(cx, |this, cx| this.collapse_all_teams(team_ids, cx))
739
.ok();
740
}),
741
)
715
742
})
716
743
}
717
744
@@ -1444,7 +1471,8 @@ impl SidebarView {
1444
1471
cx: &mut Context<Self>,
1445
1472
) -> Div {
1446
1473
let team_id = entry.team.id.clone();
1447
let expanded = team_expanded(&team_id, &self.collapsed_teams);
1474
let expanded =
1475
self.channel_filter.is_active() || team_expanded(&team_id, &self.collapsed_teams);
1448
1476
let name_style = team_name_style(entry, expanded);
1449
1477
let badge = team_badge(entry, expanded);
1450
1478
let toggle_id = team_id.clone();
@@ -1687,6 +1715,12 @@ impl SidebarView {
1687
1715
})
1688
1716
}
1689
1717
1718
fn collapse_all_teams(&mut self, team_ids: Vec<String>, cx: &mut Context<Self>) {
1719
self.collapsed_teams.extend(team_ids);
1720
save_collapsed_teams(&self.state.read(cx).store, &self.collapsed_teams);
1721
cx.notify();
1722
}
1723
1690
1724
fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {
1691
1725
let (sidebar, pinned_ids, selected, team_photos) = {
1692
1726
let state = self.state.read(cx);
@@ -1706,6 +1740,14 @@ impl SidebarView {
1706
1740
team_photos,
1707
1741
)
1708
1742
};
1743
let filtering = self.channel_filter.is_active();
1744
let mut sidebar = sidebar;
1745
let pinned_ids = if filtering {
1746
sidebar.teams = self.channel_filter.apply(&sidebar.teams);
1747
Vec::new()
1748
} else {
1749
pinned_ids
1750
};
1709
1751
let team_keys = sidebar
1710
1752
.teams
1711
1753
.iter()
@@ -2097,9 +2139,17 @@ impl Render for SidebarView {
2097
2139
)
2098
2140
.child(self.filter_bar(cx)),
2099
2141
),
2100
SidebarTab::Channels => {
2101
Some(page_header(self.tab.title()).child(self.channel_list_menu_button(cx)))
2102
}
2142
SidebarTab::Channels => Some(
2143
v_flex()
2144
.flex_none()
2145
.child(
2146
page_header(self.tab.title())
2147
.child(self.channel_list_menu_button(cx))
2148
.child(self.channel_filter_button(cx))
2149
.child(self.new_channel_items_button(cx)),
2150
)
2151
.child(self.channel_filter_bar(cx)),
2152
),
2103
2153
SidebarTab::Agents => Some(page_header(self.tab.title())),
2104
2154
SidebarTab::Activity | SidebarTab::Calls | SidebarTab::Calendar => None,
2105
2155
};
@@ -48,6 +48,7 @@ use crate::theme;48
use app_ui_kit::layout::SIDEBAR_WIDTH;48
use app_ui_kit::layout::SIDEBAR_WIDTH;49
use gpui_kit::component::input::InputState;49
use gpui_kit::component::input::InputState;50
50
51
pub(crate) mod channel_filter_bar;51
pub(crate) mod chat_filter_bar;52
pub(crate) mod chat_filter_bar;52
53
53
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";54
pub const SIDEBAR_SCROLL_DIVIDER: &str = "shell/islands/sidebar/divider-scroll";@@ -352,6 +353,10 @@ pub struct SidebarView {352
channels_scroll: ScrollHandle,353
channels_scroll: ScrollHandle,353
chat_filter: ChatFilter,354
chat_filter: ChatFilter,354
filter_box_open: bool,355
filter_box_open: bool,356
channel_filter: crate::channel_filter::ChannelFilter,357
channel_filter_open: bool,358
channel_filter_input: Option<Entity<InputState>>,359
channel_filter_subscription: Option<Subscription>,355
more_filters_open: bool,360
more_filters_open: bool,356
filter_input: Option<Entity<InputState>>,361
filter_input: Option<Entity<InputState>>,357
filter_subscription: Option<Subscription>,362
filter_subscription: Option<Subscription>,@@ -473,6 +478,10 @@ impl SidebarView {473
channels_scroll: ScrollHandle::new(),478
channels_scroll: ScrollHandle::new(),474
chat_filter: ChatFilter::default(),479
chat_filter: ChatFilter::default(),475
filter_box_open: false,480
filter_box_open: false,481
channel_filter: Default::default(),482
channel_filter_open: false,483
channel_filter_input: None,484
channel_filter_subscription: None,476
more_filters_open: false,485
more_filters_open: false,477
filter_input: None,486
filter_input: None,478
filter_subscription: None,487
filter_subscription: None,@@ -696,6 +705,15 @@ impl SidebarView {696
fn channel_list_menu_button(&self, cx: &mut Context<Self>) -> impl IntoElement {705
fn channel_list_menu_button(&self, cx: &mut Context<Self>) -> impl IntoElement {697
let state = self.state.clone();706
let state = self.state.clone();698
let read_only = self.state.read(cx).mode.read_only;707
let read_only = self.state.read(cx).mode.read_only;708
let view = cx.entity().downgrade();709
let team_ids: Vec<String> = self710
.state711
.read(cx)712
.sidebar713
.teams714
.iter()715
.map(|entry| entry.team.id.clone())716
.collect();699
Button::new("channel-list-more")717
Button::new("channel-list-more")700
.icon(IconName::Ellipsis)718
.icon(IconName::Ellipsis)701
.ghost()719
.ghost()@@ -703,7 +721,7 @@ impl SidebarView {703
.rounded(px(8.))721
.rounded(px(8.))704
.tooltip("More options")722
.tooltip("More options")705
.dropdown_menu(move |menu, _, _| {723
.dropdown_menu(move |menu, _, _| {706
let state = state.clone();724
let (state, view, team_ids) = (state.clone(), view.clone(), team_ids.clone());707
menu.item(725
menu.item(708
PopupMenuItem::new(MARK_ALL_READ_LABEL)726
PopupMenuItem::new(MARK_ALL_READ_LABEL)709
.icon(menu_icon(IconName::CheckCheck))727
.icon(menu_icon(IconName::CheckCheck))@@ -712,6 +730,15 @@ impl SidebarView {712
state.update(cx, |state, cx| state.mark_all_channels_read(cx));730
state.update(cx, |state, cx| state.mark_all_channels_read(cx));713
}),731
}),714
)732
)733
.item(734
PopupMenuItem::new(COLLAPSE_ALL_LABEL)735
.icon(menu_icon(IconName::ChevronsDownUp))736
.on_click(move |_, _, cx| {737
let team_ids = team_ids.clone();738
view.update(cx, |this, cx| this.collapse_all_teams(team_ids, cx))739
.ok();740
}),741
)715
})742
})716
}743
}717
744
@@ -1444,7 +1471,8 @@ impl SidebarView {1444
cx: &mut Context<Self>,1471
cx: &mut Context<Self>,1445
) -> Div {1472
) -> Div {1446
let team_id = entry.team.id.clone();1473
let team_id = entry.team.id.clone();1447
let expanded = team_expanded(&team_id, &self.collapsed_teams);1474
let expanded =1475
self.channel_filter.is_active() || team_expanded(&team_id, &self.collapsed_teams);1448
let name_style = team_name_style(entry, expanded);1476
let name_style = team_name_style(entry, expanded);1449
let badge = team_badge(entry, expanded);1477
let badge = team_badge(entry, expanded);1450
let toggle_id = team_id.clone();1478
let toggle_id = team_id.clone();@@ -1687,6 +1715,12 @@ impl SidebarView {1687
})1715
})1688
}1716
}1689
1717
1718
fn collapse_all_teams(&mut self, team_ids: Vec<String>, cx: &mut Context<Self>) {1719
self.collapsed_teams.extend(team_ids);1720
save_collapsed_teams(&self.state.read(cx).store, &self.collapsed_teams);1721
cx.notify();1722
}1723
1690
fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {1724
fn channels_body(&self, cx: &mut Context<Self>) -> AnyElement {1691
let (sidebar, pinned_ids, selected, team_photos) = {1725
let (sidebar, pinned_ids, selected, team_photos) = {1692
let state = self.state.read(cx);1726
let state = self.state.read(cx);@@ -1706,6 +1740,14 @@ impl SidebarView {1706
team_photos,1740
team_photos,1707
)1741
)1708
};1742
};1743
let filtering = self.channel_filter.is_active();1744
let mut sidebar = sidebar;1745
let pinned_ids = if filtering {1746
sidebar.teams = self.channel_filter.apply(&sidebar.teams);1747
Vec::new()1748
} else {1749
pinned_ids1750
};1709
let team_keys = sidebar1751
let team_keys = sidebar1710
.teams1752
.teams1711
.iter()1753
.iter()@@ -2097,9 +2139,17 @@ impl Render for SidebarView {2097
)2139
)2098
.child(self.filter_bar(cx)),2140
.child(self.filter_bar(cx)),2099
),2141
),2100
SidebarTab::Channels => {2142
SidebarTab::Channels => Some(2101
Some(page_header(self.tab.title()).child(self.channel_list_menu_button(cx)))2143
v_flex()2102
}2144
.flex_none()2145
.child(2146
page_header(self.tab.title())2147
.child(self.channel_list_menu_button(cx))2148
.child(self.channel_filter_button(cx))2149
.child(self.new_channel_items_button(cx)),2150
)2151
.child(self.channel_filter_bar(cx)),2152
),2103
SidebarTab::Agents => Some(page_header(self.tab.title())),2153
SidebarTab::Agents => Some(page_header(self.tab.title())),2104
SidebarTab::Activity | SidebarTab::Calls | SidebarTab::Calendar => None,2154
SidebarTab::Activity | SidebarTab::Calls | SidebarTab::Calendar => None,2105
};2155
};@@ -0,0 +1,182 @@
1
use gpui_kit::assets::IconName;
2
use gpui_kit::component::button::{Button, ButtonVariants as _};
3
use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};
4
use gpui_kit::component::menu::{DropdownMenu as _, PopupMenuItem};
5
use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};
6
use gpui_kit::prelude::FluentBuilder as _;
7
use gpui_kit::*;
8
9
use super::{NEW_CHAT_BUTTON_SIZE, SidebarEvent, SidebarView};
10
use crate::app_state::Selection;
11
use crate::channel_filter::{CHANNEL_FILTER_PLACEHOLDER, UNREAD_PILL};
12
use crate::chat_filter::{CLOSE_FILTER_TEXT, SHOW_FILTER_TEXT};
13
use crate::theme;
14
use crate::views::create_channel_dialog::open_create_channel_dialog;
15
use crate::views::widgets::{icon, menu_icon};
16
17
pub const CHANNEL_FILTER_TAG: &str = "shell/islands/sidebar/channel-filter";
18
const NEW_CHANNEL_LABEL: &str = "New channel";
19
const INPUT_HEIGHT: f32 = 32.;
20
const PILL_HEIGHT: f32 = 24.;
21
const SIDE_INSET: f32 = 16.;
22
23
impl SidebarView {
24
fn toggle_channel_filter(&mut self, window: &mut Window, cx: &mut Context<Self>) {
25
if self.channel_filter_open {
26
self.close_channel_filter(window, cx);
27
return;
28
}
29
self.channel_filter_open = true;
30
let input = self.channel_filter_input(window, cx);
31
input.update(cx, |input, cx| input.focus(window, cx));
32
cx.notify();
33
}
34
35
fn close_channel_filter(&mut self, window: &mut Window, cx: &mut Context<Self>) {
36
self.channel_filter_open = false;
37
self.channel_filter.text.clear();
38
if let Some(input) = &self.channel_filter_input {
39
input.update(cx, |input, cx| input.set_value("", window, cx));
40
}
41
cx.emit(SidebarEvent::RestoreFocus);
42
cx.notify();
43
}
44
45
fn channel_filter_input(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Entity<InputState> {
46
if let Some(input) = &self.channel_filter_input {
47
return input.clone();
48
}
49
let input = cx.new(|cx| InputState::new(window, cx).placeholder(CHANNEL_FILTER_PLACEHOLDER));
50
let subscription = cx.subscribe_in(&input, window, |this, input, event, _, cx| {
51
if matches!(event, InputEvent::Change) {
52
this.channel_filter.text = input.read(cx).value().to_string();
53
cx.notify();
54
}
55
});
56
self.channel_filter_subscription = Some(subscription);
57
self.channel_filter_input = Some(input.clone());
58
input
59
}
60
61
pub(super) fn channel_filter_button(&self, cx: &mut Context<Self>) -> impl IntoElement {
62
let open = self.channel_filter_open;
63
let label = if open { CLOSE_FILTER_TEXT } else { SHOW_FILTER_TEXT };
64
div()
65
.id("channel-filter-toggle")
66
.size(px(NEW_CHAT_BUTTON_SIZE))
67
.flex_none()
68
.flex()
69
.items_center()
70
.justify_center()
71
.rounded(px(8.))
72
.cursor_pointer()
73
.when(open, |button| button.bg(theme::popup_hover()))
74
.hover(|button| button.bg(theme::popup_hover()))
75
.tooltip(move |window, cx| Tooltip::new(label).build(window, cx))
76
.child(icon(
77
IconName::Search,
78
16.,
79
if open { theme::accent_text() } else { theme::text_soft() },
80
))
81
.on_click(cx.listener(|this, _, window, cx| this.toggle_channel_filter(window, cx)))
82
}
83
84
pub(super) fn new_channel_items_button(&self, cx: &mut Context<Self>) -> impl IntoElement {
85
let state = self.state.clone();
86
let app = self.state.read(cx);
87
let team_id = match &app.selection {
88
Some(Selection::Channel(channel_id)) => app
89
.sidebar
90
.teams
91
.iter()
92
.find(|entry| entry.channels.iter().any(|channel| &channel.id == channel_id))
93
.filter(|entry| entry.rights.add_channel && !app.mode.read_only)
94
.map(|entry| entry.team.id.clone()),
95
_ => None,
96
};
97
Button::new("channel-list-new")
98
.icon(IconName::Pencil)
99
.ghost()
100
.size(px(NEW_CHAT_BUTTON_SIZE))
101
.rounded(px(8.))
102
.tooltip("New items")
103
.dropdown_menu(move |menu, _, _| {
104
let (state, team_id) = (state.clone(), team_id.clone());
105
menu.item(
106
PopupMenuItem::new(NEW_CHANNEL_LABEL)
107
.icon(menu_icon(IconName::Hash))
108
.disabled(team_id.is_none())
109
.on_click(move |_, window, cx| {
110
if let Some(team_id) = &team_id {
111
open_create_channel_dialog(state.clone(), team_id, window, cx);
112
}
113
}),
114
)
115
})
116
}
117
118
pub(super) fn channel_filter_bar(&self, cx: &mut Context<Self>) -> impl IntoElement {
119
let input_row = self
120
.channel_filter_input
121
.clone()
122
.filter(|_| self.channel_filter_open)
123
.map(|input| self.channel_filter_input_row(&input, cx));
124
let selected = self.channel_filter.unread_only;
125
v_flex()
126
.debug_selector(|| CHANNEL_FILTER_TAG.into())
127
.flex_none()
128
.w_full()
129
.pb(px(8.))
130
.gap(px(8.))
131
.children(input_row)
132
.child(
133
h_flex().px(px(SIDE_INSET)).child(
134
div()
135
.id("channel-filter-unread")
136
.h(px(PILL_HEIGHT))
137
.px(px(12.))
138
.flex()
139
.flex_none()
140
.items_center()
141
.rounded_full()
142
.text_size(px(12.))
143
.cursor_pointer()
144
.when(selected, |chip| chip.bg(theme::accent()).text_color(theme::on_accent()))
145
.when(!selected, |chip| {
146
chip.bg(theme::surface_raised())
147
.text_color(theme::text_soft())
148
.hover(|chip| chip.bg(theme::border_strong()))
149
})
150
.child(UNREAD_PILL)
151
.on_click(cx.listener(|this, _, _, cx| {
152
this.channel_filter.unread_only = !this.channel_filter.unread_only;
153
cx.notify();
154
})),
155
),
156
)
157
}
158
159
fn channel_filter_input_row(&self, input: &Entity<InputState>, cx: &mut Context<Self>) -> Div {
160
h_flex()
161
.mx(px(SIDE_INSET))
162
.h(px(INPUT_HEIGHT))
163
.flex_none()
164
.pl(px(10.))
165
.pr(px(4.))
166
.gap(px(8.))
167
.items_center()
168
.rounded(px(6.))
169
.bg(theme::surface_raised())
170
.capture_action(cx.listener(|this, _: &Escape, window, cx| {
171
this.close_channel_filter(window, cx);
172
cx.stop_propagation();
173
}))
174
.child(icon(IconName::Search, 14., theme::text_muted()))
175
.child(
176
div()
177
.flex_1()
178
.min_w_0()
179
.child(Input::new(input).appearance(false).bordered(false)),
180
)
181
}
182
}
@@ -0,0 +1,182 @@1
use gpui_kit::assets::IconName;2
use gpui_kit::component::button::{Button, ButtonVariants as _};3
use gpui_kit::component::input::{Escape, Input, InputEvent, InputState};4
use gpui_kit::component::menu::{DropdownMenu as _, PopupMenuItem};5
use gpui_kit::component::{h_flex, tooltip::Tooltip, v_flex};6
use gpui_kit::prelude::FluentBuilder as _;7
use gpui_kit::*;8
9
use super::{NEW_CHAT_BUTTON_SIZE, SidebarEvent, SidebarView};10
use crate::app_state::Selection;11
use crate::channel_filter::{CHANNEL_FILTER_PLACEHOLDER, UNREAD_PILL};12
use crate::chat_filter::{CLOSE_FILTER_TEXT, SHOW_FILTER_TEXT};13
use crate::theme;14
use crate::views::create_channel_dialog::open_create_channel_dialog;15
use crate::views::widgets::{icon, menu_icon};16
17
pub const CHANNEL_FILTER_TAG: &str = "shell/islands/sidebar/channel-filter";18
const NEW_CHANNEL_LABEL: &str = "New channel";19
const INPUT_HEIGHT: f32 = 32.;20
const PILL_HEIGHT: f32 = 24.;21
const SIDE_INSET: f32 = 16.;22
23
impl SidebarView {24
fn toggle_channel_filter(&mut self, window: &mut Window, cx: &mut Context<Self>) {25
if self.channel_filter_open {26
self.close_channel_filter(window, cx);27
return;28
}29
self.channel_filter_open = true;30
let input = self.channel_filter_input(window, cx);31
input.update(cx, |input, cx| input.focus(window, cx));32
cx.notify();33
}34
35
fn close_channel_filter(&mut self, window: &mut Window, cx: &mut Context<Self>) {36
self.channel_filter_open = false;37
self.channel_filter.text.clear();38
if let Some(input) = &self.channel_filter_input {39
input.update(cx, |input, cx| input.set_value("", window, cx));40
}41
cx.emit(SidebarEvent::RestoreFocus);42
cx.notify();43
}44
45
fn channel_filter_input(&mut self, window: &mut Window, cx: &mut Context<Self>) -> Entity<InputState> {46
if let Some(input) = &self.channel_filter_input {47
return input.clone();48
}49
let input = cx.new(|cx| InputState::new(window, cx).placeholder(CHANNEL_FILTER_PLACEHOLDER));50
let subscription = cx.subscribe_in(&input, window, |this, input, event, _, cx| {51
if matches!(event, InputEvent::Change) {52
this.channel_filter.text = input.read(cx).value().to_string();53
cx.notify();54
}55
});56
self.channel_filter_subscription = Some(subscription);57
self.channel_filter_input = Some(input.clone());58
input59
}60
61
pub(super) fn channel_filter_button(&self, cx: &mut Context<Self>) -> impl IntoElement {62
let open = self.channel_filter_open;63
let label = if open { CLOSE_FILTER_TEXT } else { SHOW_FILTER_TEXT };64
div()65
.id("channel-filter-toggle")66
.size(px(NEW_CHAT_BUTTON_SIZE))67
.flex_none()68
.flex()69
.items_center()70
.justify_center()71
.rounded(px(8.))72
.cursor_pointer()73
.when(open, |button| button.bg(theme::popup_hover()))74
.hover(|button| button.bg(theme::popup_hover()))75
.tooltip(move |window, cx| Tooltip::new(label).build(window, cx))76
.child(icon(77
IconName::Search,78
16.,79
if open { theme::accent_text() } else { theme::text_soft() },80
))81
.on_click(cx.listener(|this, _, window, cx| this.toggle_channel_filter(window, cx)))82
}83
84
pub(super) fn new_channel_items_button(&self, cx: &mut Context<Self>) -> impl IntoElement {85
let state = self.state.clone();86
let app = self.state.read(cx);87
let team_id = match &app.selection {88
Some(Selection::Channel(channel_id)) => app89
.sidebar90
.teams91
.iter()92
.find(|entry| entry.channels.iter().any(|channel| &channel.id == channel_id))93
.filter(|entry| entry.rights.add_channel && !app.mode.read_only)94
.map(|entry| entry.team.id.clone()),95
_ => None,96
};97
Button::new("channel-list-new")98
.icon(IconName::Pencil)99
.ghost()100
.size(px(NEW_CHAT_BUTTON_SIZE))101
.rounded(px(8.))102
.tooltip("New items")103
.dropdown_menu(move |menu, _, _| {104
let (state, team_id) = (state.clone(), team_id.clone());105
menu.item(106
PopupMenuItem::new(NEW_CHANNEL_LABEL)107
.icon(menu_icon(IconName::Hash))108
.disabled(team_id.is_none())109
.on_click(move |_, window, cx| {110
if let Some(team_id) = &team_id {111
open_create_channel_dialog(state.clone(), team_id, window, cx);112
}113
}),114
)115
})116
}117
118
pub(super) fn channel_filter_bar(&self, cx: &mut Context<Self>) -> impl IntoElement {119
let input_row = self120
.channel_filter_input121
.clone()122
.filter(|_| self.channel_filter_open)123
.map(|input| self.channel_filter_input_row(&input, cx));124
let selected = self.channel_filter.unread_only;125
v_flex()126
.debug_selector(|| CHANNEL_FILTER_TAG.into())127
.flex_none()128
.w_full()129
.pb(px(8.))130
.gap(px(8.))131
.children(input_row)132
.child(133
h_flex().px(px(SIDE_INSET)).child(134
div()135
.id("channel-filter-unread")136
.h(px(PILL_HEIGHT))137
.px(px(12.))138
.flex()139
.flex_none()140
.items_center()141
.rounded_full()142
.text_size(px(12.))143
.cursor_pointer()144
.when(selected, |chip| chip.bg(theme::accent()).text_color(theme::on_accent()))145
.when(!selected, |chip| {146
chip.bg(theme::surface_raised())147
.text_color(theme::text_soft())148
.hover(|chip| chip.bg(theme::border_strong()))149
})150
.child(UNREAD_PILL)151
.on_click(cx.listener(|this, _, _, cx| {152
this.channel_filter.unread_only = !this.channel_filter.unread_only;153
cx.notify();154
})),155
),156
)157
}158
159
fn channel_filter_input_row(&self, input: &Entity<InputState>, cx: &mut Context<Self>) -> Div {160
h_flex()161
.mx(px(SIDE_INSET))162
.h(px(INPUT_HEIGHT))163
.flex_none()164
.pl(px(10.))165
.pr(px(4.))166
.gap(px(8.))167
.items_center()168
.rounded(px(6.))169
.bg(theme::surface_raised())170
.capture_action(cx.listener(|this, _: &Escape, window, cx| {171
this.close_channel_filter(window, cx);172
cx.stop_propagation();173
}))174
.child(icon(IconName::Search, 14., theme::text_muted()))175
.child(176
div()177
.flex_1()178
.min_w_0()179
.child(Input::new(input).appearance(false).bordered(false)),180
)181
}182
}