BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / views / calls_tab.rs

calls_tab.rs

calls_tab.rs 11.8 KiB Download Raw
1use chrono::{Local, Offset, Utc};
2use gpui_kit::assets::IconName;
3use gpui_kit::component::Sizable as _;
4use gpui_kit::component::button::{Button, ButtonVariants as _};
5use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
6use gpui_kit::component::{h_flex, v_flex};
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9
10use super::avatar::person_avatar;
11use super::join_dialog::open_join_with_id;
12use super::widgets::icon;
13use crate::app_state::AppState;
14use crate::call::{
15 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT, ListEntry,
16 SECTION_HEIGHT, join_available,
17};
18use crate::theme;
19
20const FALLBACK_VIEWPORT: f32 = 900.;
21const VIEWPORT_MARGIN: f32 = 300.;
22const TIME_COLUMN_WIDTH: f32 = 96.;
23const AVATAR_SIZE: f32 = 36.;
24const MENU_ICON_SIZE: f32 = 15.;
25
26fn meeting_avatar() -> Div {
27 div()
28 .size(px(AVATAR_SIZE))
29 .flex_none()
30 .flex()
31 .items_center()
32 .justify_center()
33 .rounded_full()
34 .bg(theme::border_strong())
35 .child(icon(IconName::Video, 16., theme::text()))
36}
37
38fn call_row(
39 state: &Entity<AppState>,
40 row: &CallRow,
41 can_open_chat: bool,
42 directory: &crate::data::Directory,
43) -> AnyElement {
44 let avatar = if row.meeting {
45 meeting_avatar().into_any_element()
46 } else {
47 person_avatar(directory, row.user_id.as_deref(), &row.title, AVATAR_SIZE)
48 };
49 let title_color = if row.missed {
50 theme::red_soft()
51 } else {
52 theme::text()
53 };
54 let click_state = state.clone();
55 let click_row = row.clone();
56 let menu_state = state.clone();
57 let menu_row = row.clone();
58 let can_call_back = !row.meeting && row.user_id.is_some();
59 h_flex()
60 .id(SharedString::from(format!("call-{}", row.key)))
61 .mx(px(6.))
62 .h(px(CALL_ROW_HEIGHT))
63 .px(px(10.))
64 .gap(px(12.))
65 .items_center()
66 .rounded(px(8.))
67 .cursor_pointer()
68 .hover(|row| row.bg(theme::row_hover()))
69 .child(avatar)
70 .child(
71 v_flex()
72 .flex_1()
73 .min_w_0()
74 .gap(px(2.))
75 .child(
76 h_flex()
77 .gap(px(8.))
78 .items_baseline()
79 .child(
80 div()
81 .flex_1()
82 .min_w_0()
83 .truncate()
84 .text_size(px(14.))
85 .text_color(title_color)
86 .child(row.title.clone()),
87 )
88 .child(
89 div()
90 .flex_none()
91 .text_size(px(11.))
92 .text_color(theme::text_muted())
93 .child(row.time_label.clone()),
94 ),
95 )
96 .child(
97 div()
98 .truncate()
99 .text_size(px(12.5))
100 .text_color(if row.missed {
101 theme::red_soft()
102 } else {
103 theme::text_muted()
104 })
105 .child(row.subline.clone()),
106 ),
107 )
108 .on_click(move |_, _, cx| {
109 click_state.update(cx, |state, cx| state.activate_call_row(&click_row, cx));
110 })
111 .context_menu(move |popup, _, _| {
112 let call_state = menu_state.clone();
113 let call_row = menu_row.clone();
114 let chat_state = menu_state.clone();
115 let chat_row = menu_row.clone();
116 popup
117 .when(can_call_back, |popup| {
118 popup.item(
119 PopupMenuItem::new("Call back")
120 .icon(icon(IconName::Phone, MENU_ICON_SIZE, theme::text_muted()))
121 .on_click(move |_, _, cx| {
122 call_state.update(cx, |state, cx| {
123 state.call_back_from_history(&call_row, cx)
124 });
125 }),
126 )
127 })
128 .when(can_open_chat, |popup| {
129 popup.item(
130 PopupMenuItem::new("Open chat")
131 .icon(icon(
132 IconName::MessageSquare,
133 MENU_ICON_SIZE,
134 theme::text_muted(),
135 ))
136 .on_click(move |_, _, cx| {
137 chat_state.update(cx, |state, cx| {
138 state.open_chat_of_call_row(&chat_row, cx)
139 });
140 }),
141 )
142 })
143 })
144 .into_any_element()
145}
146
147fn join_button(id: &'static str, label: &'static str, primary: bool) -> Stateful<Div> {
148 let (fill, hover_fill, text_color) = if primary {
149 (theme::accent(), theme::accent_text(), theme::on_accent())
150 } else {
151 (theme::surface_raised(), theme::popup_hover(), theme::text_strong())
152 };
153 div()
154 .id(id)
155 .h(px(28.))
156 .px(px(12.))
157 .flex()
158 .items_center()
159 .rounded(px(7.))
160 .bg(fill)
161 .cursor_pointer()
162 .hover(move |button| button.bg(hover_fill))
163 .text_size(px(12.5))
164 .font_weight(FontWeight::SEMIBOLD)
165 .text_color(text_color)
166 .child(label)
167}
168
169fn join_buttons(state: &Entity<AppState>, meet_now_pending: bool) -> impl IntoElement {
170 let meet_state = state.clone();
171 let id_state = state.clone();
172 let paste_state = state.clone();
173 h_flex()
174 .w_full()
175 .px(px(16.))
176 .pb(px(8.))
177 .gap(px(8.))
178 .flex_wrap()
179 .child(
180 join_button("meet-now", "Meet now", true)
181 .when(meet_now_pending, |button| button.opacity(0.5))
182 .when(!meet_now_pending, |button| {
183 button.on_click(move |_, _, cx| {
184 meet_state.update(cx, |state, cx| state.start_meet_now(cx));
185 })
186 }),
187 )
188 .child(
189 join_button("join-with-id", "Join with ID", false)
190 .on_click(move |_, window, cx| open_join_with_id(id_state.clone(), window, cx)),
191 )
192 .child(
193 join_button("paste-meeting-link", "Paste a meeting link", false).on_click(
194 move |_, _, cx| {
195 paste_state.update(cx, |state, cx| state.join_meeting_from_clipboard(cx));
196 },
197 ),
198 )
199}
200
201fn section_header(title: &'static str) -> AnyElement {
202 div()
203 .h(px(SECTION_HEIGHT))
204 .px(px(16.))
205 .flex()
206 .items_end()
207 .pb(px(4.))
208 .text_size(px(12.))
209 .font_weight(FontWeight::SEMIBOLD)
210 .text_color(theme::text_muted())
211 .child(title)
212 .into_any_element()
213}
214
215fn day_header(label: &str) -> AnyElement {
216 div()
217 .h(px(DAY_HEIGHT))
218 .px(px(16.))
219 .flex()
220 .items_center()
221 .text_size(px(11.5))
222 .text_color(theme::text_faint())
223 .child(label.to_owned())
224 .into_any_element()
225}
226
227fn empty_row(text: &'static str) -> AnyElement {
228 div()
229 .h(px(EMPTY_HEIGHT))
230 .flex()
231 .items_center()
232 .justify_center()
233 .text_size(px(13.))
234 .text_color(theme::text_muted())
235 .child(text)
236 .into_any_element()
237}
238
239fn agenda_row(state: &Entity<AppState>, row: &AgendaRow, joinable: bool) -> AnyElement {
240 let click_state = state.clone();
241 let click_row = row.clone();
242 let join_state = state.clone();
243 let join_row = row.clone();
244 h_flex()
245 .id(SharedString::from(format!("agenda-{}", row.key)))
246 .mx(px(6.))
247 .h(px(AGENDA_ROW_HEIGHT))
248 .px(px(10.))
249 .gap(px(12.))
250 .items_center()
251 .rounded(px(8.))
252 .cursor_pointer()
253 .hover(|row| row.bg(theme::row_hover()))
254 .child(
255 div()
256 .w(px(TIME_COLUMN_WIDTH))
257 .flex_none()
258 .text_size(px(12.))
259 .text_color(theme::text_muted())
260 .child(row.time_label.clone()),
261 )
262 .child(
263 v_flex()
264 .flex_1()
265 .min_w_0()
266 .gap(px(2.))
267 .child(
268 div()
269 .truncate()
270 .text_size(px(14.))
271 .text_color(theme::text())
272 .child(row.subject.clone()),
273 )
274 .when(!row.detail.is_empty(), |column| {
275 column.child(
276 div()
277 .truncate()
278 .text_size(px(12.5))
279 .text_color(theme::text_muted())
280 .child(row.detail.clone()),
281 )
282 }),
283 )
284 .when(joinable, |line| {
285 line.child(
286 Button::new(SharedString::from(format!("agenda-join-{}", row.key)))
287 .small()
288 .primary()
289 .label("Join")
290 .on_click(move |_, _, cx| {
291 cx.stop_propagation();
292 join_state.update(cx, |state, cx| state.join_agenda_row(&join_row, cx));
293 }),
294 )
295 })
296 .on_click(move |_, _, cx| {
297 click_state.update(cx, |state, cx| state.open_agenda_chat(&click_row, cx));
298 })
299 .into_any_element()
300}
301
302pub fn calls_body(
303 state: &Entity<AppState>,
304 scroll: &ScrollHandle,
305 window_height: f32,
306 cx: &mut App,
307) -> AnyElement {
308 let now = Utc::now();
309 let offset = Local::now().offset().fix();
310 if state.read(cx).calls_list.needs_rebuild(now, offset) {
311 let rebuild_state = state.clone();
312 cx.defer(move |cx| rebuild_state.update(cx, |state, cx| state.rebuild_calls_list(cx)));
313 }
314 let top = -f32::from(scroll.offset().y);
315 let measured = f32::from(scroll.bounds().size.height);
316 let height = if measured > 1. {
317 measured
318 } else {
319 window_height.max(FALLBACK_VIEWPORT)
320 };
321 let app = state.read(cx);
322 let window = app
323 .calls_list
324 .window(top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);
325 let entries = &app.calls_list.entries()[window.range.clone()];
326 let mut list = v_flex().w_full().pb(px(12.));
327 if window.before > 0. {
328 list = list.child(div().h(px(window.before)).flex_none());
329 }
330 for entry in entries {
331 list = list.child(match entry {
332 ListEntry::Section(title) => section_header(title),
333 ListEntry::Day(label) => day_header(label),
334 ListEntry::Empty(text) => empty_row(text),
335 ListEntry::Agenda(row) => {
336 agenda_row(state, row, join_available(row.start, row.end, now) && row.join_url.is_some())
337 }
338 ListEntry::Call(row) => call_row(
339 state,
340 row,
341 app.can_open_chat_of_call_row(row),
342 &app.directory,
343 ),
344 });
345 }
346 if window.after > 0. {
347 list = list.child(div().h(px(window.after)).flex_none());
348 }
349 v_flex()
350 .flex_1()
351 .min_h_0()
352 .child(join_buttons(state, app.meet_now_pending))
353 .child(
354 div()
355 .id("calls-scroll")
356 .flex_1()
357 .min_h_0()
358 .overflow_y_scroll()
359 .track_scroll(scroll)
360 .child(list),
361 )
362 .into_any_element()
363}