BlueGit

ict rusty-teams

feat(channel): new post composer as one card like Teams

- author row with close, large subject, edge-to-edge divider, format bar always open, body
- actions bottom left, accent Post button bottom right, no Cancel text
- editing a post keeps the chat layout with Cancel

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-06 · 3 weeks ago

Hash
9c1cde1a18909a883a3a08f230cf41612a5f592c
Parent
06c19e72
5 files changed +264 −73
crates/app/src/layout_guard.rs +49 −0
@@ -185,6 +185,8 @@ mod frames {
185 185 use crate::views::composer::{
186 186 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
187 187 COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,
188 POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
189 POST_CARD_SUBJECT_TAG,
188 190 };
189 191 use crate::views::conversation::{
190 192 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
@@ -2079,6 +2081,53 @@ mod frames {
2079 2081 visual
2080 2082 }
2081 2083
2084 #[gpui_kit::test]
2085 fn the_new_post_is_one_card_with_subject_divider_format_bar_and_post_button(
2086 cx: &mut TestAppContext,
2087 ) {
2088 let mut visual = open_channel(cx, crate::views::post_card::POST_IN_CHANNEL_TAG);
2089 let open = visual
2090 .debug_bounds(crate::views::post_card::POST_IN_CHANNEL_TAG)
2091 .expect("post in channel card");
2092 visual.simulate_click(open.center(), Default::default());
2093 collect(&mut visual, Some(POST_CARD_SEND_TAG));
2094 let mut bounds_of = |path: &'static str| {
2095 visual
2096 .debug_bounds(path)
2097 .unwrap_or_else(|| panic!("{path} missing"))
2098 };
2099 let card = bounds_of(COMPOSER_BOX_TAG);
2100 let header = bounds_of(POST_CARD_HEADER_TAG);
2101 let subject = bounds_of(POST_CARD_SUBJECT_TAG);
2102 let divider = bounds_of(POST_CARD_DIVIDER_TAG);
2103 let format_bar = bounds_of(COMPOSER_FORMAT_BAR_TAG);
2104 let footer = bounds_of(POST_CARD_FOOTER_TAG);
2105 let send = bounds_of(POST_CARD_SEND_TAG);
2106 assert!(
2107 visual.debug_bounds(COMPOSER_SEND_TAG).is_none(),
2108 "chat send button shown in a post"
2109 );
2110 assert!(
2111 visual.debug_bounds(COMPOSER_FORMAT_TAG).is_none(),
2112 "format toggle shown although the bar stays open"
2113 );
2114 assert!(header.bottom() <= subject.top() && subject.bottom() <= divider.top());
2115 assert!(divider.bottom() <= format_bar.top() && format_bar.bottom() <= footer.top());
2116 assert!(
2117 f32::from(divider.left() - card.left()).abs() < 1.5
2118 && f32::from(card.right() - divider.right()).abs() < 1.5,
2119 "subject divider {} does not run edge to edge in {}",
2120 describe(divider),
2121 describe(card)
2122 );
2123 let side = f32::from(card.right() - send.right());
2124 let bottom = f32::from(card.bottom() - send.bottom());
2125 assert!(
2126 (side - bottom).abs() < TOLERANCE,
2127 "Post button insets: side {side}, bottom {bottom}"
2128 );
2129 }
2130
2082 2131 #[gpui_kit::test]
2083 2132 fn channel_posts_start_the_body_at_the_avatar_edge_like_teams(cx: &mut TestAppContext) {
2084 2133 let mut visual = open_channel(cx, POST_FOOTER_AVATAR_TAG);
@@ -185,6 +185,8 @@ mod frames {
185 use crate::views::composer::{
185 use crate::views::composer::{
186 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
186 COMPOSER_BOX_TAG, COMPOSER_FORMAT_BAR_TAG, COMPOSER_FORMAT_DIVIDER_TAG,
187 COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,
187 COMPOSER_ACTIONS_TAG, COMPOSER_FORMAT_TAG, COMPOSER_INPUT_TAG, COMPOSER_SEND_TAG,
188 POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
189 POST_CARD_SUBJECT_TAG,
188 };
190 };
189 use crate::views::conversation::{
191 use crate::views::conversation::{
190 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
192 CHANNEL_DETAILS_BUTTON, CHANNEL_DETAILS_PINNED_TAG, CHANNEL_DETAILS_SHARED_TAG,
@@ -2079,6 +2081,53 @@ mod frames {
2079 visual
2081 visual
2080 }
2082 }
2081
2083
2084 #[gpui_kit::test]
2085 fn the_new_post_is_one_card_with_subject_divider_format_bar_and_post_button(
2086 cx: &mut TestAppContext,
2087 ) {
2088 let mut visual = open_channel(cx, crate::views::post_card::POST_IN_CHANNEL_TAG);
2089 let open = visual
2090 .debug_bounds(crate::views::post_card::POST_IN_CHANNEL_TAG)
2091 .expect("post in channel card");
2092 visual.simulate_click(open.center(), Default::default());
2093 collect(&mut visual, Some(POST_CARD_SEND_TAG));
2094 let mut bounds_of = |path: &'static str| {
2095 visual
2096 .debug_bounds(path)
2097 .unwrap_or_else(|| panic!("{path} missing"))
2098 };
2099 let card = bounds_of(COMPOSER_BOX_TAG);
2100 let header = bounds_of(POST_CARD_HEADER_TAG);
2101 let subject = bounds_of(POST_CARD_SUBJECT_TAG);
2102 let divider = bounds_of(POST_CARD_DIVIDER_TAG);
2103 let format_bar = bounds_of(COMPOSER_FORMAT_BAR_TAG);
2104 let footer = bounds_of(POST_CARD_FOOTER_TAG);
2105 let send = bounds_of(POST_CARD_SEND_TAG);
2106 assert!(
2107 visual.debug_bounds(COMPOSER_SEND_TAG).is_none(),
2108 "chat send button shown in a post"
2109 );
2110 assert!(
2111 visual.debug_bounds(COMPOSER_FORMAT_TAG).is_none(),
2112 "format toggle shown although the bar stays open"
2113 );
2114 assert!(header.bottom() <= subject.top() && subject.bottom() <= divider.top());
2115 assert!(divider.bottom() <= format_bar.top() && format_bar.bottom() <= footer.top());
2116 assert!(
2117 f32::from(divider.left() - card.left()).abs() < 1.5
2118 && f32::from(card.right() - divider.right()).abs() < 1.5,
2119 "subject divider {} does not run edge to edge in {}",
2120 describe(divider),
2121 describe(card)
2122 );
2123 let side = f32::from(card.right() - send.right());
2124 let bottom = f32::from(card.bottom() - send.bottom());
2125 assert!(
2126 (side - bottom).abs() < TOLERANCE,
2127 "Post button insets: side {side}, bottom {bottom}"
2128 );
2129 }
2130
2082 #[gpui_kit::test]
2131 #[gpui_kit::test]
2083 fn channel_posts_start_the_body_at_the_avatar_edge_like_teams(cx: &mut TestAppContext) {
2132 fn channel_posts_start_the_body_at_the_avatar_edge_like_teams(cx: &mut TestAppContext) {
2084 let mut visual = open_channel(cx, POST_FOOTER_AVATAR_TAG);
2133 let mut visual = open_channel(cx, POST_FOOTER_AVATAR_TAG);
crates/app/src/views/composer.rs +30 −15
@@ -33,6 +33,11 @@ use teams_core::{
33 33 pub(crate) mod delivery;
34 34 mod drafts;
35 35 mod format_menus;
36 mod post;
37 pub use post::{
38 POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
39 POST_CARD_SUBJECT_TAG,
40 };
36 41 mod rule;
37 42 mod schedule;
38 43 mod slash;
@@ -134,6 +139,7 @@ pub enum ComposerEvent {
134 139 FocusMessages,
135 140 Typing(bool),
136 141 Edited,
142 ClosePost,
137 143 }
138 144
139 145 struct MentionPopup {
@@ -240,6 +246,7 @@ pub struct Composer {
240 246 format_popup: Option<FormatPopup>,
241 247 format_overflow: bool,
242 248 format_bar: HashSet<String>,
249 post_subject: Option<Entity<InputState>>,
243 250 active_cell: Option<(String, teams_core::Cell)>,
244 251 caret_before_table: usize,
245 252 caret_text: String,
@@ -508,6 +515,7 @@ impl Composer {
508 515 format_popup: None,
509 516 format_overflow: false,
510 517 format_bar: HashSet::new(),
518 post_subject: None,
511 519 active_cell: None,
512 520 caret_before_table: 0,
513 521 caret_text: String::new(),
@@ -2925,8 +2933,9 @@ impl Render for Composer {
2925 2933 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2926 2934 });
2927 2935 let markdown_mode = self.app.read(cx).markdown_mode;
2928 let format_open = self.format_bar_open() && !markdown_mode;
2929 let format_toggle = (!markdown_mode).then(|| {
2936 let post_layout = self.post_layout();
2937 let format_open = (self.format_bar_open() || post_layout) && !markdown_mode;
2938 let format_toggle = (!markdown_mode && !post_layout).then(|| {
2930 2939 div()
2931 2940 .id("composer-format")
2932 2941 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
@@ -2958,6 +2967,20 @@ impl Render for Composer {
2958 2967 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)))
2959 2968 });
2960 2969 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2970 let actions = h_flex()
2971 .debug_selector(|| COMPOSER_ACTIONS_TAG.into())
2972 .flex_none()
2973 .gap(px(COMPOSER_BUTTON_INSET))
2974 .children(format_toggle)
2975 .children(self.render_delivery_button(cx))
2976 .children(fun)
2977 .children(attach);
2978 let (row_actions, post_footer) = if post_layout {
2979 (None, Some(self.render_post_footer(actions, can_send, cx)))
2980 } else {
2981 (Some(actions.ml(px(COMPOSER_BUTTON_INSET))), None)
2982 };
2983 let post_header = self.render_post_header(cx);
2961 2984 let composer = cx.weak_entity();
2962 2985 let tokens_composer = composer.clone();
2963 2986 let input = Textarea::new(&self.input)
@@ -3396,6 +3419,7 @@ impl Render for Composer {
3396 3419 .absolute()
3397 3420 .size_full(),
3398 3421 )
3422 .children(post_header)
3399 3423 .children(format_bar)
3400 3424 .children(self.render_importance_label(cx))
3401 3425 .children(tray)
@@ -3438,19 +3462,10 @@ impl Render for Composer {
3438 3462 )
3439 3463 .child(input),
3440 3464 )
3441 .child(
3442 h_flex()
3443 .debug_selector(|| COMPOSER_ACTIONS_TAG.into())
3444 .flex_none()
3445 .ml(px(COMPOSER_BUTTON_INSET))
3446 .gap(px(COMPOSER_BUTTON_INSET))
3447 .children(format_toggle)
3448 .children(self.render_delivery_button(cx))
3449 .children(fun)
3450 .children(attach),
3451 )
3452 .child(send),
3453 ),
3465 .children(row_actions)
3466 .when(!post_layout, |row| row.child(send)),
3467 )
3468 .children(post_footer),
3454 3469 ),
3455 3470 )
3456 3471 .children(self.render_paste_hint())
@@ -33,6 +33,11 @@ use teams_core::{
33pub(crate) mod delivery;
33pub(crate) mod delivery;
34mod drafts;
34mod drafts;
35mod format_menus;
35mod format_menus;
36mod post;
37pub use post::{
38 POST_CARD_DIVIDER_TAG, POST_CARD_FOOTER_TAG, POST_CARD_HEADER_TAG, POST_CARD_SEND_TAG,
39 POST_CARD_SUBJECT_TAG,
40};
36mod rule;
41mod rule;
37mod schedule;
42mod schedule;
38mod slash;
43mod slash;
@@ -134,6 +139,7 @@ pub enum ComposerEvent {
134 FocusMessages,
139 FocusMessages,
135 Typing(bool),
140 Typing(bool),
136 Edited,
141 Edited,
142 ClosePost,
137}
143}
138
144
139struct MentionPopup {
145struct MentionPopup {
@@ -240,6 +246,7 @@ pub struct Composer {
240 format_popup: Option<FormatPopup>,
246 format_popup: Option<FormatPopup>,
241 format_overflow: bool,
247 format_overflow: bool,
242 format_bar: HashSet<String>,
248 format_bar: HashSet<String>,
249 post_subject: Option<Entity<InputState>>,
243 active_cell: Option<(String, teams_core::Cell)>,
250 active_cell: Option<(String, teams_core::Cell)>,
244 caret_before_table: usize,
251 caret_before_table: usize,
245 caret_text: String,
252 caret_text: String,
@@ -508,6 +515,7 @@ impl Composer {
508 format_popup: None,
515 format_popup: None,
509 format_overflow: false,
516 format_overflow: false,
510 format_bar: HashSet::new(),
517 format_bar: HashSet::new(),
518 post_subject: None,
511 active_cell: None,
519 active_cell: None,
512 caret_before_table: 0,
520 caret_before_table: 0,
513 caret_text: String::new(),
521 caret_text: String::new(),
@@ -2925,8 +2933,9 @@ impl Render for Composer {
2925 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2933 .on_click(cx.listener(|this, _, window, cx| this.open_picker(window, cx)))
2926 });
2934 });
2927 let markdown_mode = self.app.read(cx).markdown_mode;
2935 let markdown_mode = self.app.read(cx).markdown_mode;
2928 let format_open = self.format_bar_open() && !markdown_mode;
2936 let post_layout = self.post_layout();
2929 let format_toggle = (!markdown_mode).then(|| {
2937 let format_open = (self.format_bar_open() || post_layout) && !markdown_mode;
2938 let format_toggle = (!markdown_mode && !post_layout).then(|| {
2930 div()
2939 div()
2931 .id("composer-format")
2940 .id("composer-format")
2932 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
2941 .debug_selector(|| COMPOSER_FORMAT_TAG.into())
@@ -2958,6 +2967,20 @@ impl Render for Composer {
2958 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)))
2967 .on_click(cx.listener(|this, _, window, cx| this.toggle_format_bar(window, cx)))
2959 });
2968 });
2960 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2969 let format_bar = format_open.then(|| self.render_format_bar(window, cx));
2970 let actions = h_flex()
2971 .debug_selector(|| COMPOSER_ACTIONS_TAG.into())
2972 .flex_none()
2973 .gap(px(COMPOSER_BUTTON_INSET))
2974 .children(format_toggle)
2975 .children(self.render_delivery_button(cx))
2976 .children(fun)
2977 .children(attach);
2978 let (row_actions, post_footer) = if post_layout {
2979 (None, Some(self.render_post_footer(actions, can_send, cx)))
2980 } else {
2981 (Some(actions.ml(px(COMPOSER_BUTTON_INSET))), None)
2982 };
2983 let post_header = self.render_post_header(cx);
2961 let composer = cx.weak_entity();
2984 let composer = cx.weak_entity();
2962 let tokens_composer = composer.clone();
2985 let tokens_composer = composer.clone();
2963 let input = Textarea::new(&self.input)
2986 let input = Textarea::new(&self.input)
@@ -3396,6 +3419,7 @@ impl Render for Composer {
3396 .absolute()
3419 .absolute()
3397 .size_full(),
3420 .size_full(),
3398 )
3421 )
3422 .children(post_header)
3399 .children(format_bar)
3423 .children(format_bar)
3400 .children(self.render_importance_label(cx))
3424 .children(self.render_importance_label(cx))
3401 .children(tray)
3425 .children(tray)
@@ -3438,19 +3462,10 @@ impl Render for Composer {
3438 )
3462 )
3439 .child(input),
3463 .child(input),
3440 )
3464 )
3441 .child(
3465 .children(row_actions)
3442 h_flex()
3466 .when(!post_layout, |row| row.child(send)),
3443 .debug_selector(|| COMPOSER_ACTIONS_TAG.into())
3467 )
3444 .flex_none()
3468 .children(post_footer),
3445 .ml(px(COMPOSER_BUTTON_INSET))
3446 .gap(px(COMPOSER_BUTTON_INSET))
3447 .children(format_toggle)
3448 .children(self.render_delivery_button(cx))
3449 .children(fun)
3450 .children(attach),
3451 )
3452 .child(send),
3453 ),
3454 ),
3469 ),
3455 )
3470 )
3456 .children(self.render_paste_hint())
3471 .children(self.render_paste_hint())
crates/app/src/views/composer/post.rs added +150 −0
@@ -0,0 +1,150 @@
1 use gpui_kit::component::input::{Input, InputState};
2 use gpui_kit::component::tooltip::Tooltip;
3 use gpui_kit::component::{Sizable as _, Size, h_flex, v_flex};
4 use gpui_kit::prelude::FluentBuilder as _;
5 use gpui_kit::*;
6
7 use super::{COMPOSER_BUTTON_SIZE, Composer, ComposerEvent};
8 use crate::theme;
9 use crate::views::avatar::person_avatar;
10 use crate::views::widgets::symbol;
11
12 pub const POST_CARD_HEADER_TAG: &str = "composer/post/header";
13 pub const POST_CARD_SUBJECT_TAG: &str = "composer/post/subject";
14 pub const POST_CARD_DIVIDER_TAG: &str = "composer/post/divider";
15 pub const POST_CARD_FOOTER_TAG: &str = "composer/post/footer";
16 pub const POST_CARD_SEND_TAG: &str = "composer/post/send";
17 const POST_LABEL: &str = "Post";
18 const CLOSE_TOOLTIP: &str = "Close";
19 const AUTHOR_AVATAR: f32 = 24.;
20 const CARD_INSET: f32 = 12.;
21 const SUBJECT_SIZE: f32 = 18.;
22 const INPUT_TEXT_SCALE: f32 = 0.875;
23 const SUBJECT_INSET: f32 = 8.;
24 const TEXT_INSET: f32 = 16.;
25
26 impl Composer {
27 /// Shows the channel post layout with `subject` above the body, or the chat layout when `None`.
28 pub fn set_post_layout(&mut self, subject: Option<Entity<InputState>>, cx: &mut Context<Self>) {
29 let changed = self.post_subject.as_ref().map(Entity::entity_id)
30 != subject.as_ref().map(Entity::entity_id);
31 self.post_subject = subject;
32 if changed {
33 cx.notify();
34 }
35 }
36
37 pub(super) fn post_layout(&self) -> bool {
38 self.post_subject.is_some() && self.editing.is_none()
39 }
40
41 pub(super) fn render_post_header(&self, cx: &mut Context<Self>) -> Option<Div> {
42 let subject = self.post_subject.clone().filter(|_| self.editing.is_none())?;
43 let directory = &self.app.read(cx).directory;
44 let author = directory.me.as_ref().map(|me| {
45 h_flex()
46 .gap(px(8.))
47 .items_center()
48 .child(person_avatar(
49 directory,
50 Some(&me.user_id),
51 &me.display_name,
52 AUTHOR_AVATAR,
53 ))
54 .child(
55 div()
56 .text_size(px(13.))
57 .font_weight(FontWeight::SEMIBOLD)
58 .text_color(theme::text_strong())
59 .child(me.display_name.clone()),
60 )
61 });
62 let close = div()
63 .id("composer-post-close")
64 .size(px(28.))
65 .flex_none()
66 .flex()
67 .items_center()
68 .justify_center()
69 .rounded(px(6.))
70 .cursor_pointer()
71 .hover(|button| button.bg(theme::popup_hover()))
72 .tooltip(|window, cx| Tooltip::new(CLOSE_TOOLTIP).build(window, cx))
73 .child(symbol("close", 18., theme::text_muted()))
74 .on_click(cx.listener(|_, _, _, cx| cx.emit(ComposerEvent::ClosePost)));
75 Some(
76 v_flex()
77 .w_full()
78 .child(
79 h_flex()
80 .debug_selector(|| POST_CARD_HEADER_TAG.into())
81 .w_full()
82 .pl(px(TEXT_INSET))
83 .pr(px(CARD_INSET))
84 .pt(px(CARD_INSET))
85 .items_center()
86 .children(author)
87 .child(div().flex_1())
88 .child(close),
89 )
90 .child(
91 div()
92 .debug_selector(|| POST_CARD_SUBJECT_TAG.into())
93 .w_full()
94 .px(px(SUBJECT_INSET))
95 .py(px(6.))
96 .font_weight(FontWeight::SEMIBOLD)
97 .child(
98 Input::new(&subject)
99 .appearance(false)
100 .bordered(false)
101 .with_size(Size::Size(px(SUBJECT_SIZE / INPUT_TEXT_SCALE))),
102 ),
103 )
104 .child(
105 div()
106 .debug_selector(|| POST_CARD_DIVIDER_TAG.into())
107 .w_full()
108 .h(px(1.))
109 .bg(theme::border()),
110 ),
111 )
112 }
113
114 pub(super) fn render_post_footer(
115 &self,
116 actions: impl IntoElement,
117 can_send: bool,
118 cx: &mut Context<Self>,
119 ) -> Div {
120 h_flex()
121 .debug_selector(|| POST_CARD_FOOTER_TAG.into())
122 .w_full()
123 .px(px(CARD_INSET))
124 .pb(px(CARD_INSET))
125 .items_center()
126 .child(actions)
127 .child(div().flex_1())
128 .child(
129 div()
130 .id("composer-post-send")
131 .debug_selector(|| POST_CARD_SEND_TAG.into())
132 .h(px(COMPOSER_BUTTON_SIZE))
133 .px(px(14.))
134 .flex()
135 .items_center()
136 .rounded(px(6.))
137 .bg(theme::accent())
138 .text_size(px(13.))
139 .font_weight(FontWeight::SEMIBOLD)
140 .text_color(theme::on_accent())
141 .child(POST_LABEL)
142 .when(!can_send, |button| button.opacity(0.4))
143 .when(can_send, |button| {
144 button.cursor_pointer().on_click(
145 cx.listener(|this, _, window, cx| this.submit_current(window, cx)),
146 )
147 }),
148 )
149 }
150 }
@@ -0,0 +1,150 @@
1use gpui_kit::component::input::{Input, InputState};
2use gpui_kit::component::tooltip::Tooltip;
3use gpui_kit::component::{Sizable as _, Size, h_flex, v_flex};
4use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6
7use super::{COMPOSER_BUTTON_SIZE, Composer, ComposerEvent};
8use crate::theme;
9use crate::views::avatar::person_avatar;
10use crate::views::widgets::symbol;
11
12pub const POST_CARD_HEADER_TAG: &str = "composer/post/header";
13pub const POST_CARD_SUBJECT_TAG: &str = "composer/post/subject";
14pub const POST_CARD_DIVIDER_TAG: &str = "composer/post/divider";
15pub const POST_CARD_FOOTER_TAG: &str = "composer/post/footer";
16pub const POST_CARD_SEND_TAG: &str = "composer/post/send";
17const POST_LABEL: &str = "Post";
18const CLOSE_TOOLTIP: &str = "Close";
19const AUTHOR_AVATAR: f32 = 24.;
20const CARD_INSET: f32 = 12.;
21const SUBJECT_SIZE: f32 = 18.;
22const INPUT_TEXT_SCALE: f32 = 0.875;
23const SUBJECT_INSET: f32 = 8.;
24const TEXT_INSET: f32 = 16.;
25
26impl Composer {
27 /// Shows the channel post layout with `subject` above the body, or the chat layout when `None`.
28 pub fn set_post_layout(&mut self, subject: Option<Entity<InputState>>, cx: &mut Context<Self>) {
29 let changed = self.post_subject.as_ref().map(Entity::entity_id)
30 != subject.as_ref().map(Entity::entity_id);
31 self.post_subject = subject;
32 if changed {
33 cx.notify();
34 }
35 }
36
37 pub(super) fn post_layout(&self) -> bool {
38 self.post_subject.is_some() && self.editing.is_none()
39 }
40
41 pub(super) fn render_post_header(&self, cx: &mut Context<Self>) -> Option<Div> {
42 let subject = self.post_subject.clone().filter(|_| self.editing.is_none())?;
43 let directory = &self.app.read(cx).directory;
44 let author = directory.me.as_ref().map(|me| {
45 h_flex()
46 .gap(px(8.))
47 .items_center()
48 .child(person_avatar(
49 directory,
50 Some(&me.user_id),
51 &me.display_name,
52 AUTHOR_AVATAR,
53 ))
54 .child(
55 div()
56 .text_size(px(13.))
57 .font_weight(FontWeight::SEMIBOLD)
58 .text_color(theme::text_strong())
59 .child(me.display_name.clone()),
60 )
61 });
62 let close = div()
63 .id("composer-post-close")
64 .size(px(28.))
65 .flex_none()
66 .flex()
67 .items_center()
68 .justify_center()
69 .rounded(px(6.))
70 .cursor_pointer()
71 .hover(|button| button.bg(theme::popup_hover()))
72 .tooltip(|window, cx| Tooltip::new(CLOSE_TOOLTIP).build(window, cx))
73 .child(symbol("close", 18., theme::text_muted()))
74 .on_click(cx.listener(|_, _, _, cx| cx.emit(ComposerEvent::ClosePost)));
75 Some(
76 v_flex()
77 .w_full()
78 .child(
79 h_flex()
80 .debug_selector(|| POST_CARD_HEADER_TAG.into())
81 .w_full()
82 .pl(px(TEXT_INSET))
83 .pr(px(CARD_INSET))
84 .pt(px(CARD_INSET))
85 .items_center()
86 .children(author)
87 .child(div().flex_1())
88 .child(close),
89 )
90 .child(
91 div()
92 .debug_selector(|| POST_CARD_SUBJECT_TAG.into())
93 .w_full()
94 .px(px(SUBJECT_INSET))
95 .py(px(6.))
96 .font_weight(FontWeight::SEMIBOLD)
97 .child(
98 Input::new(&subject)
99 .appearance(false)
100 .bordered(false)
101 .with_size(Size::Size(px(SUBJECT_SIZE / INPUT_TEXT_SCALE))),
102 ),
103 )
104 .child(
105 div()
106 .debug_selector(|| POST_CARD_DIVIDER_TAG.into())
107 .w_full()
108 .h(px(1.))
109 .bg(theme::border()),
110 ),
111 )
112 }
113
114 pub(super) fn render_post_footer(
115 &self,
116 actions: impl IntoElement,
117 can_send: bool,
118 cx: &mut Context<Self>,
119 ) -> Div {
120 h_flex()
121 .debug_selector(|| POST_CARD_FOOTER_TAG.into())
122 .w_full()
123 .px(px(CARD_INSET))
124 .pb(px(CARD_INSET))
125 .items_center()
126 .child(actions)
127 .child(div().flex_1())
128 .child(
129 div()
130 .id("composer-post-send")
131 .debug_selector(|| POST_CARD_SEND_TAG.into())
132 .h(px(COMPOSER_BUTTON_SIZE))
133 .px(px(14.))
134 .flex()
135 .items_center()
136 .rounded(px(6.))
137 .bg(theme::accent())
138 .text_size(px(13.))
139 .font_weight(FontWeight::SEMIBOLD)
140 .text_color(theme::on_accent())
141 .child(POST_LABEL)
142 .when(!can_send, |button| button.opacity(0.4))
143 .when(can_send, |button| {
144 button.cursor_pointer().on_click(
145 cx.listener(|this, _, window, cx| this.submit_current(window, cx)),
146 )
147 }),
148 )
149 }
150}
crates/app/src/views/conversation.rs +3 −2
@@ -789,6 +789,7 @@ impl ConversationView {
789 789 ComposerEvent::FocusMessages => window.focus(&self.focus_handle, cx),
790 790 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
791 791 ComposerEvent::Edited => {}
792 ComposerEvent::ClosePost => self.cancel_new_post(window, cx),
792 793 }
793 794 }
794 795
@@ -914,7 +915,7 @@ impl ConversationView {
914 915 }
915 916 self.stop_typing(cx);
916 917 self.stop_reply_typing(cx);
917 self.new_post_open = false;
918 self.close_new_post(cx);
918 919 self.feed_stash = None;
919 920 self.feed_at_top = true;
920 921 self.restore_subject(None, window, cx);
@@ -3991,7 +3992,7 @@ impl Render for ConversationView {
3991 3992 }
3992 3993 let recap_active = self.recap_active();
3993 3994 let empty_channel = in_feed && self.rows.borrow().is_empty();
3994 let new_post = self.render_new_post(window, cx);
3995 let new_post = self.render_new_post(cx);
3995 3996 self.watch_feed_scroll(cx);
3996 3997 let feed_scrolled = new_post.is_some() && self.scroller.read(cx).is_scrolled_from_top();
3997 3998 let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {
@@ -789,6 +789,7 @@ impl ConversationView {
789 ComposerEvent::FocusMessages => window.focus(&self.focus_handle, cx),
789 ComposerEvent::FocusMessages => window.focus(&self.focus_handle, cx),
790 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
790 ComposerEvent::Typing(active) => self.send_typing(*active, cx),
791 ComposerEvent::Edited => {}
791 ComposerEvent::Edited => {}
792 ComposerEvent::ClosePost => self.cancel_new_post(window, cx),
792 }
793 }
793 }
794 }
794
795
@@ -914,7 +915,7 @@ impl ConversationView {
914 }
915 }
915 self.stop_typing(cx);
916 self.stop_typing(cx);
916 self.stop_reply_typing(cx);
917 self.stop_reply_typing(cx);
917 self.new_post_open = false;
918 self.close_new_post(cx);
918 self.feed_stash = None;
919 self.feed_stash = None;
919 self.feed_at_top = true;
920 self.feed_at_top = true;
920 self.restore_subject(None, window, cx);
921 self.restore_subject(None, window, cx);
@@ -3991,7 +3992,7 @@ impl Render for ConversationView {
3991 }
3992 }
3992 let recap_active = self.recap_active();
3993 let recap_active = self.recap_active();
3993 let empty_channel = in_feed && self.rows.borrow().is_empty();
3994 let empty_channel = in_feed && self.rows.borrow().is_empty();
3994 let new_post = self.render_new_post(window, cx);
3995 let new_post = self.render_new_post(cx);
3995 self.watch_feed_scroll(cx);
3996 self.watch_feed_scroll(cx);
3996 let feed_scrolled = new_post.is_some() && self.scroller.read(cx).is_scrolled_from_top();
3997 let feed_scrolled = new_post.is_some() && self.scroller.read(cx).is_scrolled_from_top();
3997 let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {
3998 let body = if drafting && self.current.is_none() && self.rows.borrow().is_empty() {
crates/app/src/views/conversation/feed.rs +32 −56
@@ -4,7 +4,7 @@ use std::rc::Rc;
4 4 use gpui_kit::component::{
5 5 button::{Button, ButtonVariants as _},
6 6 h_flex,
7 input::{Input, InputEvent, InputState},
7 input::{InputEvent, InputState},
8 8 message_scroller::MessageScrollerState,
9 9 v_flex,
10 10 };
@@ -14,7 +14,6 @@ use super::{ConversationView, ViewMode};
14 14 use crate::notice::short_error;
15 15 use crate::rows::Row;
16 16 use crate::runtime;
17 use crate::theme;
18 17 use crate::views::channel_tabs::ChannelPane;
19 18 use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};
20 19 use crate::views::post_card::{PostAction, post_in_channel_card};
@@ -45,13 +44,22 @@ impl ConversationView {
45 44 }
46 45
47 46 pub(super) fn open_new_post(&mut self, window: &mut Window, cx: &mut Context<Self>) {
48 self.new_post_open = true;
47 self.mark_new_post_open(cx);
49 48 self.composer
50 49 .update(cx, |composer, cx| composer.focus(window, cx));
50 }
51
52 fn mark_new_post_open(&mut self, cx: &mut Context<Self>) {
53 self.new_post_open = true;
54 let subject = self.subject.clone();
55 self.composer
56 .update(cx, |composer, cx| composer.set_post_layout(Some(subject), cx));
51 57 cx.notify();
52 58 }
53 59
54 60 pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {
61 self.composer
62 .update(cx, |composer, cx| composer.set_post_layout(None, cx));
55 63 if self.new_post_open {
56 64 self.new_post_open = false;
57 65 cx.notify();
@@ -212,7 +220,8 @@ impl ConversationView {
212 220 ComposerEvent::Edited => self.keep_reply_editor_in_view(window, cx),
213 221 ComposerEvent::Schedule { .. }
214 222 | ComposerEvent::EditLast
215 | ComposerEvent::FocusMessages => {}
223 | ComposerEvent::FocusMessages
224 | ComposerEvent::ClosePost => {}
216 225 }
217 226 }
218 227
@@ -228,16 +237,11 @@ impl ConversationView {
228 237
229 238 pub(super) fn show_main_composer(&mut self, cx: &mut Context<Self>) {
230 239 if self.in_feed() {
231 self.new_post_open = true;
232 cx.notify();
240 self.mark_new_post_open(cx);
233 241 }
234 242 }
235 243
236 pub(super) fn render_new_post(
237 &self,
238 window: &Window,
239 cx: &mut Context<Self>,
240 ) -> Option<AnyElement> {
244 pub(super) fn render_new_post(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
241 245 if !self.in_feed() || self.pane != ChannelPane::Posts {
242 246 return None;
243 247 }
@@ -264,57 +268,29 @@ impl ConversationView {
264 268 );
265 269 }
266 270 let editing = self.composer.read(cx).is_editing();
267 let focused = self
268 .subject
269 .read(cx)
270 .focus_handle(cx)
271 .contains_focused(window, cx);
272 let subject = (!editing).then(|| {
273 div().w_full().px(px(20.)).pt(px(12.)).child(
274 div()
275 .w_full()
276 .h(px(36.))
277 .px(px(12.))
278 .flex()
279 .items_center()
280 .rounded(px(10.))
281 .bg(theme::surface_raised())
282 .border_1()
283 .border_color(if focused {
284 theme::accent()
285 } else {
286 transparent_black()
287 })
288 .child(
289 div()
290 .w_full()
291 .child(Input::new(&self.subject).appearance(false).bordered(false)),
292 ),
293 )
271 let cancel = editing.then(|| {
272 h_flex()
273 .w_full()
274 .px(px(20.))
275 .pb(px(12.))
276 .justify_end()
277 .child(
278 Button::new("cancel-new-post")
279 .ghost()
280 .compact()
281 .label("Cancel")
282 .on_click(cx.listener(|this, _, window, cx| {
283 this.cancel_new_post(window, cx)
284 })),
285 )
294 286 });
295 287 Some(
296 288 v_flex()
297 289 .w_full()
298 290 .flex_none()
299 .children(subject)
300 291 .children(proposal_card)
301 .child(self.composer.clone())
302 .child(
303 h_flex()
304 .w_full()
305 .px(px(20.))
306 .pb(px(12.))
307 .justify_end()
308 .child(
309 Button::new("cancel-new-post")
310 .ghost()
311 .compact()
312 .label("Cancel")
313 .on_click(cx.listener(|this, _, window, cx| {
314 this.cancel_new_post(window, cx)
315 })),
316 ),
317 )
292 .child(div().w_full().pt(px(12.)).child(self.composer.clone()))
293 .children(cancel)
318 294 .into_any_element(),
319 295 )
320 296 }
@@ -4,7 +4,7 @@ use std::rc::Rc;
4use gpui_kit::component::{
4use gpui_kit::component::{
5 button::{Button, ButtonVariants as _},
5 button::{Button, ButtonVariants as _},
6 h_flex,
6 h_flex,
7 input::{Input, InputEvent, InputState},
7 input::{InputEvent, InputState},
8 message_scroller::MessageScrollerState,
8 message_scroller::MessageScrollerState,
9 v_flex,
9 v_flex,
10};
10};
@@ -14,7 +14,6 @@ use super::{ConversationView, ViewMode};
14use crate::notice::short_error;
14use crate::notice::short_error;
15use crate::rows::Row;
15use crate::rows::Row;
16use crate::runtime;
16use crate::runtime;
17use crate::theme;
18use crate::views::channel_tabs::ChannelPane;
17use crate::views::channel_tabs::ChannelPane;
19use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};
18use crate::views::composer::{Composer, ComposerEvent, ReplyPreview};
20use crate::views::post_card::{PostAction, post_in_channel_card};
19use crate::views::post_card::{PostAction, post_in_channel_card};
@@ -45,13 +44,22 @@ impl ConversationView {
45 }
44 }
46
45
47 pub(super) fn open_new_post(&mut self, window: &mut Window, cx: &mut Context<Self>) {
46 pub(super) fn open_new_post(&mut self, window: &mut Window, cx: &mut Context<Self>) {
48 self.new_post_open = true;
47 self.mark_new_post_open(cx);
49 self.composer
48 self.composer
50 .update(cx, |composer, cx| composer.focus(window, cx));
49 .update(cx, |composer, cx| composer.focus(window, cx));
50 }
51
52 fn mark_new_post_open(&mut self, cx: &mut Context<Self>) {
53 self.new_post_open = true;
54 let subject = self.subject.clone();
55 self.composer
56 .update(cx, |composer, cx| composer.set_post_layout(Some(subject), cx));
51 cx.notify();
57 cx.notify();
52 }
58 }
53
59
54 pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {
60 pub(super) fn close_new_post(&mut self, cx: &mut Context<Self>) {
61 self.composer
62 .update(cx, |composer, cx| composer.set_post_layout(None, cx));
55 if self.new_post_open {
63 if self.new_post_open {
56 self.new_post_open = false;
64 self.new_post_open = false;
57 cx.notify();
65 cx.notify();
@@ -212,7 +220,8 @@ impl ConversationView {
212 ComposerEvent::Edited => self.keep_reply_editor_in_view(window, cx),
220 ComposerEvent::Edited => self.keep_reply_editor_in_view(window, cx),
213 ComposerEvent::Schedule { .. }
221 ComposerEvent::Schedule { .. }
214 | ComposerEvent::EditLast
222 | ComposerEvent::EditLast
215 | ComposerEvent::FocusMessages => {}
223 | ComposerEvent::FocusMessages
224 | ComposerEvent::ClosePost => {}
216 }
225 }
217 }
226 }
218
227
@@ -228,16 +237,11 @@ impl ConversationView {
228
237
229 pub(super) fn show_main_composer(&mut self, cx: &mut Context<Self>) {
238 pub(super) fn show_main_composer(&mut self, cx: &mut Context<Self>) {
230 if self.in_feed() {
239 if self.in_feed() {
231 self.new_post_open = true;
240 self.mark_new_post_open(cx);
232 cx.notify();
233 }
241 }
234 }
242 }
235
243
236 pub(super) fn render_new_post(
244 pub(super) fn render_new_post(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
237 &self,
238 window: &Window,
239 cx: &mut Context<Self>,
240 ) -> Option<AnyElement> {
241 if !self.in_feed() || self.pane != ChannelPane::Posts {
245 if !self.in_feed() || self.pane != ChannelPane::Posts {
242 return None;
246 return None;
243 }
247 }
@@ -264,57 +268,29 @@ impl ConversationView {
264 );
268 );
265 }
269 }
266 let editing = self.composer.read(cx).is_editing();
270 let editing = self.composer.read(cx).is_editing();
267 let focused = self
271 let cancel = editing.then(|| {
268 .subject
272 h_flex()
269 .read(cx)
273 .w_full()
270 .focus_handle(cx)
274 .px(px(20.))
271 .contains_focused(window, cx);
275 .pb(px(12.))
272 let subject = (!editing).then(|| {
276 .justify_end()
273 div().w_full().px(px(20.)).pt(px(12.)).child(
277 .child(
274 div()
278 Button::new("cancel-new-post")
275 .w_full()
279 .ghost()
276 .h(px(36.))
280 .compact()
277 .px(px(12.))
281 .label("Cancel")
278 .flex()
282 .on_click(cx.listener(|this, _, window, cx| {
279 .items_center()
283 this.cancel_new_post(window, cx)
280 .rounded(px(10.))
284 })),
281 .bg(theme::surface_raised())
285 )
282 .border_1()
283 .border_color(if focused {
284 theme::accent()
285 } else {
286 transparent_black()
287 })
288 .child(
289 div()
290 .w_full()
291 .child(Input::new(&self.subject).appearance(false).bordered(false)),
292 ),
293 )
294 });
286 });
295 Some(
287 Some(
296 v_flex()
288 v_flex()
297 .w_full()
289 .w_full()
298 .flex_none()
290 .flex_none()
299 .children(subject)
300 .children(proposal_card)
291 .children(proposal_card)
301 .child(self.composer.clone())
292 .child(div().w_full().pt(px(12.)).child(self.composer.clone()))
302 .child(
293 .children(cancel)
303 h_flex()
304 .w_full()
305 .px(px(20.))
306 .pb(px(12.))
307 .justify_end()
308 .child(
309 Button::new("cancel-new-post")
310 .ghost()
311 .compact()
312 .label("Cancel")
313 .on_click(cx.listener(|this, _, window, cx| {
314 this.cancel_new_post(window, cx)
315 })),
316 ),
317 )
318 .into_any_element(),
294 .into_any_element(),
319 )
295 )
320 }
296 }