BlueGit

ict rusty-teams

Files

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

call_controls.rs

call_controls.rs 3.0 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::{is_echo_chat, 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| {
57 is_echo_chat(chat) || plan_for_chat(chat, state.directory.me.as_ref()).is_some()
58 }));
59 if callable {
60 for (id, tooltip, glyph, with_video) in [
61 ("header-video-call", "Video call", IconName::Video, true),
62 ("header-call", "Call", IconName::Phone, false),
63 ] {
64 let call_app = app.clone();
65 controls.push(
66 Button::new(id)
67 .ghost()
68 .p_0()
69 .size(px(BUTTON_SIZE))
70 .tooltip(tooltip)
71 .child(icon(glyph, GLYPH_SIZE, theme::text_soft()))
72 .on_click(move |_, _, cx| {
73 call_app.update(cx, |state, cx| {
74 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
75 if with_video {
76 state.start_chat_video_call(&chat_id, cx);
77 } else {
78 state.start_chat_call(&chat_id, cx);
79 }
80 }
81 });
82 })
83 .into_any_element(),
84 );
85 }
86 }
87 controls
88}