BlueGit

ict rusty-teams

Files

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

call_controls.rs

call_controls.rs 2.9 KiB Download Raw
1use gpui_kit::assets::IconName;
2use gpui_kit::component::{
3 button::{Button, ButtonVariants as _},
4 h_flex,
5};
6use gpui_kit::*;
7
8use super::widgets::icon;
9use crate::app_state::{AppState, Selection};
10use crate::call::plan_for_chat;
11use crate::theme;
12
13const BUTTON_SIZE: f32 = 30.;
14const GLYPH_SIZE: f32 = 16.;
15const JOIN_HEIGHT: f32 = 30.;
16
17pub fn header_call_controls(
18 app: &Entity<AppState>,
19 state: &AppState,
20 selection: &Selection,
21) -> Vec<AnyElement> {
22 let conversation_id = selection.conversation_id().to_owned();
23 let mut controls = Vec::new();
24 if state.running_meeting(&conversation_id).is_some() {
25 let join_app = app.clone();
26 let join_id = conversation_id.clone();
27 controls.push(
28 h_flex()
29 .id("header-join")
30 .h(px(JOIN_HEIGHT))
31 .px(px(14.))
32 .gap(px(6.))
33 .flex_none()
34 .items_center()
35 .rounded_full()
36 .bg(theme::green())
37 .text_color(theme::white())
38 .text_size(px(13.))
39 .font_weight(FontWeight::SEMIBOLD)
40 .cursor_pointer()
41 .hover(|button| button.opacity(0.85))
42 .child(icon(IconName::Phone, 14., theme::white()))
43 .child("Join")
44 .on_click(move |_, _, cx| {
45 join_app.update(cx, |state, cx| state.join_meeting_call(&join_id, cx));
46 })
47 .into_any_element(),
48 );
49 }
50 let callable = matches!(selection, Selection::Chat(chat_id)
51 if state
52 .sidebar
53 .chats
54 .iter()
55 .find(|chat| &chat.id == chat_id)
56 .is_some_and(|chat| plan_for_chat(chat, state.directory.me.as_ref()).is_some()));
57 if callable {
58 for (id, tooltip, glyph, with_video) in [
59 ("header-video-call", "Video call", IconName::Video, true),
60 ("header-call", "Call", IconName::Phone, false),
61 ] {
62 let call_app = app.clone();
63 controls.push(
64 Button::new(id)
65 .ghost()
66 .p_0()
67 .size(px(BUTTON_SIZE))
68 .tooltip(tooltip)
69 .child(icon(glyph, GLYPH_SIZE, theme::text_soft()))
70 .on_click(move |_, _, cx| {
71 call_app.update(cx, |state, cx| {
72 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
73 if with_video {
74 state.start_chat_video_call(&chat_id, cx);
75 } else {
76 state.start_chat_call(&chat_id, cx);
77 }
78 }
79 });
80 })
81 .into_any_element(),
82 );
83 }
84 }
85 controls
86}