BlueGit

ict rusty-teams

Files

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

meeting_view.rs

meeting_view.rs 6.2 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(),
61 )
62 .border_1()
63 .border_color(theme::border_strong())
64 .text_color(theme::text())
65 .on_click(move |_, _, cx| {
66 cx.stop_propagation();
67 snooze_app.update(cx, |state, cx| state.snooze_meeting_toast(toast_id, cx));
68 });
69 let dismiss = div()
70 .id("meeting-dismiss")
71 .absolute()
72 .top(px(CLOSE_INSET))
73 .right(px(CLOSE_INSET))
74 .size(px(CLOSE_BUTTON))
75 .flex()
76 .items_center()
77 .justify_center()
78 .rounded(px(6.))
79 .cursor_pointer()
80 .hover(|button| button.bg(theme::row_hover()))
81 .child(icon(IconName::Close, 14., theme::text_muted()))
82 .on_click(move |_, _, cx| {
83 cx.stop_propagation();
84 dismiss_app.update(cx, |state, cx| state.dismiss_meeting_toast(toast_id, cx));
85 });
86 let join = answer_button("meeting-join", "Join", IconName::Video, theme::accent())
87 .text_color(theme::on_accent())
88 .on_click(move |_, _, cx| {
89 cx.stop_propagation();
90 join_center.update(cx, |center, cx| center.join_meeting_toast(toast_id, cx));
91 });
92 let live = toast.phase == ReminderPhase::Live;
93 let buttons = if toast.phase == ReminderPhase::Soon {
94 h_flex().mt(px(8.)).gap(px(6.)).child(snooze).child(join)
95 } else {
96 h_flex().mt(px(8.)).gap(px(6.)).child(join)
97 };
98 div()
99 .id(("meeting-toast", toast_id))
100 .size_full()
101 .rounded(toast_radius(window))
102 .bg(theme::popup())
103 .overflow_hidden()
104 .child(
105 div().size_full().p(px(TOAST_PADDING)).child(
106 h_flex()
107 .size_full()
108 .gap(px(AVATAR_GAP))
109 .items_start()
110 .child(
111 div()
112 .size(px(RING_AVATAR))
113 .flex_none()
114 .flex()
115 .items_center()
116 .justify_center()
117 .rounded_full()
118 .bg(theme::border_strong())
119 .child(icon(IconName::Video, MEETING_ICON, theme::text())),
120 )
121 .child(
122 v_flex()
123 .flex_1()
124 .min_w_0()
125 .pr(px(CLOSE_CLEARANCE))
126 .gap(px(2.))
127 .child(
128 div()
129 .truncate()
130 .text_size(px(15.))
131 .font_weight(FontWeight::SEMIBOLD)
132 .text_color(theme::text())
133 .child(toast.subject.clone()),
134 )
135 .child(
136 h_flex()
137 .gap(px(6.))
138 .items_center()
139 .text_size(px(12.5))
140 .text_color(theme::text_muted())
141 .when(live, |row| {
142 row.child(
143 div()
144 .size(px(LIVE_DOT))
145 .flex_none()
146 .rounded_full()
147 .bg(theme::green()),
148 )
149 })
150 .child(subtitle),
151 )
152 .child(buttons),
153 ),
154 ),
155 )
156 .child(dismiss)
157 .into_any_element()
158 }
159}