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.

stream-edit: Show loading spinner on subscription toggle button.

Sahil Batraf2ef37770ecf
diff --git a/web/src/stream_edit.ts b/web/src/stream_edit.ts
index 9aa2d123ece..bb465c69685 100644
--- a/web/src/stream_edit.ts
+++ b/web/src/stream_edit.ts
@@ -852,13 +852,12 @@ export function initialize(): void {
// button in the right side subheader, we do not pass
// $stream_row as we do not want the spinner to appear
// replacing the checkmark.
- stream_settings_components.sub_or_unsub(sub);
+ stream_settings_components.sub_or_unsub(sub, undefined, $(this));
} else {
stream_settings_components.sub_or_unsub(sub, $stream_row);
- }
-
- if (!sub.subscribed) {
- open_edit_panel_for_row(util.the($stream_row));
+ if (!sub.subscribed) {
+ open_edit_panel_for_row(util.the($stream_row));
+ }
}
stream_ui_updates.update_channel_email_section(sub);
diff --git a/web/src/stream_settings_components.ts b/web/src/stream_settings_components.ts
index 633467bd59f..3dbce2872b7 100644
--- a/web/src/stream_settings_components.ts
+++ b/web/src/stream_settings_components.ts
@@ -7,6 +7,7 @@ import render_new_channel_members_title from "../templates/stream_settings/new_c
import render_selected_stream_title from "../templates/stream_settings/selected_stream_title.hbs";
import * as blueslip from "./blueslip.ts";
+import * as buttons from "./buttons.ts";
import * as channel from "./channel.ts";
import * as channel_folders from "./channel_folders.ts";
import * as channel_folders_ui from "./channel_folders_ui.ts";
@@ -195,6 +196,7 @@ export function ajaxSubscribe(
stream: string,
color: string,
$stream_row: JQuery | undefined,
+ $button_elem: JQuery | undefined,
): void {
// Subscribe yourself to a single stream.
let true_stream_name;
@@ -202,6 +204,9 @@ export function ajaxSubscribe(
if ($stream_row !== undefined) {
display_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.show_button_loading_indicator($button_elem);
+ }
void channel.post({
url: "/json/users/me/subscriptions",
data: {subscriptions: JSON.stringify([{name: stream, color}])},
@@ -231,11 +236,17 @@ export function ajaxSubscribe(
if ($stream_row !== undefined) {
hide_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.hide_button_loading_indicator($button_elem);
+ }
},
error(xhr) {
if ($stream_row !== undefined) {
hide_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.hide_button_loading_indicator($button_elem);
+ }
ui_report.error(
$t_html({defaultMessage: "Error adding subscription"}),
xhr,
@@ -245,11 +256,18 @@ export function ajaxSubscribe(
});
}
-function ajaxUnsubscribe(sub: StreamSubscription, $stream_row: JQuery | undefined): void {
+function ajaxUnsubscribe(
+ sub: StreamSubscription,
+ $stream_row: JQuery | undefined,
+ $button_elem: JQuery | undefined,
+): void {
// TODO: use stream_id when backend supports it
if ($stream_row !== undefined) {
display_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.show_button_loading_indicator($button_elem);
+ }
void channel.del({
url: "/json/users/me/subscriptions",
data: {subscriptions: JSON.stringify([sub.name])},
@@ -260,11 +278,17 @@ function ajaxUnsubscribe(sub: StreamSubscription, $stream_row: JQuery | undefine
if ($stream_row !== undefined) {
hide_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.hide_button_loading_indicator($button_elem);
+ }
},
error(xhr) {
if ($stream_row !== undefined) {
hide_subscribe_toggle_spinner($stream_row);
}
+ if ($button_elem !== undefined) {
+ buttons.hide_button_loading_indicator($button_elem);
+ }
ui_report.error(
$t_html({defaultMessage: "Error removing subscription"}),
xhr,
@@ -277,6 +301,7 @@ function ajaxUnsubscribe(sub: StreamSubscription, $stream_row: JQuery | undefine
export function unsubscribe_from_private_stream(
sub: StreamSubscription,
$stream_row: JQuery | undefined,
+ $button_elem: JQuery | undefined,
): void {
const invite_only = sub.invite_only;
const sub_count = peer_data.get_subscriber_count(sub.stream_id);
@@ -295,7 +320,7 @@ export function unsubscribe_from_private_stream(
});
function unsubscribe_from_stream(): void {
- ajaxUnsubscribe(sub, $stream_row);
+ ajaxUnsubscribe(sub, $stream_row, $button_elem);
}
confirm_dialog.launch({
@@ -308,19 +333,23 @@ export function unsubscribe_from_private_stream(
});
}
-export function sub_or_unsub(sub: StreamSubscription, $stream_row?: JQuery): void {
+export function sub_or_unsub(
+ sub: StreamSubscription,
+ $stream_row?: JQuery,
+ $button_elem?: JQuery,
+): void {
if (sub.subscribed) {
// TODO: This next line should allow guests to access web-public streams.
if (
(sub.invite_only && !stream_data.has_content_access_via_group_permissions(sub)) ||
current_user.is_guest
) {
- unsubscribe_from_private_stream(sub, $stream_row);
+ unsubscribe_from_private_stream(sub, $stream_row, $button_elem);
return;
}
- ajaxUnsubscribe(sub, $stream_row);
+ ajaxUnsubscribe(sub, $stream_row, $button_elem);
} else {
- ajaxSubscribe(sub.name, sub.color, $stream_row);
+ ajaxSubscribe(sub.name, sub.color, $stream_row, $button_elem);
}
}
diff --git a/web/src/stream_ui_updates.ts b/web/src/stream_ui_updates.ts
index ddc2870608b..7fea1bf9504 100644
--- a/web/src/stream_ui_updates.ts
+++ b/web/src/stream_ui_updates.ts
@@ -229,13 +229,13 @@ export function update_settings_button_for_sub(sub: StreamSubscription): void {
}
if (sub.subscribed) {
+ $settings_button.find(".action-button-label").text($t({defaultMessage: "Unsubscribe"}));
$settings_button
- .text($t({defaultMessage: "Unsubscribe"}))
.removeClass("unsubscribed action-button-subtle-brand")
.addClass("action-button-subtle-neutral");
} else {
+ $settings_button.find(".action-button-label").text($t({defaultMessage: "Subscribe"}));
$settings_button
- .text($t({defaultMessage: "Subscribe"}))
.addClass("unsubscribed action-button-subtle-brand")
.removeClass("action-button-subtle-neutral");
}
diff --git a/web/templates/stream_settings/selected_stream_title.hbs b/web/templates/stream_settings/selected_stream_title.hbs
index 3655b482a7d..15a70c8f216 100644
--- a/web/templates/stream_settings/selected_stream_title.hbs
+++ b/web/templates/stream_settings/selected_stream_title.hbs
@@ -29,11 +29,13 @@
</span>
</template>
<button class="action-button subscribe-button sub_unsub_button {{#if subscribed}}action-button-subtle-neutral{{else}}action-button-subtle-brand{{/if}} {{#if should_display_subscription_button}}toggle-subscription-tooltip{{/if}} {{#unless subscribed }}unsubscribed{{/unless}}" type="button" name="button" data-tooltip-template-id="toggle-subscription-tooltip-template" {{#unless should_display_subscription_button}}disabled="disabled"{{/unless}}>
- {{#if subscribed }}
- {{t "Unsubscribe" }}
- {{else}}
- {{t "Subscribe" }}
- {{/if}}
+ <span class="action-button-label">
+ {{#if subscribed }}
+ {{t "Unsubscribe" }}
+ {{else}}
+ {{t "Subscribe" }}
+ {{/if}}
+ </span>
</button>
</div>
{{> ../components/action_button