Use naive_format_distance_from_now in Notifications
This commit is contained in:
parent
b76c117979
commit
6d562aaa6f
2 changed files with 61 additions and 8 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::utils::naive_format_distance_from_now;
|
||||||
use crate::{
|
use crate::{
|
||||||
h_stack, prelude::*, static_new_notification_items_2, v_stack, Avatar, Button, Icon,
|
h_stack, prelude::*, static_new_notification_items_2, v_stack, Avatar, Button, Icon,
|
||||||
IconButton, IconElement, Label, LabelColor, LineHeightStyle, ListHeaderMeta, ListSeparator,
|
IconButton, IconElement, Label, LabelColor, LineHeightStyle, ListHeaderMeta, ListSeparator,
|
||||||
|
@ -137,6 +138,7 @@ impl<V> Notification<V> {
|
||||||
fn new(
|
fn new(
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
message: SharedString,
|
message: SharedString,
|
||||||
|
date_received: NaiveDateTime,
|
||||||
slot: ActorOrIcon,
|
slot: ActorOrIcon,
|
||||||
click_action: Option<ClickHandler<V>>,
|
click_action: Option<ClickHandler<V>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -150,9 +152,7 @@ impl<V> Notification<V> {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
date_received: DateTime::parse_from_rfc3339("1969-07-20T00:00:00Z")
|
date_received,
|
||||||
.unwrap()
|
|
||||||
.naive_local(),
|
|
||||||
message,
|
message,
|
||||||
meta: None,
|
meta: None,
|
||||||
slot,
|
slot,
|
||||||
|
@ -170,12 +170,14 @@ impl<V> Notification<V> {
|
||||||
pub fn new_actor_message(
|
pub fn new_actor_message(
|
||||||
id: impl Into<ElementId>,
|
id: impl Into<ElementId>,
|
||||||
message: impl Into<SharedString>,
|
message: impl Into<SharedString>,
|
||||||
|
date_received: NaiveDateTime,
|
||||||
actor: PublicActor,
|
actor: PublicActor,
|
||||||
click_action: ClickHandler<V>,
|
click_action: ClickHandler<V>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
id.into(),
|
id.into(),
|
||||||
message.into(),
|
message.into(),
|
||||||
|
date_received,
|
||||||
ActorOrIcon::Actor(actor),
|
ActorOrIcon::Actor(actor),
|
||||||
Some(click_action),
|
Some(click_action),
|
||||||
)
|
)
|
||||||
|
@ -187,12 +189,14 @@ impl<V> Notification<V> {
|
||||||
pub fn new_icon_message(
|
pub fn new_icon_message(
|
||||||
id: impl Into<ElementId>,
|
id: impl Into<ElementId>,
|
||||||
message: impl Into<SharedString>,
|
message: impl Into<SharedString>,
|
||||||
|
date_received: NaiveDateTime,
|
||||||
icon: Icon,
|
icon: Icon,
|
||||||
click_action: ClickHandler<V>,
|
click_action: ClickHandler<V>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(
|
Self::new(
|
||||||
id.into(),
|
id.into(),
|
||||||
message.into(),
|
message.into(),
|
||||||
|
date_received,
|
||||||
ActorOrIcon::Icon(icon),
|
ActorOrIcon::Icon(icon),
|
||||||
Some(click_action),
|
Some(click_action),
|
||||||
)
|
)
|
||||||
|
@ -205,10 +209,18 @@ impl<V> Notification<V> {
|
||||||
pub fn new_actor_with_actions(
|
pub fn new_actor_with_actions(
|
||||||
id: impl Into<ElementId>,
|
id: impl Into<ElementId>,
|
||||||
message: impl Into<SharedString>,
|
message: impl Into<SharedString>,
|
||||||
|
date_received: NaiveDateTime,
|
||||||
actor: PublicActor,
|
actor: PublicActor,
|
||||||
actions: [NotificationAction<V>; 2],
|
actions: [NotificationAction<V>; 2],
|
||||||
) -> Self {
|
) -> 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
|
/// Creates a new notification with an icon slot
|
||||||
|
@ -218,10 +230,18 @@ impl<V> Notification<V> {
|
||||||
pub fn new_icon_with_actions(
|
pub fn new_icon_with_actions(
|
||||||
id: impl Into<ElementId>,
|
id: impl Into<ElementId>,
|
||||||
message: impl Into<SharedString>,
|
message: impl Into<SharedString>,
|
||||||
|
date_received: NaiveDateTime,
|
||||||
icon: Icon,
|
icon: Icon,
|
||||||
actions: [NotificationAction<V>; 2],
|
actions: [NotificationAction<V>; 2],
|
||||||
) -> Self {
|
) -> 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<V>) -> Self {
|
fn on_click(mut self, handler: ClickHandler<V>) -> Self {
|
||||||
|
@ -303,9 +323,11 @@ impl<V> Notification<V> {
|
||||||
h_stack()
|
h_stack()
|
||||||
.gap_1()
|
.gap_1()
|
||||||
.child(
|
.child(
|
||||||
Label::new(
|
Label::new(naive_format_distance_from_now(
|
||||||
self.date_received.format("%m/%d/%Y").to_string(),
|
self.date_received,
|
||||||
)
|
true,
|
||||||
|
true,
|
||||||
|
))
|
||||||
.color(LabelColor::Muted),
|
.color(LabelColor::Muted),
|
||||||
)
|
)
|
||||||
.child(self.render_meta_items(cx)),
|
.child(self.render_meta_items(cx)),
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use chrono::{DateTime, NaiveDateTime};
|
||||||
use gpui2::{AppContext, ViewContext};
|
use gpui2::{AppContext, ViewContext};
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use theme2::ActiveTheme;
|
use theme2::ActiveTheme;
|
||||||
|
@ -332,12 +333,18 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||||
Notification::new_icon_message(
|
Notification::new_icon_message(
|
||||||
"notif-1",
|
"notif-1",
|
||||||
"You were mentioned in a note.",
|
"You were mentioned in a note.",
|
||||||
|
DateTime::parse_from_rfc3339("2023-11-02T11:59:57Z")
|
||||||
|
.unwrap()
|
||||||
|
.naive_local(),
|
||||||
Icon::AtSign,
|
Icon::AtSign,
|
||||||
Arc::new(|_, _| {}),
|
Arc::new(|_, _| {}),
|
||||||
),
|
),
|
||||||
Notification::new_actor_with_actions(
|
Notification::new_actor_with_actions(
|
||||||
"notif-2",
|
"notif-2",
|
||||||
"as-cii sent you a contact request.",
|
"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"),
|
PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"),
|
||||||
[
|
[
|
||||||
NotificationAction::new(
|
NotificationAction::new(
|
||||||
|
@ -355,12 +362,18 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||||
Notification::new_icon_message(
|
Notification::new_icon_message(
|
||||||
"notif-3",
|
"notif-3",
|
||||||
"You were mentioned #design.",
|
"You were mentioned #design.",
|
||||||
|
DateTime::parse_from_rfc3339("2023-11-02T12:09:07Z")
|
||||||
|
.unwrap()
|
||||||
|
.naive_local(),
|
||||||
Icon::MessageBubbles,
|
Icon::MessageBubbles,
|
||||||
Arc::new(|_, _| {}),
|
Arc::new(|_, _| {}),
|
||||||
),
|
),
|
||||||
Notification::new_actor_with_actions(
|
Notification::new_actor_with_actions(
|
||||||
"notif-4",
|
"notif-4",
|
||||||
"as-cii sent you a contact request.",
|
"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"),
|
PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"),
|
||||||
[
|
[
|
||||||
NotificationAction::new(
|
NotificationAction::new(
|
||||||
|
@ -378,12 +391,18 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||||
Notification::new_icon_message(
|
Notification::new_icon_message(
|
||||||
"notif-5",
|
"notif-5",
|
||||||
"You were mentioned in a note.",
|
"You were mentioned in a note.",
|
||||||
|
DateTime::parse_from_rfc3339("2023-10-28T12:09:07Z")
|
||||||
|
.unwrap()
|
||||||
|
.naive_local(),
|
||||||
Icon::AtSign,
|
Icon::AtSign,
|
||||||
Arc::new(|_, _| {}),
|
Arc::new(|_, _| {}),
|
||||||
),
|
),
|
||||||
Notification::new_actor_with_actions(
|
Notification::new_actor_with_actions(
|
||||||
"notif-6",
|
"notif-6",
|
||||||
"as-cii sent you a contact request.",
|
"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"),
|
PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"),
|
||||||
[
|
[
|
||||||
NotificationAction::new(
|
NotificationAction::new(
|
||||||
|
@ -401,12 +420,18 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||||
Notification::new_icon_message(
|
Notification::new_icon_message(
|
||||||
"notif-7",
|
"notif-7",
|
||||||
"You were mentioned in a note.",
|
"You were mentioned in a note.",
|
||||||
|
DateTime::parse_from_rfc3339("2022-10-14T12:09:07Z")
|
||||||
|
.unwrap()
|
||||||
|
.naive_local(),
|
||||||
Icon::AtSign,
|
Icon::AtSign,
|
||||||
Arc::new(|_, _| {}),
|
Arc::new(|_, _| {}),
|
||||||
),
|
),
|
||||||
Notification::new_actor_with_actions(
|
Notification::new_actor_with_actions(
|
||||||
"notif-8",
|
"notif-8",
|
||||||
"as-cii sent you a contact request.",
|
"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"),
|
PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"),
|
||||||
[
|
[
|
||||||
NotificationAction::new(
|
NotificationAction::new(
|
||||||
|
@ -424,12 +449,18 @@ pub fn static_new_notification_items_2<V: 'static>() -> Vec<Notification<V>> {
|
||||||
Notification::new_icon_message(
|
Notification::new_icon_message(
|
||||||
"notif-9",
|
"notif-9",
|
||||||
"You were mentioned in a note.",
|
"You were mentioned in a note.",
|
||||||
|
DateTime::parse_from_rfc3339("2021-02-02T12:09:07Z")
|
||||||
|
.unwrap()
|
||||||
|
.naive_local(),
|
||||||
Icon::AtSign,
|
Icon::AtSign,
|
||||||
Arc::new(|_, _| {}),
|
Arc::new(|_, _| {}),
|
||||||
),
|
),
|
||||||
Notification::new_actor_with_actions(
|
Notification::new_actor_with_actions(
|
||||||
"notif-10",
|
"notif-10",
|
||||||
"as-cii sent you a contact request.",
|
"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"),
|
PublicActor::new("as-cii", "http://github.com/as-cii.png?s=50"),
|
||||||
[
|
[
|
||||||
NotificationAction::new(
|
NotificationAction::new(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue