BlueGit

ict rusty-teams

Files

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

meeting_view.rs

meeting_view.rs 6.1 KiB Download Raw
1use chrono::{Local, Offset, Utc};
2use gpui_kit::assets::IconName;
3use gpui_kit::component::{h_flex, v_flex};
4use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6
7use super::center::NotificationCenter;
8use super::layout::{AVATAR_GAP, TOAST_PADDING};
9use super::ring_view::{RING_AVATAR, answer_button, toast_radius};
10use crate::app_state::AppState;
11use crate::call::ReminderPhase;
12use crate::call::meeting_subtitle;
13use crate::theme;
14use crate::views::widgets::icon;
15
16const MEETING_ICON: f32 = 22.;
17const LIVE_DOT: f32 = 7.;
18const CLOSE_BUTTON: f32 = 24.;
19const CLOSE_INSET: f32 = 8.;
20const CLOSE_CLEARANCE: f32 = 20.;
21
22pub struct MeetingToastView {
23 center: Entity<NotificationCenter>,
24 app: Entity<AppState>,
25 toast_id: u64,
26 _subscriptions: [Subscription; 2],
27}
28
29impl 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(&center, |_, _, cx| cx.notify()),
35 ];
36 MeetingToastView {
37 center,
38 app,
39 toast_id,
40 _subscriptions: subscriptions,
41 }
42 }
43}
44
45impl 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("meeting-join", "Join", IconName::Video, theme::accent(), theme::on_accent())
85 .on_click(move |_, _, cx| {
86 cx.stop_propagation();
87 join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx));
88 });
89 let live = toast.phase == ReminderPhase::Live;
90 let buttons = if toast.phase == ReminderPhase::Soon {
91 h_flex().mt(px(8.)).gap(px(6.)).child(snooze).child(join)
92 } else {
93 h_flex().mt(px(8.)).gap(px(6.)).child(join)
94 };
95 div()
96 .id(("meeting-toast", toast_id))
97 .size_full()
98 .rounded(toast_radius(window))
99 .bg(theme::popup())
100 .overflow_hidden()
101 .child(
102 div().size_full().p(px(TOAST_PADDING)).child(
103 h_flex()
104 .size_full()
105 .gap(px(AVATAR_GAP))
106 .items_start()
107 .child(
108 div()
109 .size(px(RING_AVATAR))
110 .flex_none()
111 .flex()
112 .items_center()
113 .justify_center()
114 .rounded_full()
115 .bg(theme::border_strong())
116 .child(icon(IconName::Video, MEETING_ICON, theme::text())),
117 )
118 .child(
119 v_flex()
120 .flex_1()
121 .min_w_0()
122 .pr(px(CLOSE_CLEARANCE))
123 .gap(px(2.))
124 .child(
125 div()
126 .truncate()
127 .text_size(px(15.))
128 .font_weight(FontWeight::SEMIBOLD)
129 .text_color(theme::text())
130 .child(toast.subject.clone()),
131 )
132 .child(
133 h_flex()
134 .gap(px(6.))
135 .items_center()
136 .text_size(px(12.5))
137 .text_color(theme::text_muted())
138 .when(live, |row| {
139 row.child(
140 div()
141 .size(px(LIVE_DOT))
142 .flex_none()
143 .rounded_full()
144 .bg(theme::green()),
145 )
146 })
147 .child(subtitle),
148 )
149 .child(buttons),
150 ),
151 ),
152 )
153 .child(dismiss)
154 .into_any_element()
155 }
156}