BlueGit

ict rusty-teams

Files

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

calls_tab.rs

calls_tab.rs 15.3 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, ListEntry,
20 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 day_header(label: &str) -> AnyElement {
228 div()
229 .h(px(DAY_HEIGHT))
230 .px(px(16.))
231 .flex()
232 .items_center()
233 .text_size(px(11.5))
234 .text_color(theme::text_faint())
235 .child(label.to_owned())
236 .into_any_element()
237}
238
239fn empty_row(text: &'static str) -> AnyElement {
240 div()
241 .h(px(EMPTY_HEIGHT))
242 .flex()
243 .items_center()
244 .justify_center()
245 .text_size(px(13.))
246 .text_color(theme::text_muted())
247 .child(text)
248 .into_any_element()
249}
250
251fn rsvp_menu_item(
252 state: &Entity<AppState>,
253 event_key: &str,
254 label: &'static str,
255 reply: Reply,
256 chosen: bool,
257) -> PopupMenuItem {
258 let state = state.clone();
259 let event_key = event_key.to_owned();
260 PopupMenuItem::new(label)
261 .checked(chosen)
262 .on_click(move |_, _, cx| {
263 state.update(cx, |state, cx| {
264 state.respond_to_event(&event_key, reply, cx)
265 });
266 })
267}
268
269fn rsvp_control(state: &Entity<AppState>, row: &AgendaRow, send_response: bool) -> AnyElement {
270 let menu_state = state.clone();
271 let key = row.key.clone();
272 let response = row.response;
273 div()
274 .id(SharedString::from(format!("agenda-rsvp-{}", row.key)))
275 .flex_none()
276 .on_click(|_, _, cx| cx.stop_propagation())
277 .child(
278 Button::new(SharedString::from(format!(
279 "agenda-rsvp-button-{}",
280 row.key
281 )))
282 .xsmall()
283 .outline()
284 .label(response_label(response))
285 .icon(IconName::ChevronDown)
286 .dropdown_menu(move |menu, _, _| {
287 let toggle_state = menu_state.clone();
288 menu.item(rsvp_menu_item(
289 &menu_state,
290 &key,
291 "Accept",
292 Reply::Accept,
293 response == ResponseType::Accepted,
294 ))
295 .item(rsvp_menu_item(
296 &menu_state,
297 &key,
298 "Tentative",
299 Reply::Tentative,
300 response == ResponseType::Tentative,
301 ))
302 .item(rsvp_menu_item(
303 &menu_state,
304 &key,
305 "Decline",
306 Reply::Decline,
307 response == ResponseType::Declined,
308 ))
309 .separator()
310 .item(
311 PopupMenuItem::new("Send a response")
312 .checked(send_response)
313 .on_click(move |_, _, cx| {
314 toggle_state
315 .update(cx, |state, cx| state.toggle_rsvp_send_response(cx));
316 }),
317 )
318 }),
319 )
320 .into_any_element()
321}
322
323fn agenda_row(
324 state: &Entity<AppState>,
325 row: &AgendaRow,
326 joinable: bool,
327 send_response: bool,
328) -> AnyElement {
329 let click_state = state.clone();
330 let click_row = row.clone();
331 let join_state = state.clone();
332 let join_row = row.clone();
333 h_flex()
334 .id(SharedString::from(format!("agenda-{}", row.key)))
335 .mx(px(6.))
336 .h(px(AGENDA_ROW_HEIGHT))
337 .flex_none()
338 .px(px(10.))
339 .gap(px(12.))
340 .items_center()
341 .rounded(px(8.))
342 .cursor_pointer()
343 .hover(|row| row.bg(theme::row_hover()))
344 .child(
345 div()
346 .w(px(TIME_COLUMN_WIDTH))
347 .flex_none()
348 .text_size(px(12.))
349 .text_color(theme::text_muted())
350 .child(row.time_label.clone()),
351 )
352 .child(
353 v_flex()
354 .flex_1()
355 .min_w_0()
356 .gap(px(2.))
357 .child(
358 div()
359 .truncate()
360 .text_size(px(14.))
361 .text_color(theme::text())
362 .child(row.subject.clone()),
363 )
364 .when(!row.detail.is_empty() || row.can_respond, |column| {
365 column.child(
366 h_flex()
367 .gap(px(6.))
368 .items_center()
369 .child(
370 div()
371 .flex_1()
372 .min_w_0()
373 .truncate()
374 .text_size(px(12.5))
375 .text_color(theme::text_muted())
376 .child(row.detail.clone()),
377 )
378 .when(row.can_respond, |line| {
379 line.child(rsvp_control(state, row, send_response))
380 }),
381 )
382 }),
383 )
384 .when(joinable, |line| {
385 line.child(
386 Button::new(SharedString::from(format!("agenda-join-{}", row.key)))
387 .small()
388 .primary()
389 .label("Join")
390 .on_click(move |_, _, cx| {
391 cx.stop_propagation();
392 join_state.update(cx, |state, cx| state.join_agenda_row(&join_row, cx));
393 }),
394 )
395 })
396 .on_click(move |_, _, cx| {
397 click_state.update(cx, |state, cx| state.open_agenda_chat(&click_row, cx));
398 })
399 .into_any_element()
400}
401
402pub fn calls_body(
403 state: &Entity<AppState>,
404 scroll: &ScrollHandle,
405 window_height: f32,
406 cx: &mut App,
407) -> AnyElement {
408 let now = Utc::now();
409 let offset = Local::now().offset().fix();
410 if state.read(cx).calls_list.needs_rebuild(now, offset) {
411 let rebuild_state = state.clone();
412 cx.defer(move |cx| rebuild_state.update(cx, |state, cx| state.rebuild_calls_list(cx)));
413 }
414 let top = -f32::from(scroll_offset(scroll).y);
415 let measured = f32::from(scroll.bounds().size.height);
416 let height = if measured > 1. {
417 measured
418 } else {
419 window_height.max(FALLBACK_VIEWPORT)
420 };
421 let app = state.read(cx);
422 let window = app
423 .calls_list
424 .window(top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);
425 let entries = &app.calls_list.entries()[window.range.clone()];
426 let mut list = v_flex().w_full().pb(px(12.));
427 if window.before > 0. {
428 list = list.child(div().h(px(window.before)).flex_none());
429 }
430 for entry in entries {
431 list = list.child(match entry {
432 ListEntry::Section(title) => section_header(title),
433 ListEntry::Day(label) => day_header(label),
434 ListEntry::Empty(text) => empty_row(text),
435 ListEntry::Agenda(row) => agenda_row(
436 state,
437 row,
438 join_available(row.start, row.end, now) && row.join_url.is_some(),
439 app.rsvp_send_response,
440 ),
441 ListEntry::Call(row) => call_row(
442 state,
443 row,
444 app.can_open_chat_of_call_row(row),
445 &app.directory,
446 ),
447 });
448 }
449 if window.after > 0. {
450 list = list.child(div().h(px(window.after)).flex_none());
451 }
452 v_flex()
453 .flex_1()
454 .min_h_0()
455 .child(join_buttons(state, app.meet_now_pending))
456 .child(with_top_edge(
457 div()
458 .id("calls-scroll")
459 .flex_1()
460 .min_h_0()
461 .overflow_y_scroll()
462 .track_scroll(scroll)
463 .child(list),
464 scroll,
465 SIDEBAR_SCROLL_DIVIDER,
466 ))
467 .into_any_element()
468}