BlueGit

ict rusty-teams

Files

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

calls_tab.rs

calls_tab.rs 11.2 KiB Download Raw
1use chrono::{Local, Offset, Utc};
2use gpui_kit::assets::IconName;
3use gpui_kit::component::Sizable as _;
4use gpui_kit::base::Disableable as _;
5use gpui_kit::component::button::{Button, ButtonVariants as _};
6use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
7use gpui_kit::component::{h_flex, v_flex};
8use gpui_kit::prelude::FluentBuilder as _;
9use gpui_kit::*;
10
11use super::avatar::person_avatar;
12use super::join_dialog::open_join_with_id;
13use super::widgets::icon;
14use crate::app_state::AppState;
15use crate::call::{
16 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT, ListEntry,
17 SECTION_HEIGHT, join_available,
18};
19use crate::theme;
20
21const FALLBACK_VIEWPORT: f32 = 900.;
22const VIEWPORT_MARGIN: f32 = 300.;
23const TIME_COLUMN_WIDTH: f32 = 96.;
24const AVATAR_SIZE: f32 = 36.;
25const MENU_ICON_SIZE: f32 = 15.;
26
27fn meeting_avatar() -> Div {
28 div()
29 .size(px(AVATAR_SIZE))
30 .flex_none()
31 .flex()
32 .items_center()
33 .justify_center()
34 .rounded_full()
35 .bg(theme::border_strong())
36 .child(icon(IconName::Video, 16., theme::text()))
37}
38
39fn call_row(
40 state: &Entity<AppState>,
41 row: &CallRow,
42 can_open_chat: bool,
43 directory: &crate::data::Directory,
44) -> AnyElement {
45 let avatar = if row.meeting {
46 meeting_avatar().into_any_element()
47 } else {
48 person_avatar(directory, row.user_id.as_deref(), &row.title, AVATAR_SIZE)
49 };
50 let title_color = if row.missed {
51 theme::red_soft()
52 } else {
53 theme::text()
54 };
55 let click_state = state.clone();
56 let click_row = row.clone();
57 let menu_state = state.clone();
58 let menu_row = row.clone();
59 let can_call_back = !row.meeting && row.user_id.is_some();
60 h_flex()
61 .id(SharedString::from(format!("call-{}", row.key)))
62 .mx(px(8.))
63 .h(px(CALL_ROW_HEIGHT))
64 .px(px(8.))
65 .gap(px(10.))
66 .items_center()
67 .rounded(px(8.))
68 .cursor_pointer()
69 .hover(|row| row.bg(theme::row_hover()))
70 .child(avatar)
71 .child(
72 v_flex()
73 .flex_1()
74 .min_w_0()
75 .gap(px(2.))
76 .child(
77 h_flex()
78 .gap(px(8.))
79 .items_baseline()
80 .child(
81 div()
82 .flex_1()
83 .min_w_0()
84 .truncate()
85 .text_size(px(14.))
86 .text_color(title_color)
87 .child(row.title.clone()),
88 )
89 .child(
90 div()
91 .flex_none()
92 .text_size(px(11.))
93 .text_color(theme::text_muted())
94 .child(row.time_label.clone()),
95 ),
96 )
97 .child(
98 div()
99 .truncate()
100 .text_size(px(12.5))
101 .text_color(if row.missed {
102 theme::red_soft()
103 } else {
104 theme::text_muted()
105 })
106 .child(row.subline.clone()),
107 ),
108 )
109 .on_click(move |_, _, cx| {
110 click_state.update(cx, |state, cx| state.activate_call_row(&click_row, cx));
111 })
112 .context_menu(move |popup, _, _| {
113 let call_state = menu_state.clone();
114 let call_row = menu_row.clone();
115 let chat_state = menu_state.clone();
116 let chat_row = menu_row.clone();
117 popup
118 .when(can_call_back, |popup| {
119 popup.item(
120 PopupMenuItem::new("Call back")
121 .icon(icon(IconName::Phone, MENU_ICON_SIZE, theme::text_muted()))
122 .on_click(move |_, _, cx| {
123 call_state.update(cx, |state, cx| {
124 state.call_back_from_history(&call_row, cx)
125 });
126 }),
127 )
128 })
129 .when(can_open_chat, |popup| {
130 popup.item(
131 PopupMenuItem::new("Open chat")
132 .icon(icon(
133 IconName::MessageSquare,
134 MENU_ICON_SIZE,
135 theme::text_muted(),
136 ))
137 .on_click(move |_, _, cx| {
138 chat_state.update(cx, |state, cx| {
139 state.open_chat_of_call_row(&chat_row, cx)
140 });
141 }),
142 )
143 })
144 })
145 .into_any_element()
146}
147
148fn join_buttons(state: &Entity<AppState>, meet_now_pending: bool) -> impl IntoElement {
149 let meet_state = state.clone();
150 let id_state = state.clone();
151 let paste_state = state.clone();
152 h_flex()
153 .w_full()
154 .px(px(12.))
155 .pb(px(8.))
156 .gap(px(8.))
157 .flex_wrap()
158 .child(
159 Button::new("meet-now")
160 .small()
161 .primary()
162 .label("Meet now")
163 .disabled(meet_now_pending)
164 .on_click(move |_, _, cx| {
165 meet_state.update(cx, |state, cx| state.start_meet_now(cx));
166 }),
167 )
168 .child(
169 Button::new("join-with-id")
170 .small()
171 .label("Join with ID")
172 .on_click(move |_, window, cx| open_join_with_id(id_state.clone(), window, cx)),
173 )
174 .child(
175 Button::new("paste-meeting-link")
176 .small()
177 .label("Paste a meeting link")
178 .on_click(move |_, _, cx| {
179 paste_state.update(cx, |state, cx| state.join_meeting_from_clipboard(cx));
180 }),
181 )
182}
183
184fn section_header(title: &'static str) -> AnyElement {
185 div()
186 .h(px(SECTION_HEIGHT))
187 .px(px(16.))
188 .flex()
189 .items_end()
190 .pb(px(4.))
191 .text_size(px(12.))
192 .font_weight(FontWeight::SEMIBOLD)
193 .text_color(theme::text_muted())
194 .child(title)
195 .into_any_element()
196}
197
198fn day_header(label: &str) -> AnyElement {
199 div()
200 .h(px(DAY_HEIGHT))
201 .px(px(16.))
202 .flex()
203 .items_center()
204 .text_size(px(11.5))
205 .text_color(theme::text_faint())
206 .child(label.to_owned())
207 .into_any_element()
208}
209
210fn empty_row(text: &'static str) -> AnyElement {
211 div()
212 .h(px(EMPTY_HEIGHT))
213 .flex()
214 .items_center()
215 .justify_center()
216 .text_size(px(13.))
217 .text_color(theme::text_muted())
218 .child(text)
219 .into_any_element()
220}
221
222fn agenda_row(state: &Entity<AppState>, row: &AgendaRow, joinable: bool) -> AnyElement {
223 let click_state = state.clone();
224 let click_row = row.clone();
225 let join_state = state.clone();
226 let join_row = row.clone();
227 h_flex()
228 .id(SharedString::from(format!("agenda-{}", row.key)))
229 .mx(px(8.))
230 .h(px(AGENDA_ROW_HEIGHT))
231 .px(px(8.))
232 .gap(px(10.))
233 .items_center()
234 .rounded(px(8.))
235 .cursor_pointer()
236 .hover(|row| row.bg(theme::row_hover()))
237 .child(
238 div()
239 .w(px(TIME_COLUMN_WIDTH))
240 .flex_none()
241 .text_size(px(12.))
242 .text_color(theme::text_muted())
243 .child(row.time_label.clone()),
244 )
245 .child(
246 v_flex()
247 .flex_1()
248 .min_w_0()
249 .gap(px(2.))
250 .child(
251 div()
252 .truncate()
253 .text_size(px(14.))
254 .text_color(theme::text())
255 .child(row.subject.clone()),
256 )
257 .when(!row.detail.is_empty(), |column| {
258 column.child(
259 div()
260 .truncate()
261 .text_size(px(12.5))
262 .text_color(theme::text_muted())
263 .child(row.detail.clone()),
264 )
265 }),
266 )
267 .when(joinable, |line| {
268 line.child(
269 Button::new(SharedString::from(format!("agenda-join-{}", row.key)))
270 .small()
271 .primary()
272 .label("Join")
273 .on_click(move |_, _, cx| {
274 cx.stop_propagation();
275 join_state.update(cx, |state, cx| state.join_agenda_row(&join_row, cx));
276 }),
277 )
278 })
279 .on_click(move |_, _, cx| {
280 click_state.update(cx, |state, cx| state.open_agenda_chat(&click_row, cx));
281 })
282 .into_any_element()
283}
284
285pub fn calls_body(
286 state: &Entity<AppState>,
287 scroll: &ScrollHandle,
288 window_height: f32,
289 cx: &mut App,
290) -> AnyElement {
291 let now = Utc::now();
292 let offset = Local::now().offset().fix();
293 if state.read(cx).calls_list.needs_rebuild(now, offset) {
294 let rebuild_state = state.clone();
295 cx.defer(move |cx| rebuild_state.update(cx, |state, cx| state.rebuild_calls_list(cx)));
296 }
297 let top = -f32::from(scroll.offset().y);
298 let measured = f32::from(scroll.bounds().size.height);
299 let height = if measured > 1. {
300 measured
301 } else {
302 window_height.max(FALLBACK_VIEWPORT)
303 };
304 let app = state.read(cx);
305 let window = app
306 .calls_list
307 .window(top - VIEWPORT_MARGIN, top + height + VIEWPORT_MARGIN);
308 let entries = &app.calls_list.entries()[window.range.clone()];
309 let mut list = v_flex().w_full().pb(px(12.));
310 if window.before > 0. {
311 list = list.child(div().h(px(window.before)).flex_none());
312 }
313 for entry in entries {
314 list = list.child(match entry {
315 ListEntry::Section(title) => section_header(title),
316 ListEntry::Day(label) => day_header(label),
317 ListEntry::Empty(text) => empty_row(text),
318 ListEntry::Agenda(row) => {
319 agenda_row(state, row, join_available(row.start, row.end, now) && row.join_url.is_some())
320 }
321 ListEntry::Call(row) => call_row(
322 state,
323 row,
324 app.can_open_chat_of_call_row(row),
325 &app.directory,
326 ),
327 });
328 }
329 if window.after > 0. {
330 list = list.child(div().h(px(window.after)).flex_none());
331 }
332 v_flex()
333 .flex_1()
334 .min_h_0()
335 .child(join_buttons(state, app.meet_now_pending))
336 .child(
337 div()
338 .id("calls-scroll")
339 .flex_1()
340 .min_h_0()
341 .overflow_y_scroll()
342 .track_scroll(scroll)
343 .child(list),
344 )
345 .into_any_element()
346}