Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose: Conditionally render placeholder for general chat.

Karl Stolley1bc53831c7b0
diff --git a/web/src/compose_actions.ts b/web/src/compose_actions.ts
index 24e47384f31..b700a62635e 100644
--- a/web/src/compose_actions.ts
+++ b/web/src/compose_actions.ts
@@ -352,7 +352,7 @@ export let start = (raw_opts: ComposeActionsStartOpts): void => {
compose_state.set_stream_id("");
compose_recipient.toggle_compose_recipient_dropdown();
}
- compose_state.topic(opts.topic);
+ compose_recipient.update_topic_displayed_text(opts.topic);
// Set the recipients with a space after each comma, so it looks nice.
compose_state.private_message_recipient(
@@ -535,7 +535,7 @@ export let on_topic_narrow = (): void => {
// we should update the compose topic to match the new narrow.
// See #3300 for context--a couple users specifically asked for
// this convenience.
- compose_state.topic(narrow_state.topic());
+ compose_recipient.update_topic_displayed_text(narrow_state.topic());
compose_validate.warn_if_topic_resolved(true);
compose_fade.set_focused_recipient("stream");
compose_fade.update_message_list();
diff --git a/web/src/compose_recipient.ts b/web/src/compose_recipient.ts
index b8cc0cc8773..3cb3d59e52c 100644
--- a/web/src/compose_recipient.ts
+++ b/web/src/compose_recipient.ts
@@ -348,6 +348,33 @@ export function initialize(): void {
$("#private_message_recipient").on("input", restore_placeholder_in_firefox_for_no_input);
}
+export function update_topic_displayed_text(topic_name: string | undefined): void {
+ if (topic_name === undefined) {
+ topic_name = "";
+ }
+ // When topics are mandatory, we just call topic() as usual.
+ if (realm.realm_mandatory_topics) {
+ compose_state.topic(topic_name);
+ return;
+ }
+ // Otherwise, we have some adjustments to make to display the
+ // general topic as a stylized placeholder
+ const $input = $("input#stream_message_recipient_topic");
+ const is_empty_string_topic = topic_name === "";
+ let topic_placeholder_text = $t({defaultMessage: "Topic"});
+
+ // Remove any stale references to the empty topic display
+ $input.removeClass("empty-topic-display");
+
+ if (is_empty_string_topic) {
+ topic_placeholder_text = util.get_final_topic_display_name("");
+ $input.addClass("empty-topic-display");
+ }
+
+ $input.attr("placeholder", topic_placeholder_text);
+ compose_state.topic(topic_name);
+}
+
export let update_compose_area_placeholder_text = (): void => {
const $textarea: JQuery<HTMLTextAreaElement> = $("textarea#compose-textarea");
// Change compose placeholder text only if compose box is open.
diff --git a/web/styles/compose.css b/web/styles/compose.css
index 38d981fb082..39315f45e75 100644
--- a/web/styles/compose.css
+++ b/web/styles/compose.css
@@ -1062,6 +1062,10 @@ textarea.new_message_textarea {
padding: 4px 6px;
/* Reset height to let `align-items: stretch` on the grid parent handle this. */
height: auto;
+
+ &.empty-topic-display::placeholder {
+ color: var(--color-compose-recipient-box-text-color);
+ }
}
/* Styles for new conversation button in the recipient_box */