BlueGit

ict rusty-teams

Files

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

calls_tab.rs

calls_tab.rs 6.8 KiB Download Raw
1use chrono::{Local, Offset, Utc};
2use gpui_kit::assets::IconName;
3use gpui_kit::component::Sizable as _;
4use gpui_kit::component::button::Button;
5use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
6use gpui_kit::component::{h_flex, v_flex};
7use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9
10use super::avatar::person_avatar;
11use super::join_dialog::open_join_with_id;
12use super::widgets::icon;
13use crate::app_state::AppState;
14use crate::call::{CallRow, call_rows};
15use crate::theme;
16
17const ROW_HEIGHT: f32 = 54.;
18const AVATAR_SIZE: f32 = 36.;
19const MENU_ICON_SIZE: f32 = 15.;
20const EMPTY_TEXT: &str = "No calls yet";
21
22fn meeting_avatar() -> Div {
23 div()
24 .size(px(AVATAR_SIZE))
25 .flex_none()
26 .flex()
27 .items_center()
28 .justify_center()
29 .rounded_full()
30 .bg(theme::border_strong())
31 .child(icon(IconName::Video, 16., theme::text()))
32}
33
34fn call_row(
35 state: &Entity<AppState>,
36 row: &CallRow,
37 can_open_chat: bool,
38 directory: &crate::data::Directory,
39) -> AnyElement {
40 let avatar = if row.meeting {
41 meeting_avatar().into_any_element()
42 } else {
43 person_avatar(directory, row.user_id.as_deref(), &row.title, AVATAR_SIZE)
44 };
45 let title_color = if row.missed {
46 theme::red_soft()
47 } else {
48 theme::text()
49 };
50 let click_state = state.clone();
51 let click_row = row.clone();
52 let menu_state = state.clone();
53 let menu_row = row.clone();
54 let can_call_back = !row.meeting && row.user_id.is_some();
55 h_flex()
56 .id(SharedString::from(format!("call-{}", row.key)))
57 .mx(px(8.))
58 .h(px(ROW_HEIGHT))
59 .px(px(8.))
60 .gap(px(10.))
61 .items_center()
62 .rounded(px(8.))
63 .cursor_pointer()
64 .hover(|row| row.bg(theme::row_hover()))
65 .child(avatar)
66 .child(
67 v_flex()
68 .flex_1()
69 .min_w_0()
70 .gap(px(2.))
71 .child(
72 h_flex()
73 .gap(px(8.))
74 .items_baseline()
75 .child(
76 div()
77 .flex_1()
78 .min_w_0()
79 .truncate()
80 .text_size(px(14.))
81 .text_color(title_color)
82 .child(row.title.clone()),
83 )
84 .child(
85 div()
86 .flex_none()
87 .text_size(px(11.))
88 .text_color(theme::text_muted())
89 .child(row.time_label.clone()),
90 ),
91 )
92 .child(
93 div()
94 .truncate()
95 .text_size(px(12.5))
96 .text_color(if row.missed {
97 theme::red_soft()
98 } else {
99 theme::text_muted()
100 })
101 .child(row.subline.clone()),
102 ),
103 )
104 .on_click(move |_, _, cx| {
105 click_state.update(cx, |state, cx| state.activate_call_row(&click_row, cx));
106 })
107 .context_menu(move |popup, _, _| {
108 let call_state = menu_state.clone();
109 let call_row = menu_row.clone();
110 let chat_state = menu_state.clone();
111 let chat_row = menu_row.clone();
112 popup
113 .when(can_call_back, |popup| {
114 popup.item(
115 PopupMenuItem::new("Call back")
116 .icon(icon(IconName::Phone, MENU_ICON_SIZE, theme::text_muted()))
117 .on_click(move |_, _, cx| {
118 call_state.update(cx, |state, cx| {
119 state.call_back_from_history(&call_row, cx)
120 });
121 }),
122 )
123 })
124 .when(can_open_chat, |popup| {
125 popup.item(
126 PopupMenuItem::new("Open chat")
127 .icon(icon(
128 IconName::MessageSquare,
129 MENU_ICON_SIZE,
130 theme::text_muted(),
131 ))
132 .on_click(move |_, _, cx| {
133 chat_state.update(cx, |state, cx| {
134 state.open_chat_of_call_row(&chat_row, cx)
135 });
136 }),
137 )
138 })
139 })
140 .into_any_element()
141}
142
143fn join_buttons(state: &Entity<AppState>) -> impl IntoElement {
144 let id_state = state.clone();
145 let paste_state = state.clone();
146 h_flex()
147 .w_full()
148 .px(px(12.))
149 .pb(px(8.))
150 .gap(px(8.))
151 .child(
152 Button::new("join-with-id")
153 .small()
154 .label("Join with ID")
155 .on_click(move |_, window, cx| open_join_with_id(id_state.clone(), window, cx)),
156 )
157 .child(
158 Button::new("paste-meeting-link")
159 .small()
160 .label("Paste a meeting link")
161 .on_click(move |_, _, cx| {
162 paste_state.update(cx, |state, cx| state.join_meeting_from_clipboard(cx));
163 }),
164 )
165}
166
167pub fn calls_body(state: &Entity<AppState>, scroll: &ScrollHandle, cx: &App) -> AnyElement {
168 let app = state.read(cx);
169 let offset = Local::now().offset().fix();
170 let rows = call_rows(&app.call_history, &app.sidebar.chats, Utc::now(), offset);
171 let list = if rows.is_empty() {
172 div()
173 .w_full()
174 .py(px(24.))
175 .flex()
176 .justify_center()
177 .text_size(px(13.))
178 .text_color(theme::text_muted())
179 .child(EMPTY_TEXT)
180 .into_any_element()
181 } else {
182 v_flex()
183 .w_full()
184 .pb(px(12.))
185 .children(rows.iter().map(|row| {
186 call_row(
187 state,
188 row,
189 app.can_open_chat_of_call_row(row),
190 &app.directory,
191 )
192 }))
193 .into_any_element()
194 };
195 v_flex()
196 .flex_1()
197 .min_h_0()
198 .child(join_buttons(state))
199 .child(
200 div()
201 .id("calls-scroll")
202 .flex_1()
203 .min_h_0()
204 .overflow_y_scroll()
205 .track_scroll(scroll)
206 .child(list),
207 )
208 .into_any_element()
209}