Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
inbox: Add dropdown to filter topics.
Aman Agrawalf191efce1bfa
diff --git a/web/src/inbox_ui.js b/web/src/inbox_ui.jsindex 21ee0f6b305..7b00521000d 100644--- a/web/src/inbox_ui.js+++ b/web/src/inbox_ui.js@@ -9,7 +9,9 @@ import render_user_with_status_icon from "../templates/user_with_status_icon.hbsimport * as buddy_data from "./buddy_data";import * as compose_closed_ui from "./compose_closed_ui";import * as compose_state from "./compose_state";+import * as dropdown_widget from "./dropdown_widget";import * as hash_util from "./hash_util";+import {$t} from "./i18n";import {is_visible, set_visible} from "./inbox_util";import * as keydown_util from "./keydown_util";import * as left_sidebar_navigation_area from "./left_sidebar_navigation_area";@@ -35,6 +37,12 @@ let topics_dict = new Map();let streams_dict = new Map();let update_triggered_by_user = false;+const FILTERS = {+ ALL_TOPICS: "all_topics",+ UNMUTED_TOPICS: "unmuted_topics",+ FOLLOWED_TOPICS: "followed_topics",+};+const COLUMNS = {COLLAPSE_BUTTON: 0,RECIPIENT: 1,@@ -45,16 +53,16 @@ const COLUMNS = {let col_focus = COLUMNS.COLLAPSE_BUTTON;let row_focus = 0;-const ls_filter_key = "inbox_filters";+const ls_filter_key = "inbox-filters";const ls_collapsed_containers_key = "inbox_collapsed_containers";const ls = localstorage();-let filters = new Set();+let filters = new Set([FILTERS.UNMUTED_TOPICS]);let collapsed_containers = new Set();let search_keyword = "";const INBOX_SEARCH_ID = "inbox-search";-const MUTED_FILTER_ID = "include_muted";+const INBOX_FILTERS_DROPDOWN_ID = "inbox-filter_widget";export let current_focus_id;const STREAM_HEADER_PREFIX = "inbox-stream-header-";@@ -72,10 +80,6 @@ function save_data_to_ls() {ls.set(ls_collapsed_containers_key, [...collapsed_containers]);}-function should_include_muted() {- return filters.has(MUTED_FILTER_ID);-}-export function show() {// Avoid setting col_focus to recipient when moving to inbox from other narrows.// We prefer to focus entire row instead of stream name for inbox-header.@@ -127,36 +131,16 @@ function get_stream_header_row(stream_id) {}function load_data_from_ls() {- filters = new Set(ls.get(ls_filter_key));- collapsed_containers = new Set(ls.get(ls_collapsed_containers_key));- update_filters();-}--function update_filters() {- const $mute_checkbox = $("#inbox-filters #inbox_filter_mute_toggle");- const $mute_filter = $("#inbox-filters .btn-inbox-filter");- if (should_include_muted()) {- $mute_checkbox.removeClass("fa-square-o");- $mute_checkbox.addClass("fa-check-square-o");- $mute_filter.addClass("btn-inbox-selected");- } else {- $mute_checkbox.removeClass("fa-check-square-o");- $mute_checkbox.addClass("fa-square-o");- $mute_filter.removeClass("btn-inbox-selected");- }-}--export function toggle_muted_filter() {- const $mute_filter = $("#inbox-filters .btn-inbox-filter");- if ($mute_filter.hasClass("btn-inbox-selected")) {- filters.delete(MUTED_FILTER_ID);+ const saved_filters = new Set(ls.get(ls_filter_key));+ const valid_filters = new Set(Object.values(FILTERS));+ // If saved filters are not in the list of valid filters, we reset to default.+ const is_subset = [...saved_filters].every((filter) => valid_filters.has(filter));+ if (saved_filters.size === 0 || !is_subset) {+ filters = new Set([FILTERS.UNMUTED_TOPICS]);} else {- filters.add(MUTED_FILTER_ID);+ filters = saved_filters;}-- update_filters();- save_data_to_ls();- update();+ collapsed_containers = new Set(ls.get(ls_collapsed_containers_key));}function format_dm(user_ids_string, unread_count, latest_msg_id) {@@ -518,6 +502,36 @@ function show_empty_inbox_text(has_visible_unreads) {}}+function filters_dropdown_options() {+ return [+ {+ unique_id: FILTERS.ALL_TOPICS,+ name: $t({defaultMessage: "All topics"}),+ },+ {+ unique_id: FILTERS.UNMUTED_TOPICS,+ name: $t({defaultMessage: "Unmuted topics"}),+ },+ {+ unique_id: FILTERS.FOLLOWED_TOPICS,+ name: $t({defaultMessage: "Followed topics"}),+ },+ ];+}++function filter_click_handler(event, dropdown, widget) {+ event.preventDefault();+ event.stopPropagation();++ const filter_id = $(event.currentTarget).attr("data-unique-id");+ // We don't support multiple filters yet, so we clear existing and add the new filter.+ filters = new Set([filter_id]);+ save_data_to_ls();+ dropdown.hide();+ widget.render();+ update();+}+export function complete_rerender() {if (!is_visible()) {return;@@ -527,16 +541,13 @@ export function complete_rerender() {$("#inbox-pane").html(render_inbox_view({search_val: search_keyword,- include_muted: should_include_muted(),INBOX_SEARCH_ID,- MUTED_FILTER_ID,dms_dict,topics_dict,streams_dict,...additional_context,}),);- update_filters();show_empty_inbox_text(has_visible_unreads);// If the focus is not on the inbox rows, the inbox view scrolls// down when moving from other views to the inbox view. To avoid@@ -547,6 +558,20 @@ export function complete_rerender() {$("#inbox-list .simplebar-content-wrapper").attr("tabindex", "-1");revive_current_focus();}, 0);++ new dropdown_widget.DropdownWidget({+ widget_name: "inbox-filter",+ get_options: filters_dropdown_options,+ item_click_callback: filter_click_handler,+ $events_container: $("#inbox-main"),+ tippy_props: {+ placement: "bottom-start",+ offset: [0, 2],+ },+ unique_id_type: dropdown_widget.DATA_TYPES.STRING,+ default_id: filters.values().next().value,+ hide_search_box: true,+ }).setup();}export function search_and_update() {@@ -579,16 +604,21 @@ function filter_should_hide_row({stream_id, topic, dm_key}) {return true;}- if (user_topics.is_topic_unmuted_or_followed(stream_id, topic)) {- return false;+ if (+ filters.has(FILTERS.FOLLOWED_TOPICS) &&+ !user_topics.is_topic_followed(stream_id, topic)+ ) {+ return true;}if (- !should_include_muted() &&- (stream_data.is_muted(stream_id) || user_topics.is_topic_muted(stream_id, topic))+ filters.has(FILTERS.UNMUTED_TOPICS) &&+ (user_topics.is_topic_muted(stream_id, topic) || stream_data.is_muted(stream_id)) &&+ !user_topics.is_topic_unmuted_or_followed(stream_id, topic)) {return true;}+text = (sub.name + " " + topic).toLowerCase();}@@ -635,7 +665,7 @@ function focus_inbox_search() {}function is_list_focused() {- return ![INBOX_SEARCH_ID, MUTED_FILTER_ID].includes(current_focus_id);+ return ![INBOX_SEARCH_ID, INBOX_FILTERS_DROPDOWN_ID].includes(current_focus_id);}function get_all_rows() {@@ -821,17 +851,17 @@ function set_list_focus(input_key) {$($cols_to_focus[col_focus]).trigger("focus");}-function focus_muted_filter() {- current_focus_id = MUTED_FILTER_ID;- focus_current_id();+function focus_filters_dropdown() {+ current_focus_id = INBOX_FILTERS_DROPDOWN_ID;+ $(`#${INBOX_FILTERS_DROPDOWN_ID}`).trigger("focus");}function is_search_focused() {return current_focus_id === INBOX_SEARCH_ID;}-function is_muted_filter_focused() {- return current_focus_id === MUTED_FILTER_ID;+function is_filters_dropdown_focused() {+ return current_focus_id === INBOX_FILTERS_DROPDOWN_ID;}function get_page_up_down_delta() {@@ -896,7 +926,7 @@ export function change_focused_element(input_key) {if (end !== text_length || is_selected) {return false;}- focus_muted_filter();+ focus_filters_dropdown();return true;case "escape":if (get_all_rows().length === 0) {@@ -909,7 +939,7 @@ export function change_focused_element(input_key) {current_focus_id = "";return false;}- } else if (is_muted_filter_focused()) {+ } else if (is_filters_dropdown_focused()) {switch (input_key) {case "down_arrow":case "tab":@@ -1249,13 +1279,6 @@ export function initialize() {window.location.href = $elt.find("a").attr("href");});- $("body").on("click", "#include_muted", () => {- current_focus_id = MUTED_FILTER_ID;- update_triggered_by_user = true;- toggle_muted_filter();- compose_closed_ui.set_standard_text_for_reply_button();- });-$("body").on("click", "#inbox-list .on_hover_dm_read", (e) => {e.stopPropagation();e.preventDefault();diff --git a/web/styles/inbox.css b/web/styles/inbox.cssindex f6f0676aa9a..3324dc8daa4 100644--- a/web/styles/inbox.css+++ b/web/styles/inbox.css@@ -143,8 +143,11 @@border-radius: 5px;border: 1px solid hsl(0deg 0% 0% / 20%);margin-bottom: var(--max-unexpanded-compose-height);- /* Width of muted filter(130) + margin(10) + search padding(50) = 190px */- max-width: calc(var(--width-inbox-search) + 190px);+ /* margin(5) + search left padding(30) + search right padding (28) = 63px */+ max-width: calc(+ var(--width-inbox-search) + var(--width-inbox-filters-dropdown) ++ 63px+ );.inbox-focus-border {display: flex;@@ -435,14 +438,6 @@align-items: center;}- #inbox_filter_mute_toggle {- font-size: 16px;- width: 16px;- height: 16px;- position: relative;- top: 1px;- }-.inbox-row,.inbox-header {&:focus,@@ -528,3 +523,43 @@text-decoration: underline;color: hsl(200deg 100% 40%);}++#inbox-filter_widget {+ margin-left: 5px;+ height: 30px;+ max-width: var(--width-inbox-filters-dropdown);+ border: 1px solid var(--color-border-inbox-search);+ background-color: var(--color-background-inbox-search);+ gap: 5px;++ &:hover {+ background-color: var(--color-background-inbox-search-hover);+ border: 1px solid var(--color-border-inbox-search-hover);+ }++ &:focus {+ outline: none;+ }++ &:focus-visible {+ outline: 2px solid var(--color-outline-focus);+ }+}++#inbox-filter_widget .dropdown_widget_value {+ text-overflow: ellipsis;+ white-space: nowrap;+ overflow: hidden;+ width: 100%;+ text-align: left;+}++#inbox-filter_widget .fa-chevron-down {+ color: var(--color-icons-inbox);+ opacity: 0.4;+}++.inbox-filter-dropdown-list-container .dropdown-list-wrapper {+ width: var(--width-inbox-filters-dropdown);+ min-width: unset;+}diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex 9a5aebacf06..e82c5b322d0 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -294,6 +294,7 @@ body {/* Inbox view constants - Values from Figma design */--height-inbox-search: 26px;--width-inbox-search: 346px;+ --width-inbox-filters-dropdown: 150px;--color-background-inbox-no-unreads-illustration: hsl(147deg 57% 25%);--color-background-inbox: var(--color-background);--color-icon-search-inbox: hsl(0deg 0% 0%);diff --git a/web/templates/dropdown_list_container.hbs b/web/templates/dropdown_list_container.hbsindex 2d29a20983d..db95fb31b6a 100644--- a/web/templates/dropdown_list_container.hbs+++ b/web/templates/dropdown_list_container.hbs@@ -1,4 +1,4 @@-<div class="dropdown-list-container">+<div class="dropdown-list-container {{widget_name}}-dropdown-list-container"><div class="dropdown-list-search"><input class="dropdown-list-search-input filter_text_input{{#if hide_search_box}} hide{{/if}}" type="text" placeholder="{{t 'Filter' }}" autofocus/></div>diff --git a/web/templates/inbox_view/inbox_view.hbs b/web/templates/inbox_view/inbox_view.hbsindex 7028e31b003..7706f254d0e 100644--- a/web/templates/inbox_view/inbox_view.hbs+++ b/web/templates/inbox_view/inbox_view.hbs@@ -5,10 +5,7 @@<i class="zulip-icon zulip-icon-close-small"></i></button><i class="zulip-icon zulip-icon-search-inbox"></i>- <button data-filter="include_muted" id="{{MUTED_FILTER_ID}}" type="button" class="btn btn-default btn-inbox-filter {{#if is_spectator}}fake_disabled_button{{/if}}" role="checkbox" aria-checked="false" tabindex="0">- <i id="inbox_filter_mute_toggle" class="fa fa-square-o"></i>- {{t 'Include muted' }}- </button>+ {{> ../dropdown_widget widget_name="inbox-filter"}}</div><div id="inbox-empty-with-search" class="inbox-empty-text empty-list-message">{{t "No conversations match your filters."}}