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