BlueGit

ict rusty-teams

Files

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

chats.rs

chats.rs 3.2 KiB Download Raw
1use gpui_kit::component::v_flex;
2use gpui_kit::*;
3use teams_core::{ChatSection, ChatSettingChange};
4
5use super::account::{DENSITY, ENTER_KEY, account_select};
6use super::rows::{caption, toggle_row};
7use crate::app_state::AppState;
8use crate::theme;
9
10const MARKDOWN_DETAIL: &str = "Use mark-down language to define the structure and appearance of messages. Your formatting will take effect once you send your message. When this is on, the formatting options menu won't be visible.";
11const RECEIPTS_DETAIL: &str = "Let people know when you've seen their messages and know when they've seen yours. Close and reopen any chat windows for the setting to take effect in those chats.";
12
13pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
14 let state = app.read(cx);
15 let muted_section = state.directory.section_settings.enabled(ChatSection::Muted);
16 let settings = state.account_chat_settings();
17 let markdown_mode = state.markdown_mode;
18 let (section_app, markdown_app, receipts_app) = (app.clone(), app.clone(), app.clone());
19 v_flex()
20 .w_full()
21 .child(caption("CHAT LIST"))
22 .child(
23 toggle_row(
24 "settings-muted-section",
25 "Show muted items in their own section",
26 "Read from your Teams account",
27 theme::text_muted(),
28 muted_section,
29 )
30 .on_click(move |_, _, cx| {
31 section_app.update(cx, |state, cx| {
32 state.set_chat_section(ChatSection::Muted, !muted_section, cx)
33 })
34 }),
35 )
36 .child(caption("CHATS"))
37 .child(account_select(
38 app,
39 (
40 "settings-message-density",
41 "Message density",
42 "Compact your chats and see more messages",
43 ),
44 &DENSITY,
45 settings.message_density,
46 ChatSettingChange::MessageDensity,
47 ))
48 .child(account_select(
49 app,
50 (
51 "settings-enter-key",
52 "When writing a message, press Enter to",
53 "This setting doesn't apply when message formatting is active.",
54 ),
55 &ENTER_KEY,
56 settings.enter_key,
57 ChatSettingChange::EnterKey,
58 ))
59 .child(
60 toggle_row(
61 "settings-markdown",
62 "Format messages using mark-down",
63 MARKDOWN_DETAIL,
64 theme::text_muted(),
65 markdown_mode,
66 )
67 .on_click(move |_, _, cx| {
68 markdown_app.update(cx, |state, cx| state.set_markdown_mode(!markdown_mode, cx))
69 }),
70 )
71 .child(
72 toggle_row(
73 "settings-read-receipts",
74 "Read receipts",
75 RECEIPTS_DETAIL,
76 theme::text_muted(),
77 settings.read_receipts,
78 )
79 .on_click(move |_, _, cx| {
80 receipts_app.update(cx, |state, cx| {
81 state.save_chat_setting(
82 ChatSettingChange::ReadReceipts(!settings.read_receipts),
83 cx,
84 )
85 })
86 }),
87 )
88}