Get notifications rendering in panel

This commit is contained in:
Julia 2023-12-12 16:31:26 -05:00
parent d3eff6371e
commit 01d4e711d8

View file

@ -9,7 +9,8 @@ use gpui::{
actions, div, list, px, serde_json, AnyElement, AppContext, AsyncWindowContext, DismissEvent, actions, div, list, px, serde_json, AnyElement, AppContext, AsyncWindowContext, DismissEvent,
Div, Element, EventEmitter, FocusHandle, FocusableView, InteractiveElement, IntoElement, Div, Element, EventEmitter, FocusHandle, FocusableView, InteractiveElement, IntoElement,
ListAlignment, ListScrollEvent, ListState, Model, ParentElement, Render, Stateful, ListAlignment, ListScrollEvent, ListState, Model, ParentElement, Render, Stateful,
StatefulInteractiveElement, Task, View, ViewContext, VisualContext, WeakView, WindowContext, Styled, StatefulInteractiveElement, Styled, Task, View, ViewContext, VisualContext, WeakView,
WindowContext,
}; };
use notifications::{NotificationEntry, NotificationEvent, NotificationStore}; use notifications::{NotificationEntry, NotificationEvent, NotificationStore};
use project::Fs; use project::Fs;
@ -109,10 +110,9 @@ impl NotificationPanel {
let notification_list = let notification_list =
ListState::new(0, ListAlignment::Top, px(1000.), move |ix, cx| { ListState::new(0, ListAlignment::Top, px(1000.), move |ix, cx| {
dbg!();
view.update(cx, |this, cx| { view.update(cx, |this, cx| {
this.render_notification(ix, cx).unwrap() this.render_notification(ix, cx)
// .unwrap_or_else(|| div().into_any()) .unwrap_or_else(|| div().into_any())
}) })
}); });
notification_list.set_scroll_handler(cx.listener( notification_list.set_scroll_handler(cx.listener(
@ -229,71 +229,80 @@ impl NotificationPanel {
self.did_render_notification(notification_id, &notification, cx); self.did_render_notification(notification_id, &notification, cx);
} }
println!("rendering a notification");
return Some(div().bg(gpui::red()).size_full().into_any());
Some( Some(
ButtonLike::new(ix) div()
.child( .child(
h_stack() ButtonLike::new(ix)
.children(actor.map(|actor| Avatar::new(actor.avatar_uri.clone())))
.child( .child(
v_stack().child(Label::new(text)).child( h_stack()
h_stack() .children(actor.map(|actor| Avatar::new(actor.avatar_uri.clone())))
.child(Label::new(format_timestamp( .child(
timestamp, v_stack().child(Label::new(text)).child(
now, h_stack()
self.local_timezone, .child(Label::new(format_timestamp(
))) timestamp,
.children(if let Some(is_accepted) = response { now,
Some(div().child(Label::new(if is_accepted { self.local_timezone,
"You accepted" )))
} else { .children(if let Some(is_accepted) = response {
"You declined" Some(div().child(Label::new(if is_accepted {
}))) "You accepted"
} else if needs_response { } else {
Some( "You declined"
h_stack() })))
.child(Button::new("decline", "Decline").on_click( } else if needs_response {
{ Some(
let notification = notification.clone(); h_stack()
let view = cx.view().clone(); .child(
move |_, cx| { Button::new("decline", "Decline")
view.update(cx, |this, cx| { .on_click({
let notification =
notification.clone();
let view = cx.view().clone();
move |_, cx| {
view.update(cx, |this, cx| {
this.respond_to_notification( this.respond_to_notification(
notification.clone(), notification.clone(),
false, false,
cx, cx,
) )
}); });
} }
}, }),
)) )
.child(Button::new("accept", "Accept").on_click({ .child(
let notification = notification.clone(); Button::new("accept", "Accept")
let view = cx.view().clone(); .on_click({
move |_, cx| { let notification =
view.update(cx, |this, cx| { notification.clone();
let view = cx.view().clone();
move |_, cx| {
view.update(cx, |this, cx| {
this.respond_to_notification( this.respond_to_notification(
notification.clone(), notification.clone(),
true, true,
cx, cx,
) )
}); });
} }
})), }),
) ),
} else { )
None } else {
}), None
), }),
), ),
),
)
.disabled(!can_navigate)
.on_click({
let notification = notification.clone();
cx.listener(move |this, _, cx| {
this.did_click_notification(&notification, cx)
})
}),
) )
.disabled(!can_navigate) .into_any(),
.on_click({
let notification = notification.clone();
cx.listener(move |this, _, cx| this.did_click_notification(&notification, cx))
})
.into_any_element(),
) )
} }
@ -476,7 +485,6 @@ impl NotificationPanel {
old_range, old_range,
new_count, new_count,
} => { } => {
dbg!(new_count);
self.notification_list.splice(old_range.clone(), *new_count); self.notification_list.splice(old_range.clone(), *new_count);
cx.notify(); cx.notify();
} }
@ -549,20 +557,19 @@ impl Render for NotificationPanel {
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement {
if self.client.user_id().is_none() { if self.client.user_id().is_none() {
dbg!();
self.render_sign_in_prompt() self.render_sign_in_prompt()
} else if self.notification_list.item_count() == 0 { } else if self.notification_list.item_count() == 0 {
dbg!();
self.render_empty_state() self.render_empty_state()
} else { } else {
dbg!(self.notification_list.item_count());
v_stack() v_stack()
.bg(gpui::red())
.child( .child(
h_stack() h_stack()
.child(Label::new("Notifications")) .child(Label::new("Notifications"))
.child(IconElement::new(Icon::Envelope)), .child(IconElement::new(Icon::Envelope)),
) )
.child(list(self.notification_list.clone()).full()) .child(list(self.notification_list.clone()).size_full())
.size_full()
.into_any_element() .into_any_element()
} }
} }