BlueGit

ict rusty-teams

Files

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

call_controls.rs

call_controls.rs 2.5 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(app: &Entity<AppState>, state: &AppState, selection: &Selection) -> Vec<AnyElement> {
18 let conversation_id = selection.conversation_id().to_owned();
19 let mut controls = Vec::new();
20 if state.running_meeting(&conversation_id).is_some() {
21 let join_app = app.clone();
22 let join_id = conversation_id.clone();
23 controls.push(
24 h_flex()
25 .id("header-join")
26 .h(px(JOIN_HEIGHT))
27 .px(px(14.))
28 .gap(px(6.))
29 .flex_none()
30 .items_center()
31 .rounded_full()
32 .bg(theme::green())
33 .text_color(theme::white())
34 .text_size(px(13.))
35 .font_weight(FontWeight::SEMIBOLD)
36 .cursor_pointer()
37 .hover(|button| button.opacity(0.85))
38 .child(icon(IconName::Phone, 14., theme::white()))
39 .child("Join")
40 .on_click(move |_, _, cx| {
41 join_app.update(cx, |state, cx| state.join_meeting_call(&join_id, cx));
42 })
43 .into_any_element(),
44 );
45 }
46 let callable = matches!(selection, Selection::Chat(chat_id)
47 if state
48 .sidebar
49 .chats
50 .iter()
51 .find(|chat| &chat.id == chat_id)
52 .is_some_and(|chat| plan_for_chat(chat, state.directory.me.as_ref()).is_some()));
53 if callable {
54 let call_app = app.clone();
55 controls.push(
56 Button::new("header-call")
57 .ghost()
58 .p_0()
59 .size(px(BUTTON_SIZE))
60 .tooltip("Call")
61 .child(icon(IconName::Phone, GLYPH_SIZE, theme::text_soft()))
62 .on_click(move |_, _, cx| {
63 call_app.update(cx, |state, cx| {
64 if let Some(Selection::Chat(chat_id)) = state.selection.clone() {
65 state.start_chat_call(&chat_id, cx);
66 }
67 });
68 })
69 .into_any_element(),
70 );
71 }
72 controls
73}