From 6065d66d3de5f05c3c2ebf305314f45d40ee6e1c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 15 Nov 2021 18:05:40 -0800 Subject: [PATCH] bookend: Simplify can_toggle_subscription variable flow. --- frontend_tests/node_tests/message_list.js | 9 +-------- static/js/message_list.js | 8 +++----- static/js/message_list_view.js | 4 ++-- static/templates/bookend.hbs | 4 ++-- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/frontend_tests/node_tests/message_list.js b/frontend_tests/node_tests/message_list.js index 865827084b..451f6670d3 100644 --- a/frontend_tests/node_tests/message_list.js +++ b/frontend_tests/node_tests/message_list.js @@ -312,6 +312,7 @@ run_test("bookend", ({override}) => { override(stream_data, "is_subscribed_by_name", () => is_subscribed); override(stream_data, "get_sub", () => ({invite_only})); + override(stream_data, "can_toggle_subscription", () => true); { const stub = make_stub(); @@ -323,13 +324,11 @@ run_test("bookend", ({override}) => { "subscribed", "deactivated", "just_unsubscribed", - "show_button", ); assert.equal(bookend.stream_name, "IceCream"); assert.equal(bookend.subscribed, true); assert.equal(bookend.deactivated, false); assert.equal(bookend.just_unsubscribed, false); - assert.equal(bookend.show_button, true); } list.last_message_historical = false; @@ -345,13 +344,11 @@ run_test("bookend", ({override}) => { "subscribed", "deactivated", "just_unsubscribed", - "show_button", ); assert.equal(bookend.stream_name, "IceCream"); assert.equal(bookend.subscribed, false); assert.equal(bookend.deactivated, false); assert.equal(bookend.just_unsubscribed, true); - assert.equal(bookend.show_button, true); } // Test when the stream is privates (invite only) @@ -367,13 +364,11 @@ run_test("bookend", ({override}) => { "subscribed", "deactivated", "just_unsubscribed", - "show_button", ); assert.equal(bookend.stream_name, "IceCream"); assert.equal(bookend.subscribed, false); assert.equal(bookend.deactivated, false); assert.equal(bookend.just_unsubscribed, true); - assert.equal(bookend.show_button, false); } list.last_message_historical = true; @@ -388,13 +383,11 @@ run_test("bookend", ({override}) => { "subscribed", "deactivated", "just_unsubscribed", - "show_button", ); assert.equal(bookend.stream_name, "IceCream"); assert.equal(bookend.subscribed, false); assert.equal(bookend.deactivated, false); assert.equal(bookend.just_unsubscribed, false); - assert.equal(bookend.show_button, true); } }); diff --git a/static/js/message_list.js b/static/js/message_list.js index 95c397ed2a..3ba3a65c40 100644 --- a/static/js/message_list.js +++ b/static/js/message_list.js @@ -244,23 +244,21 @@ export class MessageList { let deactivated = false; let just_unsubscribed = false; - let show_button = true; const subscribed = stream_data.is_subscribed_by_name(stream_name); const sub = stream_data.get_sub(stream_name); + const can_toggle_subscription = + sub !== undefined && stream_data.can_toggle_subscription(sub); if (sub === undefined) { deactivated = true; - // Hide the resubscribe button for streams that no longer exist. - show_button = false; } else if (!subscribed && !this.last_message_historical) { just_unsubscribed = true; - show_button = stream_data.can_toggle_subscription(sub); } this.view.render_trailing_bookend( stream_name, subscribed, deactivated, just_unsubscribed, - show_button, + can_toggle_subscription, page_params.is_spectator, ); } diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js index 070692c580..119ed1e7a2 100644 --- a/static/js/message_list_view.js +++ b/static/js/message_list_view.js @@ -1300,13 +1300,13 @@ export class MessageListView { subscribed, deactivated, just_unsubscribed, - show_button, + can_toggle_subscription, is_spectator, ) { const rendered_trailing_bookend = $( render_bookend({ stream_name, - trailing: show_button, + can_toggle_subscription, subscribed, deactivated, just_unsubscribed, diff --git a/static/templates/bookend.hbs b/static/templates/bookend.hbs index 9aa2b23e8b..b8c9fdfd60 100644 --- a/static/templates/bookend.hbs +++ b/static/templates/bookend.hbs @@ -1,5 +1,5 @@ {{! Client-side Mustache template for rendering the trailing bookend.}} -
+
{{#if is_spectator}} {{t "Browse recent topics" }} @@ -17,7 +17,7 @@ {{/if}} {{/if}} - {{#if trailing}} + {{#if can_toggle_subscription}}