BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / notify / agent_toast.rs

agent_toast.rs

agent_toast.rs 4.5 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{h_flex, v_flex};
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5
6use super::center::NotificationCenter;
7use super::layout::{PREVIEW_MAX_LINES, PREVIEW_SIZE};
8use super::stack::AgentToast;
9use crate::theme;
10use crate::views::widgets::{icon, symbol};
11
12const BUTTON_HEIGHT: f32 = 30.;
13const CLOSE_SIZE: f32 = 24.;
14
15fn button(id: &'static str, label: &'static str, primary: bool) -> Stateful<Div> {
16 h_flex()
17 .id(id)
18 .h(px(BUTTON_HEIGHT))
19 .px(px(12.))
20 .items_center()
21 .rounded(px(6.))
22 .cursor_pointer()
23 .text_size(px(12.5))
24 .font_weight(FontWeight::SEMIBOLD)
25 .when(primary, |button| {
26 button
27 .bg(theme::accent())
28 .text_color(theme::on_accent())
29 .hover(|button| button.bg(theme::accent_text()))
30 })
31 .when(!primary, |button| {
32 button
33 .bg(theme::popup())
34 .text_color(theme::text_soft())
35 .hover(|button| button.bg(theme::popup_hover()))
36 })
37 .child(label)
38}
39
40pub(super) fn agent_toast_content(
41 center: &Entity<NotificationCenter>,
42 id: u64,
43 agent: &AgentToast,
44 hovered: bool,
45) -> Div {
46 let (open_chat_center, follow_up_center, close_center) =
47 (center.clone(), center.clone(), center.clone());
48 let follow_up_label = if agent.failed {
49 "Retry"
50 } else {
51 "Open session"
52 };
53 let tint = if agent.failed {
54 theme::red_soft()
55 } else {
56 theme::accent_text()
57 };
58 v_flex()
59 .w_full()
60 .gap(px(8.))
61 .child(
62 h_flex()
63 .w_full()
64 .h(px(16.))
65 .gap(px(8.))
66 .items_center()
67 .child(icon(IconName::Bot, 14., tint))
68 .child(
69 div()
70 .flex_1()
71 .min_w_0()
72 .truncate()
73 .text_size(px(12.))
74 .text_color(theme::text_muted())
75 .child(agent.header.clone()),
76 )
77 .when(hovered, |row| {
78 row.child(
79 div()
80 .id("agent-toast-close")
81 .size(px(CLOSE_SIZE))
82 .flex_none()
83 .flex()
84 .items_center()
85 .justify_center()
86 .rounded_full()
87 .bg(theme::border_strong())
88 .cursor_pointer()
89 .hover(|button| button.bg(theme::text_faint()))
90 .child(symbol("close", 16., theme::text()))
91 .on_click(move |_, _, cx| {
92 cx.stop_propagation();
93 close_center.update(cx, |center, cx| center.dismiss(id, cx));
94 }),
95 )
96 }),
97 )
98 .child(
99 div()
100 .w_full()
101 .h(px(20.))
102 .truncate()
103 .text_size(px(14.))
104 .line_height(px(20.))
105 .font_weight(FontWeight::SEMIBOLD)
106 .text_color(theme::text())
107 .child(agent.title.clone()),
108 )
109 .child(
110 div()
111 .w_full()
112 .text_size(px(PREVIEW_SIZE))
113 .line_height(px(18.))
114 .text_color(theme::text_soft())
115 .line_clamp(PREVIEW_MAX_LINES)
116 .child(agent.body.clone()),
117 )
118 .child(
119 h_flex()
120 .gap(px(6.))
121 .child(button("agent-toast-open-chat", "Open chat", true).on_click(
122 move |_, _, cx| {
123 cx.stop_propagation();
124 open_chat_center.update(cx, |center, cx| center.activate(id, cx));
125 },
126 ))
127 .child(
128 button("agent-toast-follow-up", follow_up_label, false).on_click(
129 move |_, _, cx| {
130 cx.stop_propagation();
131 follow_up_center
132 .update(cx, |center, cx| center.agent_toast_follow_up(id, cx));
133 },
134 ),
135 ),
136 )
137}