Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
popup_banners: Redesign update read flag progress banners.
Sayam Samal76810434a12f
diff --git a/templates/zerver/app/index.html b/templates/zerver/app/index.htmlindex 61c0182cfd0..f9df8c9519c 100644--- a/templates/zerver/app/index.html+++ b/templates/zerver/app/index.html@@ -178,20 +178,6 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1943053 --><div id="alert-popup-container"><div id="popup_banners_wrapper" class="banner-wrapper alert-box"><div class="alert alert_sidebar alert-error home-error-bar" id="home-error"></div>- <div class="alert alert_sidebar" id="request-progress-status-banner">- <div class="alert-zulip-logo">- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 774 774">- <circle cx="387" cy="387" r="370"></circle>- <path d="M567.32 527.81c0 33.07-24.26 60.11-53.91 60.11H260.59c-29.65 0-53.91-27.04-53.91-60.11 0-20.24 9.10-38.25 22.95-49.14l134.50-120.12c2.50-2.14 5.75 1.31 3.94 4.20l-49.34 98.79c-1.38 2.76.41 6.17 3.25 6.17h191.42c29.65 0 53.91 27.04 53.91 60.11zm0-281.75c0 20.24-9.10 38.25-22.95 49.14l-134.50 120.12c-2.50 2.14-5.75-1.31-3.94-4.20l49.34-98.79c1.38-2.76-.41-6.17-3.25-6.17H260.59c-29.65 0-53.91-27.04-53.91-60.11s24.26-60.11 53.91-60.11h252.81c29.65 0 53.91 27.04 53.91 60.11z"></path>- </svg>- </div>- <div class="loading-indicator"></div>- <div class="success-indicator">- <i class="fa fa-check"></i>- </div>- <div class="alert-content"></div>- <div class="exit"></div>- </div></div></div>diff --git a/web/src/common.ts b/web/src/common.tsindex fa6bf86358c..f368c082331 100644--- a/web/src/common.ts+++ b/web/src/common.ts@@ -4,7 +4,7 @@ import * as tippy from "tippy.js";import {$t} from "./i18n.ts";import * as util from "./util.ts";-export const status_classes = "alert-error alert-success alert-info alert-warning alert-loading";+export const status_classes = "alert-error alert-success alert-info alert-warning";export function phrase_match(query: string, phrase: string): boolean {// match "tes" to "test" and "stream test" but not "hostess"diff --git a/web/src/popup_banners.ts b/web/src/popup_banners.tsindex b5b31f7aa37..a3dad5b0521 100644--- a/web/src/popup_banners.ts+++ b/web/src/popup_banners.ts@@ -106,6 +106,99 @@ const reloading_application_banner = (reason: ReloadingReason): Banner => {};};+const update_read_flags_for_narrow_banner = (+ operation: "unread" | "read",+ messages_updated: number,+ is_loaded: boolean,+): Banner => {+ let label = "";+ if (is_loaded) {+ if (operation === "read") {+ label = $t(+ {+ defaultMessage:+ "Done! {N, plural, one {# message} other {# messages}} marked as read.",+ },+ {N: messages_updated},+ );+ } else {+ label = $t(+ {+ defaultMessage:+ "Done! {N, plural, one {# message} other {# messages}} marked as unread.",+ },+ {N: messages_updated},+ );+ }+ } else {+ if (operation === "read") {+ label = $t(+ {+ defaultMessage:+ "Working… {N, plural, one {# message} other {# messages}} marked as read so far.",+ },+ {N: messages_updated},+ );+ } else {+ label = $t(+ {+ defaultMessage:+ "Working… {N, plural, one {# message} other {# messages}} marked as unread so far.",+ },+ {N: messages_updated},+ );+ }+ }++ return {+ intent: "info",+ label,+ buttons: [],+ close_button: false,+ custom_classes: "update-read-flags-for-narrow-banner popup-banner",+ };+};++export function open_update_read_flags_for_narrow_banner(+ operation: "read" | "unread",+ messages_updated: number,+ is_loaded = false,+): void {+ const $banner = $("#popup_banners_wrapper").find(".update-read-flags-for-narrow-banner");+ if ($banner.length > 0) {+ // If the banner is already open, update the label instead of duplicating the banner.+ const banner = update_read_flags_for_narrow_banner(operation, messages_updated, is_loaded);+ $banner.find(".banner-label").text(banner.label.toString());++ if (is_loaded) {+ // When all messages have been processed, change the banner+ // intent to success to match the success message and close it+ // after a short delay.+ $banner.removeClass("banner-info").addClass("banner-success");+ setTimeout(() => {+ fade_out_popup_banner($banner);+ }, 2500);+ }++ return;+ }++ banners.append(+ update_read_flags_for_narrow_banner(operation, messages_updated, is_loaded),+ $("#popup_banners_wrapper"),+ );+}++export function close_update_read_flags_for_narrow_banner(): boolean {+ const $banner = $("#popup_banners_wrapper").find(".update-read-flags-for-narrow-banner");+ if ($banner.length === 0) {+ return false;+ }++ fade_out_popup_banner($banner);+ return true;+}+export function open_found_missing_unreads_banner(on_jump_to_first_unread: () => void): void {banners.append(FOUND_MISSING_UNREADS_IN_CURRENT_NARROW, $("#popup_banners_wrapper"));diff --git a/web/src/ui_report.ts b/web/src/ui_report.tsindex 43d67c82e67..0e93f2117b1 100644--- a/web/src/ui_report.ts+++ b/web/src/ui_report.ts@@ -92,21 +92,3 @@ export function hide_error($target: JQuery): void {export function show_error($target: JQuery): void {$target.addClass("show");}--export function loading(- response_html: string,- $status_box: JQuery,- successfully_loaded = false,-): void {- $status_box.find(".alert-content").html(response_html);- if (!successfully_loaded) {- $status_box.removeClass(common.status_classes).addClass("alert-loading").stop(true);- } else {- $status_box.removeClass(common.status_classes).addClass("alert-success").stop(true);- setTimeout(() => {- $status_box.removeClass("show");- }, 2500);- }-- $status_box.addClass("show");-}diff --git a/web/src/unread_ops.ts b/web/src/unread_ops.tsindex a6ee88e82c8..8e2c279cd7a 100644--- a/web/src/unread_ops.ts+++ b/web/src/unread_ops.ts@@ -15,7 +15,6 @@ import * as dialog_widget from "./dialog_widget.ts";import * as feedback_widget from "./feedback_widget.ts";import {Filter} from "./filter.ts";import {$t, $t_html} from "./i18n.ts";-import * as loading from "./loading.ts";import * as message_flags from "./message_flags.ts";import * as message_lists from "./message_lists.ts";import type {Message} from "./message_store.ts";@@ -24,16 +23,16 @@ import * as message_viewport from "./message_viewport.ts";import * as modals from "./modals.ts";import * as overlays from "./overlays.ts";import * as people from "./people.ts";+import * as popup_banners from "./popup_banners.ts";import * as recent_view_ui from "./recent_view_ui.ts";import type {MessageDetails} from "./server_event_types.ts";import type {NarrowTerm} from "./state_data.ts";import * as sub_store from "./sub_store.ts";-import * as ui_report from "./ui_report.ts";import * as unread from "./unread.ts";import * as unread_ui from "./unread_ui.ts";import * as watchdog from "./watchdog.ts";-let loading_indicator_displayed = false;+let update_read_flag_banner_displayed = false;let unsubscribed_ignored_channels: number[] = [];// We might want to use a slightly smaller batch for the first@@ -155,6 +154,32 @@ export function get_message_count_text(count: number): string {);}+function show_read_flag_update_progress_banner(+ operation: "read" | "unread",+ messages_updated: number,+): void {+ // We show the read flag update progress banner only+ // when the operation requires multiple batches. Otherwise,+ // we don't bother distracting the user with the banner+ // since the success is obvious through the updating UI.+ popup_banners.open_update_read_flags_for_narrow_banner(operation, messages_updated);+ update_read_flag_banner_displayed = true;+}++function show_read_flag_update_success_banner(+ operation: "read" | "unread",+ messages_updated: number,+): void {+ if (!update_read_flag_banner_displayed) {+ // If the operation completed in a single batch,+ // and we never showed the progress banner,+ // we skip showing the success banner as well.+ return;+ }+ popup_banners.open_update_read_flags_for_narrow_banner(operation, messages_updated, true);+ update_read_flag_banner_displayed = false;+}+function bulk_update_read_flags_for_narrow(narrow: NarrowTerm[],op: "add" | "remove",@@ -173,7 +198,6 @@ function bulk_update_read_flags_for_narrow(} = {},caller_modal_id?: string,): void {- let response_html;const terms_with_integer_channel_id = narrow.map((term) => {if (term.operator === "channel") {return {@@ -202,36 +226,11 @@ function bulk_update_read_flags_for_narrow(success(raw_data) {const data = update_flags_for_narrow_response_schema.parse(raw_data);messages_read_till_now += data.updated_count;+ const operation = op === "add" ? "read" : "unread";if (!data.found_newest) {assert(data.last_processed_id !== null);- // If we weren't able to make everything as read in a- // single API request, then show a loading indicator.- if (op === "add") {- response_html = $t_html(- {- defaultMessage:- "{N, plural, one {Working… {N} message marked as read so far.} other {Working… {N} messages marked as read so far.}}",- },- {N: messages_read_till_now},- );- } else {- response_html = $t_html(- {- defaultMessage:- "{N, plural, one {Working… {N} message marked as unread so far.} other {Working… {N} messages marked as unread so far.}}",- },- {N: messages_read_till_now},- );- }- ui_report.loading(response_html, $("#request-progress-status-banner"));- if (!loading_indicator_displayed) {- loading.make_indicator(- $("#request-progress-status-banner .loading-indicator"),- {abs_positioned: true},- );- loading_indicator_displayed = true;- }+ show_read_flag_update_progress_banner(operation, messages_read_till_now);bulk_update_read_flags_for_narrow(narrow,@@ -244,28 +243,7 @@ function bulk_update_read_flags_for_narrow(caller_modal_id,);} else {- if (loading_indicator_displayed) {- // Only show the success message if a progress banner was displayed.- if (op === "add") {- response_html = $t_html(- {- defaultMessage:- "{N, plural, one {Done! {N} message marked as read.} other {Done! {N} messages marked as read.}}",- },- {N: messages_read_till_now},- );- } else {- response_html = $t_html(- {- defaultMessage:- "{N, plural, one {Done! {N} message marked as unread.} other {Done! {N} messages marked as unread.}}",- },- {N: messages_read_till_now},- );- }- ui_report.loading(response_html, $("#request-progress-status-banner"), true);- loading_indicator_displayed = false;- }+ show_read_flag_update_success_banner(operation, messages_read_till_now);if (_.isEqual(narrow, all_unread_messages_narrow) && unread.old_unreads_missing) {// In the rare case that the user had more than@@ -532,25 +510,8 @@ function do_mark_unread_by_narrow(];if (!data.found_newest) {assert(data.last_processed_id !== null);- // If we weren't able to complete the request fully in- // the current batch, show a progress indicator.- ui_report.loading(- $t_html(- {- defaultMessage:- "{N, plural, one {Working… {N} message marked as unread so far.} other {Working… {N} messages marked as unread so far.}}",- },- {N: messages_marked_unread_till_now},- ),- $("#request-progress-status-banner"),- );- if (!loading_indicator_displayed) {- loading.make_indicator(- $("#request-progress-status-banner .loading-indicator"),- {abs_positioned: true},- );- loading_indicator_displayed = true;- }+ show_read_flag_update_progress_banner("unread", messages_marked_unread_till_now);+do_mark_unread_by_narrow(data.last_processed_id,false,@@ -559,9 +520,7 @@ function do_mark_unread_by_narrow(narrow,);} else {- if (loading_indicator_displayed) {- finish_loading(messages_marked_unread_till_now);- }+ show_read_flag_update_success_banner("unread", messages_marked_unread_till_now);if (unsubscribed_ignored_channels.length > 0) {handle_skipped_unsubscribed_streams(unsubscribed_ignored_channels);unsubscribed_ignored_channels = [];@@ -590,9 +549,8 @@ function do_mark_unread_by_ids(message_ids_to_update: number[]): void {url: "/json/messages/flags",data: {messages: JSON.stringify(message_ids_to_update), op: "remove", flag: "read"},success(raw_data) {- if (loading_indicator_displayed) {- finish_loading(message_ids_to_update.length);- }+ show_read_flag_update_success_banner("unread", message_ids_to_update.length);+const data = update_flags_for_response_schema.parse(raw_data);const ignored_because_not_subscribed_channels =data.ignored_because_not_subscribed_channels;@@ -610,26 +568,6 @@ function do_mark_unread_by_ids(message_ids_to_update: number[]): void {});}-function finish_loading(messages_marked_unread_till_now: number): void {- // If we were showing a loading indicator, then- // display that we finished. For the common case where- // the operation succeeds in a single batch, we don't- // bother distracting the user with the indication;- // the success will be obvious from the UI updating.- loading_indicator_displayed = false;- ui_report.loading(- $t_html(- {- defaultMessage:- "{N, plural, one {Done! {N} message marked as unread.} other {Done! {N} messages marked as unread.}}",- },- {N: messages_marked_unread_till_now},- ),- $("#request-progress-status-banner"),- true,- );-}-function handle_mark_unread_from_here_error(xhr: JQuery.jqXHR<unknown>,{retry}: {retry: () => void},diff --git a/web/styles/alerts.css b/web/styles/alerts.cssindex 6a8aedf5108..54852aa94ea 100644--- a/web/styles/alerts.css+++ b/web/styles/alerts.css@@ -164,87 +164,3 @@);}}--#request-progress-status-banner {- display: none;- align-items: center;- padding: 5px 10px;- margin-top: 10px;- grid-template-columns: 80px auto 50px;-- &.show {- display: grid !important;- }-- &.alert-loading {- .alert-zulip-logo,- .loading-indicator {- display: block;- }-- /* Hide exit button since clicking it will be useless in- this scenario. */- .exit {- display: none;- }- }-- &.alert-success .success-indicator {- display: block;- }-- &.alert-loading,- &.alert-success {- border-color: hsl(156deg 28% 70%);- box-shadow: 0 0 2px hsl(156deg 28% 70%);-- .exit {- color: hsl(156deg 30% 50%);- }- }-- &::before {- content: "";- margin-left: 0;- }-- .alert-zulip-logo {- display: none;- margin: auto;- grid-column: 1 / 2;- grid-row-start: 1;- }-- .loading-indicator {- display: none;- margin: auto;- grid-column: 1 / 2;- grid-row-start: 1;- }-- .success-indicator {- display: none;- margin: auto;- grid-column: 1 / 2;- grid-row-start: 1;- padding: 7px;- font-size: 1.5em;- line-height: 0;- color: hsl(156deg 30% 50%);- }-- .alert-content {- grid-column: 2 / 3;- grid-row-start: 1;- color: var(--color-request-progress-status-alert-text);- }-- .exit {- float: unset;- margin: 0;- margin-left: auto;- grid-column: 3 / 4;- grid-row-start: 1;- line-height: 0;- }-}diff --git a/web/styles/dark_theme.css b/web/styles/dark_theme.cssindex 8188e39b192..f6b430b2595 100644--- a/web/styles/dark_theme.css+++ b/web/styles/dark_theme.css@@ -155,10 +155,6 @@color: inherit;}- #request-progress-status-banner {- background-color: hsl(212deg 32% 14%);- }-.alert.home-error-bar {color: hsl(236deg 33% 90%);background-color: hsl(35deg 84% 62% / 25%);@@ -259,7 +255,6 @@color: hsl(200deg 79% 66%);}- #request-progress-status-banner .loading-indicator,#loading_older_messages_indicator,#recent_view_loading_messages_indicator {& path {diff --git a/web/styles/zulip.css b/web/styles/zulip.cssindex b04bbc4f457..675b09f1a61 100644--- a/web/styles/zulip.css+++ b/web/styles/zulip.css@@ -241,7 +241,6 @@ p.n-margin {display: none;}-.alert-zulip-logo,.top-messages-logo,.bottom-messages-logo {width: 1.7143em; /* 24px at 14px/em */