Add an empty state to the notification panel

This commit is contained in:
Max Brunsfeld 2023-10-16 12:54:44 -07:00
parent 522b76e452
commit c66385f0f9
2 changed files with 22 additions and 3 deletions

View file

@ -299,6 +299,19 @@ impl NotificationPanel {
.into_any() .into_any()
} }
fn render_empty_state(
&self,
theme: &Arc<Theme>,
_cx: &mut ViewContext<Self>,
) -> AnyElement<Self> {
Label::new(
"You have no notifications".to_string(),
theme.chat_panel.sign_in_prompt.default.clone(),
)
.aligned()
.into_any()
}
fn on_notification_event( fn on_notification_event(
&mut self, &mut self,
_: ModelHandle<NotificationStore>, _: ModelHandle<NotificationStore>,
@ -373,13 +386,15 @@ impl View for NotificationPanel {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = theme::current(cx); let theme = theme::current(cx);
let element = if self.client.user_id().is_some() { let element = if self.client.user_id().is_none() {
self.render_sign_in_prompt(&theme, cx)
} else if self.notification_list.item_count() == 0 {
self.render_empty_state(&theme, cx)
} else {
List::new(self.notification_list.clone()) List::new(self.notification_list.clone())
.contained() .contained()
.with_style(theme.chat_panel.list) .with_style(theme.chat_panel.list)
.into_any() .into_any()
} else {
self.render_sign_in_prompt(&theme, cx)
}; };
element element
.contained() .contained()

View file

@ -378,6 +378,10 @@ impl<V: 'static> ListState<V> {
.extend((0..element_count).map(|_| ListItem::Unrendered), &()); .extend((0..element_count).map(|_| ListItem::Unrendered), &());
} }
pub fn item_count(&self) -> usize {
self.0.borrow().items.summary().count
}
pub fn splice(&self, old_range: Range<usize>, count: usize) { pub fn splice(&self, old_range: Range<usize>, count: usize) {
let state = &mut *self.0.borrow_mut(); let state = &mut *self.0.borrow_mut();