chat_panel.rs

 1use chrono::DateTime;
 2use ui::prelude::*;
 3use ui::{ChatMessage, ChatPanel, Panel};
 4
 5use crate::story::Story;
 6
 7#[derive(Element, Default)]
 8pub struct ChatPanelStory {}
 9
10impl ChatPanelStory {
11    fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
12        Story::container(cx)
13            .child(Story::title_for::<_, ChatPanel<V>>(cx))
14            .child(Story::label(cx, "Default"))
15            .child(Panel::new(
16                ScrollState::default(),
17                |_, _| vec![ChatPanel::new(ScrollState::default()).into_any()],
18                Box::new(()),
19            ))
20            .child(Story::label(cx, "With Mesages"))
21            .child(Panel::new(
22                ScrollState::default(),
23                |_, _| {
24                    vec![ChatPanel::new(ScrollState::default())
25                        .with_messages(vec![
26                            ChatMessage::new(
27                                "osiewicz".to_string(),
28                                "is this thing on?".to_string(),
29                                DateTime::parse_from_rfc3339("2023-09-27T15:40:52.707Z")
30                                    .unwrap()
31                                    .naive_local(),
32                            ),
33                            ChatMessage::new(
34                                "maxdeviant".to_string(),
35                                "Reading you loud and clear!".to_string(),
36                                DateTime::parse_from_rfc3339("2023-09-28T15:40:52.707Z")
37                                    .unwrap()
38                                    .naive_local(),
39                            ),
40                        ])
41                        .into_any()]
42                },
43                Box::new(()),
44            ))
45    }
46}