BlueGit

ict rusty-teams

Files

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

calls_tab.rs

calls_tab.rs 17.1 KiB Download Raw
1use chatsvc::{Reply, ResponseType};
2use chrono::{Local, Offset, Utc};
3use gpui_kit::assets::IconName;
4use gpui_kit::component::Sizable as _;
5use gpui_kit::component::button::{Button, ButtonVariants as _};
6use gpui_kit::component::menu::{ContextMenuExt as _, DropdownMenu as _, PopupMenuItem};
7use gpui_kit::component::{h_flex, v_flex};
8use gpui_kit::prelude::FluentBuilder as _;
9use gpui_kit::*;
10
11use super::avatar::person_avatar;
12use super::join_dialog::open_join_with_id;
13use super::new_meeting_dialog::open_new_meeting;
14use super::scroll_edge::{scroll_offset, with_top_edge};
15use super::sidebar::SIDEBAR_SCROLL_DIVIDER;
16use super::widgets::{icon, menu_icon};
17use crate::app_state::AppState;
18use crate::call::{
19 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT,
20 FILTERS_HEIGHT, HistoryFilter, ListEntry, SECTION_HEIGHT, join_available, response_label,
21};
22use crate::theme;
23
24const FALLBACK_VIEWPORT: f32 = 900.;
25const VIEWPORT_MARGIN: f32 = 300.;
26const TIME_COLUMN_WIDTH: f32 = 96.;
27const AVATAR_SIZE: f32 = 36.;
28
29fn meeting_avatar() -> Div {
30 div()
31 .size(px(AVATAR_SIZE))
32 .flex_none()
33 .flex()
34 .items_center()
35 .justify_center()
36 .rounded_full()
37 .bg(theme::border_strong())
38 .child(icon(IconName::Video, 16., theme::text()))
39}
40
41fn call_row(
42 state: &Entity<AppState>,
43 row: &CallRow,
44 can_open_chat: bool,
45 directory: &crate::data::Directory,
46) -> AnyElement {
47 let avatar = if row.meeting {
48 meeting_avatar().into_any_element()
49 } else {
50 person_avatar(directory, row.user_id.as_deref(), &row.title, AVATAR_SIZE)
51 };
52 let title_color = if row.missed {
53 theme::red_soft()
54 } else {
55 theme::text()
56 };
57 let click_state = state.clone();
58 let click_row = row.clone();
59 let menu_state = state.clone();
60 let menu_row = row.clone();
61 let can_call_back = !row.meeting && row.user_id.is_some();
62 h_flex()
63 .id(SharedString::from(format!("call-{}", row.key)))
64 .mx(px(6.))
65 .h(px(CALL_ROW_HEIGHT))
66 .flex_none()
67 .px(px(10.))
68 .gap(px(12.))
69 .items_center()
70 .rounded(px(8.))
71 .cursor_pointer()
72 .hover(|row| row.bg(theme::row_hover()))
73 .child(avatar)
74 .child(
75 v_flex()
76 .flex_1()
77 .min_w_0()
78 .gap(px(2.))
79 .child(
80 h_flex()
81 .gap(px(8.))
82 .items_baseline()
83 .child(
84 div()
85 .flex_1()
86 .min_w_0()
87 .truncate()
88 .text_size(px(14.))
89 .text_color(title_color)
90 .child(row.title.clone()),
91 )
92 .child(
93 div()
94 .flex_none()
95 .text_size(px(11.))
96 .text_color(theme::text_muted())
97 .child(row.time_label.clone()),
98 ),
99 )
100 .child(
101 div()
102 .truncate()
103 .text_size(px(12.5))
104 .text_color(if row.missed {
105 theme::red_soft()
106 } else {
107 theme::text_muted()
108 })
109 .child(row.subline.clone()),
110 ),
111 )
112 .on_click(move |_, _, cx| {
113 click_state.update(cx, |state, cx| state.activate_call_row(&click_row, cx));
114 })
115 .context_menu(move |popup, _, _| {
116 let call_state = menu_state.clone();
117 let call_row = menu_row.clone();
118 let chat_state = menu_state.clone();
119 let chat_row = menu_row.clone();
120 popup
121 .when(can_call_back, |popup| {
122 popup.item(
123 PopupMenuItem::new("Call back")
124 .icon(menu_icon(IconName::Phone))
125 .on_click(move |_, _, cx| {
126 call_state.update(cx, |state, cx| {
127 state.call_back_from_history(&call_row, cx)
128 });
129 }),
130 )
131 })
132 .when(can_open_chat, |popup| {
133 popup.item(
134 PopupMenuItem::new("Open chat")
135 .icon(menu_icon(IconName::MessageSquare))
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 (
152 theme::surface_raised(),
153 theme::popup_hover(),
154 theme::text_strong(),
155 )
156 };
157 div()
158 .id(id)
159 .h(px(28.))
160 .px(px(12.))
161 .flex()
162 .items_center()
163 .rounded(px(7.))
164 .bg(fill)
165 .cursor_pointer()
166 .hover(move |button| button.bg(hover_fill))
167 .text_size(px(12.5))
168 .font_weight(FontWeight::SEMIBOLD)
169 .text_color(text_color)
170 .child(label)
171}
172
173fn join_buttons(state: &Entity<AppState>, meet_now_pending: bool) -> impl IntoElement {
174 let meet_state = state.clone();
175 let new_state = state.clone();
176 let id_state = state.clone();
177 let paste_state = state.clone();
178 h_flex()
179 .debug_selector(|| "shell/islands/sidebar/calls-actions".into())
180 .w_full()
181 .px(px(16.))
182 .pb(px(8.))
183 .gap(px(8.))
184 .flex_wrap()
185 .child(
186 join_button("meet-now", "Meet now", true)
187 .debug_selector(|| "shell/islands/sidebar/calls-actions/meet-now".into())
188 .when(meet_now_pending, |button| button.opacity(0.5))
189 .when(!meet_now_pending, |button| {
190 button.on_click(move |_, _, cx| {
191 meet_state.update(cx, |state, cx| state.start_meet_now(cx));
192 })
193 }),
194 )
195 .child(
196 join_button("new-meeting", "New meeting", false)
197 .debug_selector(|| "shell/islands/sidebar/calls-actions/new-meeting".into())
198 .on_click(move |_, window, cx| open_new_meeting(new_state.clone(), window, cx)),
199 )
200 .child(
201 join_button("join-with-id", "Join with ID", false)
202 .on_click(move |_, window, cx| open_join_with_id(id_state.clone(), window, cx)),
203 )
204 .child(
205 join_button("paste-meeting-link", "Paste a meeting link", false).on_click(
206 move |_, _, cx| {
207 paste_state.update(cx, |state, cx| state.join_meeting_from_clipboard(cx));
208 },
209 ),
210 )
211}
212
213fn section_header(title: &'static str) -> AnyElement {
214 div()
215 .h(px(SECTION_HEIGHT))
216 .px(px(16.))
217 .flex()
218 .items_end()
219 .pb(px(4.))
220 .text_size(px(12.))
221 .font_weight(FontWeight::SEMIBOLD)
222 .text_color(theme::text_muted())
223 .child(title)
224 .into_any_element()
225}
226
227fn history_filters(state: &Entity<AppState>, current: HistoryFilter) -> AnyElement {
228 let pills = HistoryFilter::ALL.into_iter().map(|filter| {
229 let selected = filter == current;
230 let state = state.clone();
231 div()
232 .id(SharedString::from(format!("calls-filter-{}", filter.label())))
233 .h(px(24.))
234 .px(px(10.))
235 .flex()
236 .flex_none()
237 .items_center()
238 .rounded_full()
239 .cursor_pointer()
240 .text_size(px(12.))
241 .when(selected, |pill| {
242 pill.bg(theme::accent()).text_color(theme::on_accent())
243 })
244 .when(!selected, |pill| {
245 pill.bg(theme::surface_raised())
246 .text_color(theme::text_soft())
247 .hover(|pill| pill.bg(theme::border_strong()))
248 })
249 .child(filter.label())
250 .on_click(move |_, _, cx| {
251 state.update(cx, |state, cx| state.set_call_history_filter(filter, cx))
252 })
253 });
254 h_flex()
255 .h(px(FILTERS_HEIGHT))
256 .px(px(16.))
257 .gap(px(6.))
258 .items_center()
259 .children(pills)
260 .into_any_element()
261}
262
263fn day_header(label: &str) -> AnyElement {
264 div()
265 .h(px(DAY_HEIGHT))
266 .px(px(16.))
267 .flex()
268 .items_center()
269 .text_size(px(11.5))
270 .text_color(theme::text_faint())
271 .child(label.to_owned())
272 .into_any_element()
273}
274
275fn empty_row(text: &'static str) -> AnyElement {
276 div()
277 .h(px(EMPTY_HEIGHT))
278 .flex()
279 .items_center()
280 .justify_center()
281 .text_size(px(13.))
282 .text_color(theme::text_muted())
283 .child(text)
284 .into_any_element()
285}
286
287fn rsvp_menu_item(
288 state: &Entity<AppState>,
289 event_key: &str,
290 label: &'static str,
291 reply: Reply,
292 chosen: bool,
293) -> PopupMenuItem {
294 let state = state.clone();
295 let event_key = event_key.to_owned();
296 PopupMenuItem::new(label)
297 .checked(chosen)
298 .on_click(move |_, _, cx| {
299 state.update(cx, |state, cx| {
300 state.respond_to_event(&event_key, reply, cx)
301 });
302 })
303}
304
305fn rsvp_control(state: &Entity<AppState>, row: &AgendaRow, send_response: bool) -> AnyElement {
306 let menu_state = state.clone();
307 let key = row.key.clone();
308 let response = row.response;
309 div()
310 .id(SharedString::from(format!("agenda-rsvp-{}", row.key)))
311 .flex_none()
312 .on_click(|_, _, cx| cx.stop_propagation())
313 .child(
314 Button::new(SharedString::from(format!(
315 "agenda-rsvp-button-{}",
316 row.key
317 )))
318 .xsmall()
319 .outline()
320 .label(response_label(response))
321 .icon(IconName::ChevronDown)
322 .dropdown_menu(move |menu, _, _| {
323 let toggle_state = menu_state.clone();
324 menu.item(rsvp_menu_item(
325 &menu_state,
326 &key,
327 "Accept",
328 Reply::Accept,
329 response == ResponseType::Accepted,
330 ))
331 .item(rsvp_menu_item(
332 &menu_state,
333 &key,
334 "Tentative",
335 Reply::Tentative,
336 response == ResponseType::Tentative,
337 ))
338 .item(rsvp_menu_item(
339 &menu_state,
340 &key,
341 "Decline",
342 Reply::Decline,
343 response == ResponseType::Declined,
344 ))
345 .separator()
346 .item(
347 PopupMenuItem::new("Send a response")
348 .checked(send_response)
349 .on_click(move |_, _, cx| {
350 toggle_state
351 .update(cx, |state, cx| state.toggle_rsvp_send_response(cx));
352 }),
353 )
354 }),
355 )
356 .into_any_element()
357}
358
359fn agenda_row(
360 state: &Entity<AppState>,
361 row: &AgendaRow,
362 joinable: bool,
363 send_response: bool,
364) -> AnyElement {
365 let click_state = state.clone();
366 let click_row = row.clone();
367 let join_state = state.clone();
368 let join_row = row.clone();
369 let menu_join_url = row.join_url.clone();
370 let line = h_flex()
371 .id(SharedString::from(format!("agenda-{}", row.key)))
372 .mx(px(6.))
373 .h(px(AGENDA_ROW_HEIGHT))
374 .flex_none()
375 .px(px(10.))
376 .gap(px(12.))
377 .items_center()
378 .rounded(px(8.))
379 .cursor_pointer()
380 .hover(|row| row.bg(theme::row_hover()))
381 .child(
382 div()
383 .w(px(TIME_COLUMN_WIDTH))
384 .flex_none()
385 .text_size(px(12.))
386 .text_color(theme::text_muted())
387 .child(row.time_label.clone()),
388 )
389 .child(
390 v_flex()
391 .flex_1()
392 .min_w_0()
393 .gap(px(2.))
394 .child(
395 div()
396 .truncate()
397 .text_size(px(14.))
398 .text_color(theme::text())
399 .child(row.subject.clone()),
400 )
401 .when(!row.detail.is_empty() || row.can_respond, |column| {
402 column.child(
403 h_flex()
404 .gap(px(6.))
405 .items_center()
406 .child(
407 div()
408 .flex_1()
409 .min_w_0()
410 .truncate()
411 .text_size(px(12.5))
412 .text_color(theme::text_muted())
413 .child(row.detail.clone()),
414 )
415 .when(row.can_respond, |line| {
416 line.child(rsvp_control(state, row, send_response))
417 }),
418 )
419 }),
420 )
421 .when(joinable, |line| {
422 line.child(
423 Button::new(SharedString::from(format!("agenda-join-{}", row.key)))
424 .small()
425 .primary()
426 .label("Join")
427 .on_click(move |_, _, cx| {
428 cx.stop_propagation();
429 join_state.update(cx, |state, cx| state.join_agenda_row(&join_row, cx));
430 }),
431 )
432 })
433 .on_click(move |_, _, cx| {
434 click_state.update(cx, |state, cx| state.open_agenda_chat(&click_row, cx));
435 });
436 let Some(join_url) = menu_join_url else {
437 return line.into_any_element();
438 };
439 line.context_menu(move |popup, _, _| {
440 let join_url = join_url.clone();
441 popup.item(
442 PopupMenuItem::new("Copy meeting link")
443 .icon(menu_icon(IconName::Link))
444 .on_click(move |_, _, cx| {
445 cx.write_to_clipboard(ClipboardItem::new_string(join_url.clone()));
446 }),
447 )
448 })
449 .into_any_element()
450}
451
452pub fn calls_body(
453 state: &Entity<AppState>,
454 scroll: &ScrollHandle,
455 window_height: f32,
456 cx: &mut App,
457) -> AnyElement {
458 let now = Utc::now();
459 let offset = Local::now().offset().fix();
460 if state.read(cx).calls_list.needs_rebuild(now, offset) {
461 let rebuild_state = state.clone();
462 cx.defer(move |cx| rebuild_state.update(cx, |state, cx| state.rebuild_calls_list(cx)));
463 }
464 let top = -f32::from(scroll_offset(scroll).y);
465 let measured = f32::from(scroll.bounds().size.height);
466 let height = if measured > 1. {
467 measured
468 } else {
469 window_height.max(FALLBACK_VIEWPORT)
470 };
471 let app = state.read(cx);
472 let window = app
473 .calls_list
474 .window(top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);
475 let entries = &app.calls_list.entries()[window.range.clone()];
476 let mut list = v_flex().w_full().pb(px(12.));
477 if window.before > 0. {
478 list = list.child(div().h(px(window.before)).flex_none());
479 }
480 for entry in entries {
481 list = list.child(match entry {
482 ListEntry::Section(title) => section_header(title),
483 ListEntry::Filters(filter) => history_filters(state, *filter),
484 ListEntry::Day(label) => day_header(label),
485 ListEntry::Empty(text) => empty_row(text),
486 ListEntry::Agenda(row) => agenda_row(
487 state,
488 row,
489 join_available(row.start, row.end, now) && row.join_url.is_some(),
490 app.rsvp_send_response,
491 ),
492 ListEntry::Call(row) => call_row(
493 state,
494 row,
495 app.can_open_chat_of_call_row(row),
496 &app.directory,
497 ),
498 });
499 }
500 if window.after > 0. {
501 list = list.child(div().h(px(window.after)).flex_none());
502 }
503 v_flex()
504 .flex_1()
505 .min_h_0()
506 .child(join_buttons(state, app.meet_now_pending))
507 .child(with_top_edge(
508 div()
509 .id("calls-scroll")
510 .flex_1()
511 .min_h_0()
512 .overflow_y_scroll()
513 .track_scroll(scroll)
514 .child(list),
515 scroll,
516 SIDEBAR_SCROLL_DIVIDER,
517 ))
518 .into_any_element()
519}