This commit is contained in:
2026-09-24 08:39:02 +07:00
parent c61be4a139
commit 610bf816b0
3 changed files with 30 additions and 58 deletions
+18 -45
View File
@@ -344,6 +344,14 @@ impl Sidebar {
), ),
), ),
}) })
.child(
div()
.px_4()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_placeholder)
.child(active_tab.list_title()),
)
.child( .child(
div() div()
.min_h_0() .min_h_0()
@@ -510,44 +518,21 @@ impl Sidebar {
match tab { match tab {
SidebarTab::Inbox => { SidebarTab::Inbox => {
let chat = ChatRegistry::global(cx); let chat = ChatRegistry::global(cx);
let rooms = chat.read(cx).rooms(&RoomKind::Ongoing, cx); chat.read(cx)
.rooms(&RoomKind::Ongoing, cx)
let mut rows = vec![SidebarRow::Section { .into_iter()
label: "Chats".into(), .map(|room| SidebarRow::Room { room })
}]; .collect()
if rooms.is_empty() {
rows.push(SidebarRow::Hint {
text: "No conversations yet".into(),
});
} else {
rows.extend(rooms.into_iter().map(|room| SidebarRow::Room { room }));
}
rows
} }
SidebarTab::Communities => { SidebarTab::Communities => {
let registry = CommunityRegistry::global(cx); let registry = CommunityRegistry::global(cx);
let communities = registry.read(cx).communities(); registry
.read(cx)
let mut rows = vec![SidebarRow::Section { .communities()
label: "Communities".into(),
}];
if communities.is_empty() {
rows.push(SidebarRow::Hint {
text: "No communities yet".into(),
});
} else {
rows.extend(
communities
.iter() .iter()
.cloned() .cloned()
.map(|community| SidebarRow::Community { community }), .map(|community| SidebarRow::Community { community })
); .collect()
}
rows
} }
} }
} }
@@ -566,12 +551,6 @@ impl Sidebar {
let index = range.start + offset; let index = range.start + offset;
match row { match row {
SidebarRow::Section { label } => TreeRow::new(
ElementId::NamedInteger("tree-row".into(), index as u64),
TreeRowKind::Section,
label.clone(),
)
.into_any_element(),
SidebarRow::Room { room } => { SidebarRow::Room { room } => {
let name = room.read(cx).display_name(cx); let name = room.read(cx).display_name(cx);
let picture = room.read(cx).display_image(cx); let picture = room.read(cx).display_image(cx);
@@ -634,12 +613,6 @@ impl Sidebar {
}) })
.into_any_element() .into_any_element()
} }
SidebarRow::Hint { text } => TreeRow::new(
ElementId::NamedInteger("tree-row".into(), index as u64),
TreeRowKind::Hint,
text.clone(),
)
.into_any_element(),
} }
}) })
.collect() .collect()
+8
View File
@@ -14,6 +14,14 @@ impl SidebarTab {
} }
} }
/// Heading for the tab's list of items.
pub fn list_title(self) -> &'static str {
match self {
Self::Inbox => "Direct Messages",
Self::Communities => "Communities",
}
}
pub fn list_id(self) -> &'static str { pub fn list_id(self) -> &'static str {
match self { match self {
Self::Inbox => "sidebar-inbox", Self::Inbox => "sidebar-inbox",
+2 -11
View File
@@ -14,10 +14,8 @@ use ui::avatar::{Avatar, PixelAvatar};
use ui::{Icon, IconName, Selectable, Sizable, StyledExt, h_flex}; use ui::{Icon, IconName, Selectable, Sizable, StyledExt, h_flex};
pub enum SidebarRow { pub enum SidebarRow {
Section { label: SharedString },
Room { room: Entity<Room> }, Room { room: Entity<Room> },
Community { community: Entity<Community> }, Community { community: Entity<Community> },
Hint { text: SharedString },
} }
/// A collapsible group of rows in the sidebar's community view. /// A collapsible group of rows in the sidebar's community view.
@@ -48,7 +46,6 @@ pub enum TreeRowKind {
Section, Section,
Room, Room,
Community, Community,
Hint,
} }
#[derive(IntoElement)] #[derive(IntoElement)]
@@ -134,7 +131,6 @@ impl RenderOnce for TreeRow {
let is_section = self.kind == TreeRowKind::Section; let is_section = self.kind == TreeRowKind::Section;
let is_room = self.kind == TreeRowKind::Room; let is_room = self.kind == TreeRowKind::Room;
let is_community = self.kind == TreeRowKind::Community; let is_community = self.kind == TreeRowKind::Community;
let is_hint = self.kind == TreeRowKind::Hint;
let is_selected = self.selected; let is_selected = self.selected;
let avatar = if hide_avatar { let avatar = if hide_avatar {
@@ -173,6 +169,7 @@ impl RenderOnce for TreeRow {
h_flex() h_flex()
.id(self.id) .id(self.id)
.w_full() .w_full()
.h_10()
.px_2() .px_2()
.gap_2() .gap_2()
.rounded(cx.theme().radius) .rounded(cx.theme().radius)
@@ -181,13 +178,7 @@ impl RenderOnce for TreeRow {
.text_color(cx.theme().text_placeholder) .text_color(cx.theme().text_placeholder)
.font_semibold() .font_semibold()
}) })
.when(is_room || is_community, |this| this.text_sm().h_10()) .when(is_room || is_community, |this| this.text_sm())
.h_8()
.when(is_hint, |this| {
this.text_xs()
.font_normal()
.text_color(cx.theme().text_placeholder)
})
.when_some(avatar, |this, avatar| this.child(avatar)) .when_some(avatar, |this, avatar| this.child(avatar))
.child( .child(
h_flex() h_flex()