diff --git a/crates/ui2/src/components/notifications_panel.rs b/crates/ui2/src/components/notifications_panel.rs index c53b60f213..697b4de63b 100644 --- a/crates/ui2/src/components/notifications_panel.rs +++ b/crates/ui2/src/components/notifications_panel.rs @@ -1,3 +1,4 @@ +use crate::utils::naive_format_distance_from_now; use crate::{ h_stack, prelude::*, static_new_notification_items_2, v_stack, Avatar, Button, Icon, IconButton, IconElement, Label, LabelColor, LineHeightStyle, ListHeaderMeta, ListSeparator, @@ -137,6 +138,7 @@ impl Notification { fn new( id: ElementId, message: SharedString, + date_received: NaiveDateTime, slot: ActorOrIcon, click_action: Option>, ) -> Self { @@ -150,9 +152,7 @@ impl Notification { Self { id, - date_received: DateTime::parse_from_rfc3339("1969-07-20T00:00:00Z") - .unwrap() - .naive_local(), + date_received, message, meta: None, slot, @@ -170,12 +170,14 @@ impl Notification { pub fn new_actor_message( id: impl Into, message: impl Into, + date_received: NaiveDateTime, actor: PublicActor, click_action: ClickHandler, ) -> Self { Self::new( id.into(), message.into(), + date_received, ActorOrIcon::Actor(actor), Some(click_action), ) @@ -187,12 +189,14 @@ impl Notification { pub fn new_icon_message( id: impl Into, message: impl Into, + date_received: NaiveDateTime, icon: Icon, click_action: ClickHandler, ) -> Self { Self::new( id.into(), message.into(), + date_received, ActorOrIcon::Icon(icon), Some(click_action), ) @@ -205,10 +209,18 @@ impl Notification { pub fn new_actor_with_actions( id: impl Into, message: impl Into, + date_received: NaiveDateTime, actor: PublicActor, actions: [NotificationAction; 2], ) -> Self { - Self::new(id.into(), message.into(), ActorOrIcon::Actor(actor), None).actions(actions) + Self::new( + id.into(), + message.into(), + date_received, + ActorOrIcon::Actor(actor), + None, + ) + .actions(actions) } /// Creates a new notification with an icon slot @@ -218,10 +230,18 @@ impl Notification { pub fn new_icon_with_actions( id: impl Into, message: impl Into, + date_received: NaiveDateTime, icon: Icon, actions: [NotificationAction; 2], ) -> Self { - Self::new(id.into(), message.into(), ActorOrIcon::Icon(icon), None).actions(actions) + Self::new( + id.into(), + message.into(), + date_received, + ActorOrIcon::Icon(icon), + None, + ) + .actions(actions) } fn on_click(mut self, handler: ClickHandler) -> Self { @@ -303,9 +323,11 @@ impl Notification { h_stack() .gap_1() .child( - Label::new( - self.date_received.format("%m/%d/%Y").to_string(), - ) + Label::new(naive_format_distance_from_now( + self.date_received, + true, + true, + )) .color(LabelColor::Muted), ) .child(self.render_meta_items(cx)), diff --git a/crates/ui2/src/static_data.rs b/crates/ui2/src/static_data.rs index 45e4dfa423..3964873055 100644 --- a/crates/ui2/src/static_data.rs +++ b/crates/ui2/src/static_data.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; +use chrono::{DateTime, NaiveDateTime}; use gpui2::{AppContext, ViewContext}; use rand::Rng; use theme2::ActiveTheme; @@ -332,12 +333,18 @@ pub fn static_new_notification_items_2() -> Vec> { Notification::new_icon_message( "notif-1", "You were mentioned in a note.", + DateTime::parse_from_rfc3339("2023-11-02T11:59:57Z") + .unwrap() + .naive_local(), Icon::AtSign, Arc::new(|_, _| {}), ), Notification::new_actor_with_actions( "notif-2", "as-cii sent you a contact request.", + DateTime::parse_from_rfc3339("2023-11-02T12:09:07Z") + .unwrap() + .naive_local(), PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"), [ NotificationAction::new( @@ -355,12 +362,18 @@ pub fn static_new_notification_items_2() -> Vec> { Notification::new_icon_message( "notif-3", "You were mentioned #design.", + DateTime::parse_from_rfc3339("2023-11-02T12:09:07Z") + .unwrap() + .naive_local(), Icon::MessageBubbles, Arc::new(|_, _| {}), ), Notification::new_actor_with_actions( "notif-4", "as-cii sent you a contact request.", + DateTime::parse_from_rfc3339("2023-11-01T12:09:07Z") + .unwrap() + .naive_local(), PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"), [ NotificationAction::new( @@ -378,12 +391,18 @@ pub fn static_new_notification_items_2() -> Vec> { Notification::new_icon_message( "notif-5", "You were mentioned in a note.", + DateTime::parse_from_rfc3339("2023-10-28T12:09:07Z") + .unwrap() + .naive_local(), Icon::AtSign, Arc::new(|_, _| {}), ), Notification::new_actor_with_actions( "notif-6", "as-cii sent you a contact request.", + DateTime::parse_from_rfc3339("2022-10-25T12:09:07Z") + .unwrap() + .naive_local(), PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"), [ NotificationAction::new( @@ -401,12 +420,18 @@ pub fn static_new_notification_items_2() -> Vec> { Notification::new_icon_message( "notif-7", "You were mentioned in a note.", + DateTime::parse_from_rfc3339("2022-10-14T12:09:07Z") + .unwrap() + .naive_local(), Icon::AtSign, Arc::new(|_, _| {}), ), Notification::new_actor_with_actions( "notif-8", "as-cii sent you a contact request.", + DateTime::parse_from_rfc3339("2021-10-12T12:09:07Z") + .unwrap() + .naive_local(), PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"), [ NotificationAction::new( @@ -424,12 +449,18 @@ pub fn static_new_notification_items_2() -> Vec> { Notification::new_icon_message( "notif-9", "You were mentioned in a note.", + DateTime::parse_from_rfc3339("2021-02-02T12:09:07Z") + .unwrap() + .naive_local(), Icon::AtSign, Arc::new(|_, _| {}), ), Notification::new_actor_with_actions( "notif-10", "as-cii sent you a contact request.", + DateTime::parse_from_rfc3339("1969-07-20T00:00:00Z") + .unwrap() + .naive_local(), PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"), [ NotificationAction::new(