BlueGit

ict rusty-teams

Files

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

meeting_view.rs

meeting_view.rs 6.3 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, RING_BORDER, TOAST_RADIUS, answer_button};
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()
49 .size_full()
50 .bg(theme::surface_raised())
51 .into_any_element();
52 };
53 window.set_window_title(&toast.subject);
54 let subtitle = meeting_subtitle(&toast, Utc::now(), Local::now().offset().fix());
55 let toast_id = self.toast_id;
56 let join_center = self.center.clone();
57 let snooze_app = self.app.clone();
58 let dismiss_app = self.app.clone();
59 let snooze = answer_button(
60 "meeting-snooze",
61 "Snooze",
62 IconName::AlarmClock,
63 theme::surface_raised(),
64 )
65 .border_1()
66 .border_color(theme::border_strong())
67 .text_color(theme::text())
68 .on_click(move |_, _, cx| {
69 cx.stop_propagation();
70 snooze_app.update(cx, |state, cx| state.snooze_meeting_toast(toast_id, cx));
71 });
72 let dismiss = div()
73 .id("meeting-dismiss")
74 .absolute()
75 .top(px(CLOSE_INSET))
76 .right(px(CLOSE_INSET))
77 .size(px(CLOSE_BUTTON))
78 .flex()
79 .items_center()
80 .justify_center()
81 .rounded(px(6.))
82 .cursor_pointer()
83 .hover(|button| button.bg(theme::row_hover()))
84 .child(icon(IconName::Close, 14., theme::text_muted()))
85 .on_click(move |_, _, cx| {
86 cx.stop_propagation();
87 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
88 });
89 let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent())
90 .text_color(theme::on_accent())
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(px(TOAST_RADIUS))
105 .bg(theme::surface_raised())
106 .border(px(RING_BORDER))
107 .border_color(theme::accent())
108 .overflow_hidden()
109 .child(
110 div().size_full().p(px(TOAST_PADDING)).child(
111 h_flex()
112 .size_full()
113 .gap(px(AVATAR_GAP))
114 .items_start()
115 .child(
116 div()
117 .size(px(RING_AVATAR))
118 .flex_none()
119 .flex()
120 .items_center()
121 .justify_center()
122 .rounded_full()
123 .bg(theme::border_strong())
124 .child(icon(IconName::Video, MEETING_ICON, theme::text())),
125 )
126 .child(
127 v_flex()
128 .flex_1()
129 .min_w_0()
130 .pr(px(CLOSE_CLEARANCE))
131 .gap(px(2.))
132 .child(
133 div()
134 .truncate()
135 .text_size(px(15.))
136 .font_weight(FontWeight::SEMIBOLD)
137 .text_color(theme::text())
138 .child(toast.subject.clone()),
139 )
140 .child(
141 h_flex()
142 .gap(px(6.))
143 .items_center()
144 .text_size(px(12.5))
145 .text_color(theme::text_muted())
146 .when(live, |row| {
147 row.child(
148 div()
149 .size(px(LIVE_DOT))
150 .flex_none()
151 .rounded_full()
152 .bg(theme::green()),
153 )
154 })
155 .child(subtitle),
156 )
157 .child(buttons),
158 ),
159 ),
160 )
161 .child(dismiss)
162 .into_any_element()
163 }
164}