1use std::sync::Arc;
2
3use client::User;
4use story::{StoryContainer, StoryItem, StorySection};
5use ui::prelude::*;
6
7use crate::ui::{ChatMessage, UserOrAssistant};
8use crate::MessageId;
9
10pub struct ChatMessageStory;
11
12impl Render for ChatMessageStory {
13 fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
14 let user_1 = Arc::new(User {
15 id: 12345,
16 github_login: "iamnbutler".into(),
17 avatar_uri: "https://avatars.githubusercontent.com/u/1714999?v=4".into(),
18 });
19
20 StoryContainer::new(
21 "ChatMessage Story",
22 "crates/assistant2/src/ui/stories/chat_message.rs",
23 )
24 .child(
25 StorySection::new()
26 .child(StoryItem::new(
27 "User chat message",
28 ChatMessage::new(
29 MessageId(0),
30 UserOrAssistant::User(Some(user_1.clone())),
31 vec![div().child("What can I do here?").into_any_element()],
32 false,
33 Box::new(|_, _| {}),
34 ),
35 ))
36 .child(StoryItem::new(
37 "User chat message (collapsed)",
38 ChatMessage::new(
39 MessageId(0),
40 UserOrAssistant::User(Some(user_1.clone())),
41 vec![div().child("What can I do here?").into_any_element()],
42 true,
43 Box::new(|_, _| {}),
44 ),
45 )),
46 )
47 .child(
48 StorySection::new()
49 .child(StoryItem::new(
50 "Assistant chat message",
51 ChatMessage::new(
52 MessageId(0),
53 UserOrAssistant::Assistant,
54 vec![div().child("You can talk to me!").into_any_element()],
55 false,
56 Box::new(|_, _| {}),
57 ),
58 ))
59 .child(StoryItem::new(
60 "Assistant chat message (collapsed)",
61 ChatMessage::new(
62 MessageId(0),
63 UserOrAssistant::Assistant,
64 vec![div().child(MULTI_LINE_MESSAGE).into_any_element()],
65 true,
66 Box::new(|_, _| {}),
67 ),
68 )),
69 )
70 .child(
71 StorySection::new().child(StoryItem::new(
72 "Conversation between user and assistant",
73 v_flex()
74 .gap_2()
75 .child(ChatMessage::new(
76 MessageId(0),
77 UserOrAssistant::User(Some(user_1.clone())),
78 vec![div().child("What is Rust??").into_any_element()],
79 false,
80 Box::new(|_, _| {}),
81 ))
82 .child(ChatMessage::new(
83 MessageId(0),
84 UserOrAssistant::Assistant,
85 vec![div().child("Rust is a multi-paradigm programming language focused on performance and safety").into_any_element()],
86 false,
87 Box::new(|_, _| {}),
88 ))
89 .child(ChatMessage::new(
90 MessageId(0),
91 UserOrAssistant::User(Some(user_1)),
92 vec![div().child("Sounds pretty cool!").into_any_element()],
93 false,
94 Box::new(|_, _| {}),
95 )),
96 )),
97 )
98 }
99}
100
101const MULTI_LINE_MESSAGE: &str = "In 2010, the movies nominated for the 82nd Academy Awards, for films released in 2009, were as follows. Note that 2010 nominees were announced for the ceremony happening in that year, but they honor movies from the previous year";