| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::{h_flex, v_flex}; |
| 3 | use gpui_kit::prelude::FluentBuilder as _; |
| 4 | use gpui_kit::*; |
| 5 | |
| 6 | use super::center::NotificationCenter; |
| 7 | use super::layout::{PREVIEW_MAX_LINES, PREVIEW_SIZE}; |
| 8 | use super::stack::{AgentToast, AgentToastKind}; |
| 9 | use crate::theme; |
| 10 | use crate::views::widgets::{icon, symbol}; |
| 11 | |
| 12 | const BUTTON_HEIGHT: f32 = 30.; |
| 13 | const CLOSE_SIZE: f32 = 24.; |
| 14 | |
| 15 | fn 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 | |
| 40 | pub(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 = match agent.kind { |
| 49 | AgentToastKind::Run { failed: true, .. } => Some("Retry"), |
| 50 | AgentToastKind::Run { .. } => Some("Open session"), |
| 51 | AgentToastKind::Proposal { .. } => None, |
| 52 | }; |
| 53 | let open_label = match agent.kind { |
| 54 | AgentToastKind::Run { .. } => "Open chat", |
| 55 | AgentToastKind::Proposal { .. } => "Review", |
| 56 | }; |
| 57 | let tint = if agent.failed() { |
| 58 | theme::red_soft() |
| 59 | } else { |
| 60 | theme::accent_text() |
| 61 | }; |
| 62 | v_flex() |
| 63 | .w_full() |
| 64 | .gap(px(8.)) |
| 65 | .child( |
| 66 | h_flex() |
| 67 | .w_full() |
| 68 | .h(px(16.)) |
| 69 | .gap(px(8.)) |
| 70 | .items_center() |
| 71 | .child(icon(IconName::Bot, 14., tint)) |
| 72 | .child( |
| 73 | div() |
| 74 | .flex_1() |
| 75 | .min_w_0() |
| 76 | .truncate() |
| 77 | .text_size(px(12.)) |
| 78 | .text_color(theme::text_muted()) |
| 79 | .child(agent.header.clone()), |
| 80 | ) |
| 81 | .when(hovered, |row| { |
| 82 | row.child( |
| 83 | div() |
| 84 | .id("agent-toast-close") |
| 85 | .size(px(CLOSE_SIZE)) |
| 86 | .flex_none() |
| 87 | .flex() |
| 88 | .items_center() |
| 89 | .justify_center() |
| 90 | .rounded_full() |
| 91 | .bg(theme::border_strong()) |
| 92 | .cursor_pointer() |
| 93 | .hover(|button| button.bg(theme::text_faint())) |
| 94 | .child(symbol("close", 16., theme::text())) |
| 95 | .on_click(move |_, _, cx| { |
| 96 | cx.stop_propagation(); |
| 97 | close_center.update(cx, |center, cx| center.dismiss(id, cx)); |
| 98 | }), |
| 99 | ) |
| 100 | }), |
| 101 | ) |
| 102 | .child( |
| 103 | div() |
| 104 | .w_full() |
| 105 | .h(px(20.)) |
| 106 | .truncate() |
| 107 | .text_size(px(14.)) |
| 108 | .line_height(px(20.)) |
| 109 | .font_weight(FontWeight::SEMIBOLD) |
| 110 | .text_color(theme::text()) |
| 111 | .child(agent.title.clone()), |
| 112 | ) |
| 113 | .child( |
| 114 | div() |
| 115 | .w_full() |
| 116 | .text_size(px(PREVIEW_SIZE)) |
| 117 | .line_height(px(18.)) |
| 118 | .text_color(theme::text_soft()) |
| 119 | .line_clamp(PREVIEW_MAX_LINES) |
| 120 | .text_ellipsis() |
| 121 | .child(agent.body.clone()), |
| 122 | ) |
| 123 | .child( |
| 124 | h_flex() |
| 125 | .gap(px(6.)) |
| 126 | .child(button("agent-toast-open-chat", open_label, true).on_click( |
| 127 | move |_, _, cx| { |
| 128 | cx.stop_propagation(); |
| 129 | open_chat_center.update(cx, |center, cx| center.activate(id, cx)); |
| 130 | }, |
| 131 | )) |
| 132 | .children(follow_up_label.map(|label| { |
| 133 | button("agent-toast-follow-up", label, false).on_click(move |_, _, cx| { |
| 134 | cx.stop_propagation(); |
| 135 | follow_up_center |
| 136 | .update(cx, |center, cx| center.agent_toast_follow_up(id, cx)); |
| 137 | }) |
| 138 | })), |
| 139 | ) |
| 140 | } |