| 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::prelude::FluentBuilder as _; |
| 5 | use gpui_kit::*; |
| 6 | |
| 7 | use super::center::NotificationCenter; |
| 8 | use super::layout::{AVATAR_GAP, TOAST_PADDING}; |
| 9 | use super::ring_view::{RING_AVATAR, answer_button, toast_radius}; |
| 10 | use crate::app_state::AppState; |
| 11 | use crate::call::ReminderPhase; |
| 12 | use crate::call::meeting_subtitle; |
| 13 | use crate::theme; |
| 14 | use crate::views::widgets::icon; |
| 15 | |
| 16 | const MEETING_ICON: f32 = 22.; |
| 17 | const LIVE_DOT: f32 = 7.; |
| 18 | const CLOSE_BUTTON: f32 = 24.; |
| 19 | const CLOSE_INSET: f32 = 8.; |
| 20 | const CLOSE_CLEARANCE: f32 = 20.; |
| 21 | |
| 22 | pub struct MeetingToastView { |
| 23 | center: Entity<NotificationCenter>, |
| 24 | app: Entity<AppState>, |
| 25 | toast_id: u64, |
| 26 | _subscriptions: [Subscription; 2], |
| 27 | } |
| 28 | |
| 29 | impl MeetingToastView { |
| 30 | pub fn new(center: Entity<NotificationCenter>, toast_id: u64, cx: &mut Context<Self>) -> Self { |
| 31 | let app = center.read(cx).app().clone(); |
| 32 | let subscriptions = [ |
| 33 | cx.observe(&app, |_, _, cx| cx.notify()), |
| 34 | cx.observe(¢er, |_, _, cx| cx.notify()), |
| 35 | ]; |
| 36 | MeetingToastView { |
| 37 | center, |
| 38 | app, |
| 39 | toast_id, |
| 40 | _subscriptions: subscriptions, |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl Render for MeetingToastView { |
| 46 | fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement { |
| 47 | let Some(toast) = self.app.read(cx).meeting_toasts.get(self.toast_id).cloned() else { |
| 48 | return div().size_full().bg(theme::popup()).into_any_element(); |
| 49 | }; |
| 50 | window.set_window_title(&toast.subject); |
| 51 | let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix()); |
| 52 | let toast_id = self.toast_id; |
| 53 | let join_center = self.center.clone(); |
| 54 | let snooze_app = self.app.clone(); |
| 55 | let dismiss_app = self.app.clone(); |
| 56 | let snooze = answer_button( |
| 57 | "meeting-snooze", |
| 58 | "Snooze", |
| 59 | IconName::AlarmClock, |
| 60 | theme::popup_hover(), |
| 61 | theme::text(), |
| 62 | ) |
| 63 | .on_click(move |_, _, cx| { |
| 64 | cx.stop_propagation(); |
| 65 | snooze_app.update(cx, |state, cx| state.snooze_meeting_toast(toast_id, cx)); |
| 66 | }); |
| 67 | let dismiss = div() |
| 68 | .id("meeting-dismiss") |
| 69 | .absolute() |
| 70 | .top(px(CLOSE_INSET)) |
| 71 | .right(px(CLOSE_INSET)) |
| 72 | .size(px(CLOSE_BUTTON)) |
| 73 | .flex() |
| 74 | .items_center() |
| 75 | .justify_center() |
| 76 | .rounded(px(6.)) |
| 77 | .cursor_pointer() |
| 78 | .hover(|button| button.bg(theme::row_hover())) |
| 79 | .child(icon(IconName::Close, 14., theme::text_muted())) |
| 80 | .on_click(move |_, _, cx| { |
| 81 | cx.stop_propagation(); |
| 82 | dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx)); |
| 83 | }); |
| 84 | let join = answer_button( |
| 85 | "meeting-join", |
| 86 | "Join", |
| 87 | IconName::Video, |
| 88 | theme::accent(), |
| 89 | theme::on_accent(), |
| 90 | ) |
| 91 | .on_click(move |_, _, cx| { |
| 92 | cx.stop_propagation(); |
| 93 | join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx)); |
| 94 | }); |
| 95 | let live = toast.phase == ReminderPhase::Live; |
| 96 | let buttons = if toast.phase == ReminderPhase::Soon { |
| 97 | h_flex().mt(px(8.)).gap(px(6.)).child(snooze).child(join) |
| 98 | } else { |
| 99 | h_flex().mt(px(8.)).gap(px(6.)).child(join) |
| 100 | }; |
| 101 | div() |
| 102 | .id(("meeting-toast", toast_id)) |
| 103 | .size_full() |
| 104 | .rounded(toast_radius(window)) |
| 105 | .bg(theme::popup()) |
| 106 | .overflow_hidden() |
| 107 | .child( |
| 108 | div().size_full().p(px(TOAST_PADDING)).child( |
| 109 | h_flex() |
| 110 | .size_full() |
| 111 | .gap(px(AVATAR_GAP)) |
| 112 | .items_start() |
| 113 | .child( |
| 114 | div() |
| 115 | .size(px(RING_AVATAR)) |
| 116 | .flex_none() |
| 117 | .flex() |
| 118 | .items_center() |
| 119 | .justify_center() |
| 120 | .rounded_full() |
| 121 | .bg(theme::border_strong()) |
| 122 | .child(icon(IconName::Video, MEETING_ICON, theme::text())), |
| 123 | ) |
| 124 | .child( |
| 125 | v_flex() |
| 126 | .flex_1() |
| 127 | .min_w_0() |
| 128 | .pr(px(CLOSE_CLEARANCE)) |
| 129 | .gap(px(2.)) |
| 130 | .child( |
| 131 | div() |
| 132 | .truncate() |
| 133 | .text_size(px(15.)) |
| 134 | .font_weight(FontWeight::SEMIBOLD) |
| 135 | .text_color(theme::text()) |
| 136 | .child(toast.subject.clone()), |
| 137 | ) |
| 138 | .child( |
| 139 | h_flex() |
| 140 | .gap(px(6.)) |
| 141 | .items_center() |
| 142 | .text_size(px(12.5)) |
| 143 | .text_color(theme::text_muted()) |
| 144 | .when(live, |row| { |
| 145 | row.child( |
| 146 | div() |
| 147 | .size(px(LIVE_DOT)) |
| 148 | .flex_none() |
| 149 | .rounded_full() |
| 150 | .bg(theme::green()), |
| 151 | ) |
| 152 | }) |
| 153 | .child(subtitle), |
| 154 | ) |
| 155 | .child(buttons), |
| 156 | ), |
| 157 | ), |
| 158 | ) |
| 159 | .child(dismiss) |
| 160 | .into_any_element() |
| 161 | } |
| 162 | } |