| 1 | use chrono::{Local, Offset, Utc}; |
| 2 | use gpui_kit::assets::IconName; |
| 3 | use gpui_kit::component::{h_flex, v_flex}; |
| 4 | use gpui_kit::*; |
| 5 | |
| 6 | use super::center::NotificationCenter; |
| 7 | use super::layout::{AVATAR_GAP, TOAST_PADDING}; |
| 8 | use super::ring_view::{RING_AVATAR, RING_BORDER, TOAST_RADIUS, answer_button}; |
| 9 | use crate::app_state::AppState; |
| 10 | use crate::call::meeting_subtitle; |
| 11 | use crate::theme; |
| 12 | use crate::views::widgets::icon; |
| 13 | |
| 14 | const MEETING_ICON: f32 = 22.; |
| 15 | |
| 16 | pub struct MeetingToastView { |
| 17 | center: Entity<NotificationCenter>, |
| 18 | app: Entity<AppState>, |
| 19 | toast_id: u64, |
| 20 | _subscriptions: [Subscription; 2], |
| 21 | } |
| 22 | |
| 23 | impl MeetingToastView { |
| 24 | pub fn new(center: Entity<NotificationCenter>, toast_id: u64, cx: &mut Context<Self>) -> Self { |
| 25 | let app = center.read(cx).app().clone(); |
| 26 | let subscriptions = [ |
| 27 | cx.observe(&app, |_, _, cx| cx.notify()), |
| 28 | cx.observe(¢er, |_, _, cx| cx.notify()), |
| 29 | ]; |
| 30 | MeetingToastView { |
| 31 | center, |
| 32 | app, |
| 33 | toast_id, |
| 34 | _subscriptions: subscriptions, |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl Render for MeetingToastView { |
| 40 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 41 | let Some(toast) = self.app.read(cx).meeting_toasts.get(self.toast_id).cloned() else { |
| 42 | return div() |
| 43 | .size_full() |
| 44 | .bg(theme::surface_raised()) |
| 45 | .into_any_element(); |
| 46 | }; |
| 47 | window.set_window_title(&toast.subject); |
| 48 | let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix()); |
| 49 | let toast_id = self.toast_id; |
| 50 | let dismiss_app = self.app.clone(); |
| 51 | let join_center = self.center.clone(); |
| 52 | let dismiss = answer_button( |
| 53 | "meeting-dismiss", |
| 54 | "Dismiss", |
| 55 | IconName::Close, |
| 56 | theme::surface_raised(), |
| 57 | ) |
| 58 | .border_1() |
| 59 | .border_color(theme::border_strong()) |
| 60 | .text_color(theme::text()) |
| 61 | .on_click(move |_, _, cx| { |
| 62 | cx.stop_propagation(); |
| 63 | dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx)); |
| 64 | }); |
| 65 | let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent()) |
| 66 | .text_color(theme::on_accent()) |
| 67 | .on_click(move |_, _, cx| { |
| 68 | cx.stop_propagation(); |
| 69 | join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx)); |
| 70 | }); |
| 71 | div() |
| 72 | .id(("meeting-toast", toast_id)) |
| 73 | .size_full() |
| 74 | .rounded(px(TOAST_RADIUS)) |
| 75 | .bg(theme::surface_raised()) |
| 76 | .border(px(RING_BORDER)) |
| 77 | .border_color(theme::accent()) |
| 78 | .overflow_hidden() |
| 79 | .child( |
| 80 | div().size_full().p(px(TOAST_PADDING)).child( |
| 81 | h_flex() |
| 82 | .size_full() |
| 83 | .gap(px(AVATAR_GAP)) |
| 84 | .items_start() |
| 85 | .child( |
| 86 | div() |
| 87 | .size(px(RING_AVATAR)) |
| 88 | .flex_none() |
| 89 | .flex() |
| 90 | .items_center() |
| 91 | .justify_center() |
| 92 | .rounded_full() |
| 93 | .bg(theme::border_strong()) |
| 94 | .child(icon(IconName::Video, MEETING_ICON, theme::text())), |
| 95 | ) |
| 96 | .child( |
| 97 | v_flex() |
| 98 | .flex_1() |
| 99 | .min_w_0() |
| 100 | .gap(px(2.)) |
| 101 | .child( |
| 102 | div() |
| 103 | .truncate() |
| 104 | .text_size(px(15.)) |
| 105 | .font_weight(FontWeight::SEMIBOLD) |
| 106 | .text_color(theme::text()) |
| 107 | .child(toast.subject.clone()), |
| 108 | ) |
| 109 | .child( |
| 110 | div() |
| 111 | .text_size(px(12.5)) |
| 112 | .text_color(theme::text_muted()) |
| 113 | .child(subtitle), |
| 114 | ) |
| 115 | .child(h_flex().mt(px(8.)).gap(px(6.)).child(dismiss).child(join)), |
| 116 | ), |
| 117 | ), |
| 118 | ) |
| 119 | .into_any_element() |
| 120 | } |
| 121 | } |