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.

left_sidebar: Add plus icon to channel section headers.

Evy Kassirer739debf7b408
diff --git a/web/src/left_sidebar_tooltips.ts b/web/src/left_sidebar_tooltips.ts
index 0fc9de2008a..73b9427ac26 100644
--- a/web/src/left_sidebar_tooltips.ts
+++ b/web/src/left_sidebar_tooltips.ts
@@ -136,6 +136,11 @@ export function initialize(): void {
},
});
+ tippy.delegate("body", {
+ target: ".stream-list-section-container .add-stream-tooltip",
+ appendTo: () => document.body,
+ });
+
tippy.delegate("body", {
target: "#add_streams_tooltip",
onShow(instance) {
diff --git a/web/src/stream_list.ts b/web/src/stream_list.ts
index a627c521475..6b636b179fc 100644
--- a/web/src/stream_list.ts
+++ b/web/src/stream_list.ts
@@ -262,10 +262,15 @@ export function create_initial_sidebar_rows(force_rerender = false): void {
}
}
-export let stream_list_section_container_html = function (section: StreamListSection): string {
+export let stream_list_section_container_html = function (
+ section: StreamListSection,
+ can_create_streams: boolean,
+): string {
return render_stream_list_section_container({
id: section.id,
section_title: section.section_title,
+ show_plus_icon:
+ can_create_streams && !["pinned-streams", "dormant-streams"].includes(section.id),
});
};
@@ -301,8 +306,14 @@ export function build_stream_list(force_rerender: boolean): void {
clear_topics();
$("#stream_filters").empty();
+ const can_create_streams =
+ settings_data.user_can_create_private_streams() ||
+ settings_data.user_can_create_public_streams() ||
+ settings_data.user_can_create_web_public_streams();
for (const section of stream_groups.sections) {
- $("#stream_filters").append($(stream_list_section_container_html(section)));
+ $("#stream_filters").append(
+ $(stream_list_section_container_html(section, can_create_streams)),
+ );
const is_empty = section.streams.length === 0 && section.muted_streams.length === 0;
$(`#stream-list-${section.id}-container`).toggleClass("no-display", is_empty);
@@ -1108,6 +1119,15 @@ export function set_event_handlers({
toggle_section_collapse($(this).closest(".stream-list-section-container"));
},
);
+
+ $("#streams_list").on(
+ "click",
+ ".stream-list-section-container .add-stream-icon-container",
+ (e) => {
+ // To prevent toggling the header
+ e.stopPropagation();
+ },
+ );
}
export function searching(): boolean {
diff --git a/web/styles/left_sidebar.css b/web/styles/left_sidebar.css
index 35ebbe8a0b7..70951996e95 100644
--- a/web/styles/left_sidebar.css
+++ b/web/styles/left_sidebar.css
@@ -336,9 +336,17 @@
.stream-list-subsection-header {
display: grid;
align-items: center;
+ /* There's no three-dot menu here, but we still want the markers to line-up with
+ markers in other rows that do have three-dot menus. */
grid-template:
- "arrow row-content" var(--line-height-sidebar-row-prominent)
- / var(--right-sidebar-header-icon-toggle-width) minmax(0, 1fr);
+ "arrow row-content add-channel three-dot-placeholder" var(
+ --line-height-sidebar-row-prominent
+ )
+ / var(--right-sidebar-header-icon-toggle-width) minmax(0, 1fr) minmax(
+ 0,
+ max-content
+ )
+ var(--left-sidebar-vdots-width);
cursor: pointer;
background-color: var(--color-background);
position: sticky;
@@ -353,6 +361,19 @@
below. This extra margin prevents that overlap. */
margin-bottom: 1px;
+ .add-stream-icon-container {
+ text-decoration: none;
+ grid-auto-columns: var(--left-sidebar-header-icon-width);
+ /* -4px for the 2px top and bottom padding in .add-stream-icon-container */
+ grid-template-rows: calc(
+ var(--line-height-sidebar-row-prominent) - 4px
+ );
+ }
+
+ .add_stream_icon {
+ visibility: hidden;
+ }
+
&:hover {
background-color: var(--color-background-opaque-hover-narrow-filter);
box-shadow: inset 0 0 0 1px var(--color-shadow-sidebar-row-hover);
@@ -365,6 +386,10 @@
.stream-list-section-toggle {
opacity: var(--opacity-sidebar-heading-hover);
}
+
+ .add_stream_icon {
+ visibility: visible;
+ }
}
.stream-list-section-toggle {
diff --git a/web/templates/stream_list_section_container.hbs b/web/templates/stream_list_section_container.hbs
index 3489f2a4bf5..a64f7f7b851 100644
--- a/web/templates/stream_list_section_container.hbs
+++ b/web/templates/stream_list_section_container.hbs
@@ -4,6 +4,11 @@
<h4 class="left-sidebar-title">
{{section_title}}
</h4>
+ {{#if show_plus_icon}}
+ <a href="#channels/new" class="add-stream-tooltip add-stream-icon-container hidden-for-spectators" data-tippy-content="{{t 'Create a channel' }}">
+ <i class="add_stream_icon zulip-icon zulip-icon-square-plus" aria-hidden="true" ></i>
+ </a>
+ {{/if}}
</div>
<ul id="stream-list-{{id}}" class="stream-list-section"></ul>
</div>
diff --git a/web/tests/stream_list.test.cjs b/web/tests/stream_list.test.cjs
index b5cf634bcad..5ff7758fb34 100644
--- a/web/tests/stream_list.test.cjs
+++ b/web/tests/stream_list.test.cjs
@@ -48,6 +48,16 @@ const stream_list_sort = zrequire("stream_list_sort");
const user_groups = zrequire("user_groups");
const {initialize_user_settings} = zrequire("user_settings");
const settings_config = zrequire("settings_config");
+mock_esm("../src/settings_data", {
+ user_can_create_private_streams: () => true,
+ user_can_create_public_streams: () => true,
+ user_can_create_web_public_streams: () => true,
+ user_has_permission_for_group_setting: () => true,
+ should_mask_unread_count: () => false,
+});
+mock_esm("../src/unread_ui", {
+ update_unread_counts: noop,
+});
// Start with always filtering out inactive streams.
const user_settings = {