BlueGit

ict rusty-teams

Files

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

calls_tab.rs

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