| 1 | use gpui_kit::assets::IconName; |
| 2 | use gpui_kit::component::{ |
| 3 | Sizable as _, |
| 4 | button::{Button, ButtonVariants as _}, |
| 5 | h_flex, |
| 6 | menu::{DropdownMenu as _, PopupMenu, PopupMenuItem}, |
| 7 | switch::Switch, |
| 8 | tooltip::Tooltip, |
| 9 | v_flex, |
| 10 | }; |
| 11 | use gpui_kit::prelude::FluentBuilder as _; |
| 12 | use gpui_kit::*; |
| 13 | |
| 14 | use super::avatar::person_avatar; |
| 15 | use super::call_extras::open_invite_picker; |
| 16 | use super::call_organizer::{pill, tile_menu}; |
| 17 | use super::call_view::{BANNER_HEIGHT, CHAT_PANEL_WIDTH, MENU_WIDTH, round_control}; |
| 18 | use super::widgets::{Corner, corner_badge, count_badge, icon}; |
| 19 | use crate::app_state::AppState; |
| 20 | use crate::call::{ |
| 21 | ActiveCall, CallModel, OptionsDialog, PeopleSections, PersonRow, people_sections, |
| 22 | }; |
| 23 | use crate::notice::truncated; |
| 24 | use crate::theme; |
| 25 | use calling::MeetingOptions; |
| 26 | |
| 27 | const HEADER_HEIGHT: f32 = 48.; |
| 28 | const ROW_HEIGHT: f32 = 44.; |
| 29 | const AVATAR_SIZE: f32 = 28.; |
| 30 | const MORE_SIZE: f32 = 24.; |
| 31 | const SECTION_HEIGHT: f32 = 32.; |
| 32 | const NAME_LIMIT: usize = 26; |
| 33 | const STATE_ICON: f32 = 15.; |
| 34 | const DIALOG_WIDTH: f32 = 460.; |
| 35 | const DIALOG_BACKDROP: f32 = 0.55; |
| 36 | const FIELD_HEIGHT: f32 = 36.; |
| 37 | const DROPDOWN_WIDTH: f32 = 210.; |
| 38 | |
| 39 | fn dark_text() -> Hsla { |
| 40 | hsla(0., 0., 0.08, 1.) |
| 41 | } |
| 42 | |
| 43 | pub fn people_button(app: &Entity<AppState>, open: bool, raised_hands: usize) -> Stateful<Div> { |
| 44 | let app = app.clone(); |
| 45 | let (background, foreground) = if open { |
| 46 | (theme::accent(), theme::on_accent()) |
| 47 | } else { |
| 48 | (theme::surface_raised(), theme::text()) |
| 49 | }; |
| 50 | round_control("call-people", IconName::Users, background, foreground) |
| 51 | .relative() |
| 52 | .tooltip(move |window, cx| { |
| 53 | Tooltip::new(if open { "Close the people list" } else { "Show people" }).build(window, cx) |
| 54 | }) |
| 55 | .when(raised_hands > 0, |button| { |
| 56 | button.child( |
| 57 | corner_badge(Corner::TopRight, 4.).child(count_badge(raised_hands as u32, false)), |
| 58 | ) |
| 59 | }) |
| 60 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.toggle_call_people(cx))) |
| 61 | } |
| 62 | |
| 63 | pub fn lock_chip(model: &CallModel) -> Option<AnyElement> { |
| 64 | model.capability.locked.then(|| { |
| 65 | h_flex() |
| 66 | .id("call-lock-chip") |
| 67 | .h(px(24.)) |
| 68 | .px(px(8.)) |
| 69 | .gap(px(4.)) |
| 70 | .flex_none() |
| 71 | .items_center() |
| 72 | .rounded_full() |
| 73 | .bg(theme::amber()) |
| 74 | .text_color(dark_text()) |
| 75 | .text_size(px(12.)) |
| 76 | .font_weight(FontWeight::SEMIBOLD) |
| 77 | .child(icon(IconName::Lock, 13., dark_text())) |
| 78 | .child("Locked") |
| 79 | .into_any_element() |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | pub fn lock_banner(app: &Entity<AppState>, model: &CallModel) -> Option<AnyElement> { |
| 84 | if !model.capability.locked || !model.organizes_meeting() { |
| 85 | return None; |
| 86 | } |
| 87 | let app = app.clone(); |
| 88 | Some( |
| 89 | h_flex() |
| 90 | .id("call-lock-banner") |
| 91 | .w_full() |
| 92 | .h(px(BANNER_HEIGHT)) |
| 93 | .flex_none() |
| 94 | .px(px(20.)) |
| 95 | .gap(px(12.)) |
| 96 | .items_center() |
| 97 | .justify_center() |
| 98 | .bg(theme::surface_raised()) |
| 99 | .text_color(theme::text()) |
| 100 | .text_size(px(13.)) |
| 101 | .font_weight(FontWeight::SEMIBOLD) |
| 102 | .child("The meeting is locked. Nobody new can join.") |
| 103 | .child( |
| 104 | pill("call-lock-unlock", "Unlock", false) |
| 105 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.set_call_lock(false, cx))), |
| 106 | ) |
| 107 | .into_any_element(), |
| 108 | ) |
| 109 | } |
| 110 | |
| 111 | fn people_menu(popup: PopupMenu, app: &Entity<AppState>, model: &CallModel) -> PopupMenu { |
| 112 | let popup = popup.min_w(px(MENU_WIDTH)); |
| 113 | if !model.organizes_meeting() { |
| 114 | return popup; |
| 115 | } |
| 116 | let capability = model.capability; |
| 117 | let (mute_app, lock_app, mic_app, camera_app, options_app) = |
| 118 | (app.clone(), app.clone(), app.clone(), app.clone(), app.clone()); |
| 119 | popup |
| 120 | .item( |
| 121 | PopupMenuItem::new("Mute all") |
| 122 | .icon(IconName::MicOff) |
| 123 | .on_click(move |_, _, cx| mute_app.update(cx, |state, cx| state.mute_all_call(cx))), |
| 124 | ) |
| 125 | .item( |
| 126 | PopupMenuItem::new(if capability.locked { "Unlock meeting" } else { "Lock meeting" }) |
| 127 | .icon(if capability.locked { IconName::LockOpen } else { IconName::Lock }) |
| 128 | .on_click(move |_, _, cx| { |
| 129 | lock_app.update(cx, |state, cx| state.set_call_lock(!capability.locked, cx)) |
| 130 | }), |
| 131 | ) |
| 132 | .item( |
| 133 | PopupMenuItem::new(if capability.attendee_mic_off { |
| 134 | "Allow mic for attendees" |
| 135 | } else { |
| 136 | "Disable mic for attendees" |
| 137 | }) |
| 138 | .icon(IconName::MicOff) |
| 139 | .on_click(move |_, _, cx| { |
| 140 | mic_app.update(cx, |state, cx| { |
| 141 | state.set_call_attendee_restrictions( |
| 142 | !capability.attendee_mic_off, |
| 143 | capability.attendee_camera_off, |
| 144 | cx, |
| 145 | ) |
| 146 | }) |
| 147 | }), |
| 148 | ) |
| 149 | .item( |
| 150 | PopupMenuItem::new(if capability.attendee_camera_off { |
| 151 | "Allow camera for attendees" |
| 152 | } else { |
| 153 | "Disable camera for attendees" |
| 154 | }) |
| 155 | .icon(IconName::VideoOff) |
| 156 | .on_click(move |_, _, cx| { |
| 157 | camera_app.update(cx, |state, cx| { |
| 158 | state.set_call_attendee_restrictions( |
| 159 | capability.attendee_mic_off, |
| 160 | !capability.attendee_camera_off, |
| 161 | cx, |
| 162 | ) |
| 163 | }) |
| 164 | }), |
| 165 | ) |
| 166 | .separator() |
| 167 | .item( |
| 168 | PopupMenuItem::new("Meeting options...") |
| 169 | .icon(IconName::Settings) |
| 170 | .on_click(move |_, _, cx| { |
| 171 | options_app.update(cx, |state, cx| state.open_meeting_options(cx)) |
| 172 | }), |
| 173 | ) |
| 174 | } |
| 175 | |
| 176 | fn has_people_menu(model: &CallModel) -> bool { |
| 177 | model.organizes_meeting() |
| 178 | } |
| 179 | |
| 180 | fn panel_header(app: &Entity<AppState>, model: &CallModel, count: usize) -> Div { |
| 181 | let (invite_app, menu_app, close_app) = (app.clone(), app.clone(), app.clone()); |
| 182 | let menu_model = model.clone(); |
| 183 | h_flex() |
| 184 | .w_full() |
| 185 | .h(px(HEADER_HEIGHT)) |
| 186 | .flex_none() |
| 187 | .pl(px(20.)) |
| 188 | .pr(px(12.)) |
| 189 | .gap(px(8.)) |
| 190 | .items_center() |
| 191 | .child( |
| 192 | div() |
| 193 | .flex_1() |
| 194 | .min_w_0() |
| 195 | .truncate() |
| 196 | .text_size(px(15.)) |
| 197 | .font_weight(FontWeight::SEMIBOLD) |
| 198 | .child(format!("People ({count})")), |
| 199 | ) |
| 200 | .when(model.can_invite(), |header| { |
| 201 | header.child( |
| 202 | Button::new("call-people-invite") |
| 203 | .label("Invite") |
| 204 | .icon(IconName::UserPlus) |
| 205 | .xsmall() |
| 206 | .on_click(move |_, window, cx| open_invite_picker(&invite_app, window, cx)), |
| 207 | ) |
| 208 | }) |
| 209 | .when(has_people_menu(model), |header| { |
| 210 | header.child( |
| 211 | Button::new("call-people-more") |
| 212 | .icon(IconName::Ellipsis) |
| 213 | .ghost() |
| 214 | .xsmall() |
| 215 | .tooltip("More") |
| 216 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 217 | people_menu(popup, &menu_app, &menu_model) |
| 218 | }), |
| 219 | ) |
| 220 | }) |
| 221 | .child( |
| 222 | div() |
| 223 | .id("call-people-close") |
| 224 | .size(px(28.)) |
| 225 | .flex() |
| 226 | .flex_none() |
| 227 | .items_center() |
| 228 | .justify_center() |
| 229 | .rounded(px(7.)) |
| 230 | .cursor_pointer() |
| 231 | .hover(|button| button.bg(theme::row_hover())) |
| 232 | .tooltip(|window, cx| Tooltip::new("Close the people list").build(window, cx)) |
| 233 | .child(icon(IconName::Close, 14., theme::text_muted())) |
| 234 | .on_click(move |_, _, cx| close_app.update(cx, |state, cx| state.toggle_call_people(cx))), |
| 235 | ) |
| 236 | } |
| 237 | |
| 238 | fn section_header(title: String, action: Option<AnyElement>) -> Div { |
| 239 | h_flex() |
| 240 | .w_full() |
| 241 | .h(px(SECTION_HEIGHT)) |
| 242 | .flex_none() |
| 243 | .px(px(20.)) |
| 244 | .items_center() |
| 245 | .justify_between() |
| 246 | .text_size(px(12.)) |
| 247 | .font_weight(FontWeight::SEMIBOLD) |
| 248 | .text_color(theme::text_muted()) |
| 249 | .child(title) |
| 250 | .children(action) |
| 251 | } |
| 252 | |
| 253 | fn hand_badge(position: usize) -> Div { |
| 254 | h_flex() |
| 255 | .h(px(20.)) |
| 256 | .px(px(6.)) |
| 257 | .gap(px(3.)) |
| 258 | .flex_none() |
| 259 | .items_center() |
| 260 | .rounded_full() |
| 261 | .bg(theme::amber()) |
| 262 | .text_color(dark_text()) |
| 263 | .text_size(px(11.)) |
| 264 | .font_weight(FontWeight::SEMIBOLD) |
| 265 | .child(icon(IconName::Hand, 11., dark_text())) |
| 266 | .child(position.to_string()) |
| 267 | } |
| 268 | |
| 269 | fn mic_icon(row: &PersonRow) -> impl IntoElement { |
| 270 | if row.mic_blocked { |
| 271 | icon(IconName::MicOff, STATE_ICON, theme::red()) |
| 272 | } else if row.muted { |
| 273 | icon(IconName::MicOff, STATE_ICON, theme::text_muted()) |
| 274 | } else { |
| 275 | icon(IconName::Mic, STATE_ICON, theme::text()) |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | fn camera_icon(row: &PersonRow) -> impl IntoElement { |
| 280 | if row.camera_blocked { |
| 281 | icon(IconName::VideoOff, STATE_ICON, theme::red()) |
| 282 | } else if row.camera_on { |
| 283 | icon(IconName::Video, STATE_ICON, theme::text()) |
| 284 | } else { |
| 285 | icon(IconName::VideoOff, STATE_ICON, theme::text_muted()) |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | fn person_row( |
| 290 | app: &Entity<AppState>, |
| 291 | state: &AppState, |
| 292 | model: &CallModel, |
| 293 | section: &'static str, |
| 294 | row: &PersonRow, |
| 295 | ) -> AnyElement { |
| 296 | let group = SharedString::from(format!("call-people-{section}-{}", row.mri)); |
| 297 | let user_id = row |
| 298 | .user_id |
| 299 | .clone() |
| 300 | .or_else(|| { |
| 301 | row.own |
| 302 | .then(|| state.directory.me.as_ref().map(|me| me.user_id.clone())) |
| 303 | .flatten() |
| 304 | }); |
| 305 | let subtitle = if row.ringing { Some("Ringing") } else { row.label }; |
| 306 | let (more_app, more_model, more_mri, more_name) = |
| 307 | (app.clone(), model.clone(), row.mri.clone(), row.name.clone()); |
| 308 | h_flex() |
| 309 | .id(SharedString::from(format!("call-people-row-{section}-{}", row.mri))) |
| 310 | .group(group.clone()) |
| 311 | .w_full() |
| 312 | .h(px(ROW_HEIGHT)) |
| 313 | .flex_none() |
| 314 | .px(px(20.)) |
| 315 | .gap(px(8.)) |
| 316 | .items_center() |
| 317 | .hover(|row| row.bg(theme::row_hover())) |
| 318 | .child(person_avatar(&state.directory, user_id.as_deref(), &row.name, AVATAR_SIZE)) |
| 319 | .child( |
| 320 | v_flex() |
| 321 | .flex_1() |
| 322 | .min_w_0() |
| 323 | .child( |
| 324 | div() |
| 325 | .truncate() |
| 326 | .text_size(px(13.)) |
| 327 | .font_weight(FontWeight::SEMIBOLD) |
| 328 | .child(truncated(&row.name, NAME_LIMIT)), |
| 329 | ) |
| 330 | .children(subtitle.map(|text| { |
| 331 | div() |
| 332 | .truncate() |
| 333 | .text_size(px(11.)) |
| 334 | .text_color(theme::text_muted()) |
| 335 | .child(text) |
| 336 | })), |
| 337 | ) |
| 338 | .children(row.hand.map(hand_badge)) |
| 339 | .child(mic_icon(row)) |
| 340 | .child(camera_icon(row)) |
| 341 | .child( |
| 342 | div() |
| 343 | .size(px(MORE_SIZE)) |
| 344 | .flex_none() |
| 345 | .when(!row.own, |slot| { |
| 346 | slot.opacity(0.) |
| 347 | .group_hover(group, |slot| slot.opacity(1.)) |
| 348 | .child( |
| 349 | Button::new(SharedString::from(format!( |
| 350 | "call-people-more-{section}-{}", |
| 351 | row.mri |
| 352 | ))) |
| 353 | .icon(IconName::Ellipsis) |
| 354 | .ghost() |
| 355 | .xsmall() |
| 356 | .size(px(MORE_SIZE)) |
| 357 | .tooltip("More") |
| 358 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 359 | tile_menu(popup, &more_app, &more_model, &more_mri, &more_name, false) |
| 360 | }), |
| 361 | ) |
| 362 | }), |
| 363 | ) |
| 364 | .into_any_element() |
| 365 | } |
| 366 | |
| 367 | fn lobby_section(app: &Entity<AppState>, state: &AppState, sections: &PeopleSections) -> Option<Div> { |
| 368 | if sections.lobby.is_empty() { |
| 369 | return None; |
| 370 | } |
| 371 | let admit_all_app = app.clone(); |
| 372 | let action = Button::new("call-people-admit-all") |
| 373 | .label("Admit all") |
| 374 | .ghost() |
| 375 | .xsmall() |
| 376 | .on_click(move |_, _, cx| admit_all_app.update(cx, |state, cx| state.admit_all_call_guests(cx))) |
| 377 | .into_any_element(); |
| 378 | Some( |
| 379 | v_flex() |
| 380 | .w_full() |
| 381 | .child(section_header(format!("Waiting in lobby ({})", sections.lobby.len()), Some(action))) |
| 382 | .children(sections.lobby.iter().map(|guest| { |
| 383 | let (admit_app, deny_app) = (app.clone(), app.clone()); |
| 384 | let (admit_mri, deny_mri) = (guest.mri.clone(), guest.mri.clone()); |
| 385 | h_flex() |
| 386 | .id(SharedString::from(format!("call-people-lobby-{}", guest.mri))) |
| 387 | .w_full() |
| 388 | .h(px(ROW_HEIGHT)) |
| 389 | .flex_none() |
| 390 | .px(px(20.)) |
| 391 | .gap(px(8.)) |
| 392 | .items_center() |
| 393 | .child(person_avatar(&state.directory, guest.user_id.as_deref(), &guest.name, AVATAR_SIZE)) |
| 394 | .child( |
| 395 | div() |
| 396 | .flex_1() |
| 397 | .min_w_0() |
| 398 | .truncate() |
| 399 | .text_size(px(13.)) |
| 400 | .font_weight(FontWeight::SEMIBOLD) |
| 401 | .child(truncated(&guest.name, NAME_LIMIT)), |
| 402 | ) |
| 403 | .child( |
| 404 | Button::new(SharedString::from(format!("call-people-admit-{}", guest.mri))) |
| 405 | .label("Admit") |
| 406 | .xsmall() |
| 407 | .on_click(move |_, _, cx| { |
| 408 | admit_app.update(cx, |state, cx| state.admit_call_guest(admit_mri.clone(), cx)) |
| 409 | }), |
| 410 | ) |
| 411 | .child( |
| 412 | Button::new(SharedString::from(format!("call-people-deny-{}", guest.mri))) |
| 413 | .label("Deny") |
| 414 | .ghost() |
| 415 | .xsmall() |
| 416 | .on_click(move |_, _, cx| { |
| 417 | deny_app.update(cx, |state, cx| state.deny_call_guest(deny_mri.clone(), cx)) |
| 418 | }), |
| 419 | ) |
| 420 | })), |
| 421 | ) |
| 422 | } |
| 423 | |
| 424 | pub fn people_panel(app: &Entity<AppState>, state: &AppState, call: &ActiveCall) -> Option<AnyElement> { |
| 425 | call.people_open.then_some(())?; |
| 426 | let model = &call.model; |
| 427 | let sections = people_sections(model); |
| 428 | let lower_all = model.can_lower_hands().then(|| { |
| 429 | let app = app.clone(); |
| 430 | Button::new("call-people-lower-all") |
| 431 | .label("Lower all") |
| 432 | .ghost() |
| 433 | .xsmall() |
| 434 | .on_click(move |_, _, cx| app.update(cx, |state, cx| state.lower_all_call_hands(cx))) |
| 435 | .into_any_element() |
| 436 | }); |
| 437 | let body = v_flex() |
| 438 | .id("call-people-list") |
| 439 | .flex_1() |
| 440 | .min_h_0() |
| 441 | .w_full() |
| 442 | .overflow_y_scroll() |
| 443 | .pb(px(12.)) |
| 444 | .children(model.can_admit().then(|| lobby_section(app, state, §ions)).flatten()) |
| 445 | .when(!sections.hands.is_empty(), |list| { |
| 446 | list.child(section_header(format!("Raised hands ({})", sections.hands.len()), lower_all)) |
| 447 | .children( |
| 448 | sections |
| 449 | .hands |
| 450 | .iter() |
| 451 | .map(|row| person_row(app, state, model, "hands", row)), |
| 452 | ) |
| 453 | }) |
| 454 | .children(sections.groups.iter().map(|group| { |
| 455 | v_flex() |
| 456 | .w_full() |
| 457 | .child(section_header(format!("{} ({})", group.title, group.rows.len()), None)) |
| 458 | .children(group.rows.iter().map(|row| person_row(app, state, model, "group", row))) |
| 459 | })); |
| 460 | Some( |
| 461 | v_flex() |
| 462 | .id("call-people-panel") |
| 463 | .debug_selector(|| "shell/islands/main/call-people".into()) |
| 464 | .w(px(CHAT_PANEL_WIDTH)) |
| 465 | .h_full() |
| 466 | .flex_shrink(1.) |
| 467 | .min_w_0() |
| 468 | .rounded(px(10.)) |
| 469 | .overflow_hidden() |
| 470 | .bg(theme::surface()) |
| 471 | .child(panel_header(app, model, sections.count)) |
| 472 | .child(body) |
| 473 | .into_any_element(), |
| 474 | ) |
| 475 | } |
| 476 | |
| 477 | fn choice_label(choices: &[(&str, &str)], value: &str) -> String { |
| 478 | choices |
| 479 | .iter() |
| 480 | .find(|(wire, _)| *wire == value) |
| 481 | .map_or_else(|| value.to_owned(), |(_, label)| (*label).to_owned()) |
| 482 | } |
| 483 | |
| 484 | fn choice_dropdown( |
| 485 | id: &'static str, |
| 486 | app: &Entity<AppState>, |
| 487 | choices: &'static [(&'static str, &'static str)], |
| 488 | current: &str, |
| 489 | edit: fn(&mut MeetingOptions, &str), |
| 490 | ) -> AnyElement { |
| 491 | let app = app.clone(); |
| 492 | let current = current.to_owned(); |
| 493 | Button::new(id) |
| 494 | .label(choice_label(choices, ¤t)) |
| 495 | .icon(IconName::ChevronDown) |
| 496 | .ghost() |
| 497 | .h(px(FIELD_HEIGHT)) |
| 498 | .dropdown_menu_with_anchor(Anchor::TopRight, move |popup, _, _| { |
| 499 | let mut popup = popup.min_w(px(DROPDOWN_WIDTH)); |
| 500 | if !choices.iter().any(|(wire, _)| *wire == current) { |
| 501 | popup = popup.item(PopupMenuItem::new(current.clone()).checked(true)); |
| 502 | } |
| 503 | for (wire, label) in choices { |
| 504 | let app = app.clone(); |
| 505 | popup = popup.item(PopupMenuItem::new(*label).checked(*wire == current).on_click( |
| 506 | move |_, _, cx| { |
| 507 | app.update(cx, |state, cx| { |
| 508 | state.edit_meeting_options(|options| edit(options, wire), cx) |
| 509 | }) |
| 510 | }, |
| 511 | )); |
| 512 | } |
| 513 | popup |
| 514 | }) |
| 515 | .into_any_element() |
| 516 | } |
| 517 | |
| 518 | fn switch_field( |
| 519 | id: &'static str, |
| 520 | app: &Entity<AppState>, |
| 521 | on: bool, |
| 522 | edit: fn(&mut MeetingOptions, bool), |
| 523 | ) -> AnyElement { |
| 524 | let app = app.clone(); |
| 525 | Switch::new(id) |
| 526 | .checked(on) |
| 527 | .on_click(move |checked, _, cx| { |
| 528 | let checked = *checked; |
| 529 | app.update(cx, |state, cx| { |
| 530 | state.edit_meeting_options(|options| edit(options, checked), cx) |
| 531 | }) |
| 532 | }) |
| 533 | .into_any_element() |
| 534 | } |
| 535 | |
| 536 | fn option_row(label: &'static str, control: AnyElement) -> Div { |
| 537 | h_flex() |
| 538 | .w_full() |
| 539 | .min_h(px(FIELD_HEIGHT)) |
| 540 | .gap(px(12.)) |
| 541 | .items_center() |
| 542 | .justify_between() |
| 543 | .child(div().flex_1().min_w_0().text_size(px(14.)).child(label)) |
| 544 | .child(control) |
| 545 | } |
| 546 | |
| 547 | fn options_fields(app: &Entity<AppState>, options: &MeetingOptions) -> Div { |
| 548 | use calling::meeting_options::{BYPASS_CHOICES, CHAT_CHOICES, PRESENTER_CHOICES}; |
| 549 | v_flex() |
| 550 | .w_full() |
| 551 | .gap(px(6.)) |
| 552 | .child(option_row( |
| 553 | "Who can bypass the lobby", |
| 554 | choice_dropdown("options-bypass", app, &BYPASS_CHOICES, &options.bypass_lobby, |options, value| { |
| 555 | options.bypass_lobby = value.to_owned() |
| 556 | }), |
| 557 | )) |
| 558 | .child(option_row( |
| 559 | "Who can present", |
| 560 | choice_dropdown("options-present", app, &PRESENTER_CHOICES, &options.presenters, |options, value| { |
| 561 | options.presenters = value.to_owned() |
| 562 | }), |
| 563 | )) |
| 564 | .child(option_row( |
| 565 | "Allow mic for attendees", |
| 566 | switch_field("options-mic", app, options.attendee_mic, |options, on| options.attendee_mic = on), |
| 567 | )) |
| 568 | .child(option_row( |
| 569 | "Allow camera for attendees", |
| 570 | switch_field("options-camera", app, options.attendee_camera, |options, on| { |
| 571 | options.attendee_camera = on |
| 572 | }), |
| 573 | )) |
| 574 | .child(option_row( |
| 575 | "Meeting chat", |
| 576 | choice_dropdown("options-chat", app, &CHAT_CHOICES, &options.meeting_chat, |options, value| { |
| 577 | options.meeting_chat = value.to_owned() |
| 578 | }), |
| 579 | )) |
| 580 | .child(option_row( |
| 581 | "Allow reactions", |
| 582 | switch_field("options-reactions", app, options.reactions, |options, on| options.reactions = on), |
| 583 | )) |
| 584 | .child(option_row( |
| 585 | "Record automatically", |
| 586 | switch_field("options-record", app, options.record_automatically, |options, on| { |
| 587 | options.record_automatically = on |
| 588 | }), |
| 589 | )) |
| 590 | } |
| 591 | |
| 592 | fn dialog_body(app: &Entity<AppState>, dialog: &OptionsDialog) -> Div { |
| 593 | let body = v_flex().w_full().gap(px(12.)); |
| 594 | let body = match &dialog.draft { |
| 595 | Some(draft) => body.child(options_fields(app, draft)), |
| 596 | None if dialog.is_loading() => body.child( |
| 597 | div() |
| 598 | .text_size(px(13.)) |
| 599 | .text_color(theme::text_muted()) |
| 600 | .child("Loading the meeting options..."), |
| 601 | ), |
| 602 | None => body, |
| 603 | }; |
| 604 | body.children(dialog.error.as_ref().map(|error| { |
| 605 | div() |
| 606 | .id("options-error") |
| 607 | .w_full() |
| 608 | .text_size(px(13.)) |
| 609 | .text_color(theme::red()) |
| 610 | .child(error.clone()) |
| 611 | })) |
| 612 | } |
| 613 | |
| 614 | pub fn options_dialog(app: &Entity<AppState>, call: &ActiveCall) -> Option<AnyElement> { |
| 615 | let dialog = call.options_dialog.as_ref()?; |
| 616 | let (close_app, cancel_app, save_app) = (app.clone(), app.clone(), app.clone()); |
| 617 | let can_save = dialog.can_save(); |
| 618 | let save = Button::new("options-save") |
| 619 | .label(if dialog.saving { "Saving..." } else { "Save" }) |
| 620 | .when(!can_save, |button| button.opacity(0.4)) |
| 621 | .on_click(move |_, _, cx| { |
| 622 | if can_save { |
| 623 | save_app.update(cx, |state, cx| state.save_meeting_options(cx)) |
| 624 | } |
| 625 | }); |
| 626 | Some( |
| 627 | div() |
| 628 | .id("options-layer") |
| 629 | .absolute() |
| 630 | .top_0() |
| 631 | .left_0() |
| 632 | .size_full() |
| 633 | .flex() |
| 634 | .items_center() |
| 635 | .justify_center() |
| 636 | .child( |
| 637 | div() |
| 638 | .id("options-backdrop") |
| 639 | .absolute() |
| 640 | .top_0() |
| 641 | .left_0() |
| 642 | .size_full() |
| 643 | .bg(black().opacity(DIALOG_BACKDROP)) |
| 644 | .occlude() |
| 645 | .on_click(move |_, _, cx| close_app.update(cx, |state, cx| state.close_meeting_options(cx))), |
| 646 | ) |
| 647 | .child( |
| 648 | v_flex() |
| 649 | .id("options-card") |
| 650 | .w(px(DIALOG_WIDTH)) |
| 651 | .max_w(relative(1.)) |
| 652 | .p(px(16.)) |
| 653 | .gap(px(12.)) |
| 654 | .rounded(px(12.)) |
| 655 | .bg(theme::background()) |
| 656 | .border_1() |
| 657 | .border_color(theme::border_strong()) |
| 658 | .text_color(theme::text()) |
| 659 | .shadow_lg() |
| 660 | .occlude() |
| 661 | .child( |
| 662 | div() |
| 663 | .text_size(px(15.)) |
| 664 | .font_weight(FontWeight::SEMIBOLD) |
| 665 | .child("Meeting options"), |
| 666 | ) |
| 667 | .child(dialog_body(app, dialog)) |
| 668 | .child( |
| 669 | h_flex() |
| 670 | .w_full() |
| 671 | .justify_end() |
| 672 | .gap(px(8.)) |
| 673 | .child( |
| 674 | Button::new("options-cancel") |
| 675 | .label("Cancel") |
| 676 | .ghost() |
| 677 | .on_click(move |_, _, cx| { |
| 678 | cancel_app.update(cx, |state, cx| state.close_meeting_options(cx)) |
| 679 | }), |
| 680 | ) |
| 681 | .child(save), |
| 682 | ), |
| 683 | ) |
| 684 | .into_any_element(), |
| 685 | ) |
| 686 | } |