BlueGit

ict rusty-teams

Files

rusty-teams / crates / app / src / settings / calls.rs

calls.rs

chore: cargo fmt the workspace
metis Daniel Däschle · pushed by metis · 2 weeks ago
a6592765 History
calls.rs 2.4 KiB Download Raw
1use gpui_kit::component::{h_flex, v_flex};
2use gpui_kit::*;
3
4use super::rows::{Choice, caption, control_row, select, text_button};
5use crate::notify::NotificationCenter;
6use crate::notify::sounds::{Ringtone, RingtoneCallType};
7
8pub fn render(center: &Entity<NotificationCenter>, cx: &App) -> Div {
9 let ringtones = center.read(cx).settings().sounds.ringtones;
10 let rows = RingtoneCallType::ALL
11 .into_iter()
12 .filter(|call_type| {
13 *call_type == RingtoneCallType::Regular || ringtones.get(*call_type) != Ringtone::Ring
14 })
15 .map(|call_type| ringtone_row(center, call_type, ringtones.get(call_type)));
16 v_flex().w_full().child(caption("RINGTONES")).children(rows)
17}
18
19fn ringtone_row(
20 center: &Entity<NotificationCenter>,
21 call_type: RingtoneCallType,
22 current: Ringtone,
23) -> Div {
24 let choices = Ringtone::ALL
25 .iter()
26 .map(|ringtone| {
27 let (center, ringtone) = (center.clone(), *ringtone);
28 Choice::new(ringtone.label(), ringtone == current, move |cx| {
29 center.update(cx, |center, cx| {
30 center.update_settings(cx, |settings| {
31 settings.sounds.ringtones.set(call_type, ringtone)
32 });
33 center.preview_sound(ringtone.file_name(), cx);
34 })
35 })
36 })
37 .collect();
38 let (id, preview_id) = ringtone_ids(call_type);
39 let preview_center = center.clone();
40 control_row(
41 call_type.label(),
42 "",
43 h_flex()
44 .gap(px(8.))
45 .items_center()
46 .child(select(id, current.label(), false, choices))
47 .child(
48 text_button(preview_id, "Preview").on_click(move |_, _, cx| {
49 preview_center.update(cx, |center, cx| {
50 center.preview_sound(current.file_name(), cx)
51 })
52 }),
53 ),
54 )
55}
56
57fn ringtone_ids(call_type: RingtoneCallType) -> (&'static str, &'static str) {
58 match call_type {
59 RingtoneCallType::Regular => ("ringtone-regular", "ringtone-regular-preview"),
60 RingtoneCallType::CallGroup => ("ringtone-call-group", "ringtone-call-group-preview"),
61 RingtoneCallType::CallQueue => ("ringtone-call-queue", "ringtone-call-queue-preview"),
62 RingtoneCallType::Delegate => ("ringtone-delegate", "ringtone-delegate-preview"),
63 }
64}