mirror of https://github.com/zulip/zulip.git
bookend: Simplify can_toggle_subscription variable flow.
This commit is contained in:
parent
2b59148e21
commit
6065d66d3d
|
@ -312,6 +312,7 @@ run_test("bookend", ({override}) => {
|
||||||
|
|
||||||
override(stream_data, "is_subscribed_by_name", () => is_subscribed);
|
override(stream_data, "is_subscribed_by_name", () => is_subscribed);
|
||||||
override(stream_data, "get_sub", () => ({invite_only}));
|
override(stream_data, "get_sub", () => ({invite_only}));
|
||||||
|
override(stream_data, "can_toggle_subscription", () => true);
|
||||||
|
|
||||||
{
|
{
|
||||||
const stub = make_stub();
|
const stub = make_stub();
|
||||||
|
@ -323,13 +324,11 @@ run_test("bookend", ({override}) => {
|
||||||
"subscribed",
|
"subscribed",
|
||||||
"deactivated",
|
"deactivated",
|
||||||
"just_unsubscribed",
|
"just_unsubscribed",
|
||||||
"show_button",
|
|
||||||
);
|
);
|
||||||
assert.equal(bookend.stream_name, "IceCream");
|
assert.equal(bookend.stream_name, "IceCream");
|
||||||
assert.equal(bookend.subscribed, true);
|
assert.equal(bookend.subscribed, true);
|
||||||
assert.equal(bookend.deactivated, false);
|
assert.equal(bookend.deactivated, false);
|
||||||
assert.equal(bookend.just_unsubscribed, false);
|
assert.equal(bookend.just_unsubscribed, false);
|
||||||
assert.equal(bookend.show_button, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.last_message_historical = false;
|
list.last_message_historical = false;
|
||||||
|
@ -345,13 +344,11 @@ run_test("bookend", ({override}) => {
|
||||||
"subscribed",
|
"subscribed",
|
||||||
"deactivated",
|
"deactivated",
|
||||||
"just_unsubscribed",
|
"just_unsubscribed",
|
||||||
"show_button",
|
|
||||||
);
|
);
|
||||||
assert.equal(bookend.stream_name, "IceCream");
|
assert.equal(bookend.stream_name, "IceCream");
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.deactivated, false);
|
assert.equal(bookend.deactivated, false);
|
||||||
assert.equal(bookend.just_unsubscribed, true);
|
assert.equal(bookend.just_unsubscribed, true);
|
||||||
assert.equal(bookend.show_button, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test when the stream is privates (invite only)
|
// Test when the stream is privates (invite only)
|
||||||
|
@ -367,13 +364,11 @@ run_test("bookend", ({override}) => {
|
||||||
"subscribed",
|
"subscribed",
|
||||||
"deactivated",
|
"deactivated",
|
||||||
"just_unsubscribed",
|
"just_unsubscribed",
|
||||||
"show_button",
|
|
||||||
);
|
);
|
||||||
assert.equal(bookend.stream_name, "IceCream");
|
assert.equal(bookend.stream_name, "IceCream");
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.deactivated, false);
|
assert.equal(bookend.deactivated, false);
|
||||||
assert.equal(bookend.just_unsubscribed, true);
|
assert.equal(bookend.just_unsubscribed, true);
|
||||||
assert.equal(bookend.show_button, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
list.last_message_historical = true;
|
list.last_message_historical = true;
|
||||||
|
@ -388,13 +383,11 @@ run_test("bookend", ({override}) => {
|
||||||
"subscribed",
|
"subscribed",
|
||||||
"deactivated",
|
"deactivated",
|
||||||
"just_unsubscribed",
|
"just_unsubscribed",
|
||||||
"show_button",
|
|
||||||
);
|
);
|
||||||
assert.equal(bookend.stream_name, "IceCream");
|
assert.equal(bookend.stream_name, "IceCream");
|
||||||
assert.equal(bookend.subscribed, false);
|
assert.equal(bookend.subscribed, false);
|
||||||
assert.equal(bookend.deactivated, false);
|
assert.equal(bookend.deactivated, false);
|
||||||
assert.equal(bookend.just_unsubscribed, false);
|
assert.equal(bookend.just_unsubscribed, false);
|
||||||
assert.equal(bookend.show_button, true);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -244,23 +244,21 @@ export class MessageList {
|
||||||
|
|
||||||
let deactivated = false;
|
let deactivated = false;
|
||||||
let just_unsubscribed = false;
|
let just_unsubscribed = false;
|
||||||
let show_button = true;
|
|
||||||
const subscribed = stream_data.is_subscribed_by_name(stream_name);
|
const subscribed = stream_data.is_subscribed_by_name(stream_name);
|
||||||
const sub = stream_data.get_sub(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) {
|
if (sub === undefined) {
|
||||||
deactivated = true;
|
deactivated = true;
|
||||||
// Hide the resubscribe button for streams that no longer exist.
|
|
||||||
show_button = false;
|
|
||||||
} else if (!subscribed && !this.last_message_historical) {
|
} else if (!subscribed && !this.last_message_historical) {
|
||||||
just_unsubscribed = true;
|
just_unsubscribed = true;
|
||||||
show_button = stream_data.can_toggle_subscription(sub);
|
|
||||||
}
|
}
|
||||||
this.view.render_trailing_bookend(
|
this.view.render_trailing_bookend(
|
||||||
stream_name,
|
stream_name,
|
||||||
subscribed,
|
subscribed,
|
||||||
deactivated,
|
deactivated,
|
||||||
just_unsubscribed,
|
just_unsubscribed,
|
||||||
show_button,
|
can_toggle_subscription,
|
||||||
page_params.is_spectator,
|
page_params.is_spectator,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1300,13 +1300,13 @@ export class MessageListView {
|
||||||
subscribed,
|
subscribed,
|
||||||
deactivated,
|
deactivated,
|
||||||
just_unsubscribed,
|
just_unsubscribed,
|
||||||
show_button,
|
can_toggle_subscription,
|
||||||
is_spectator,
|
is_spectator,
|
||||||
) {
|
) {
|
||||||
const rendered_trailing_bookend = $(
|
const rendered_trailing_bookend = $(
|
||||||
render_bookend({
|
render_bookend({
|
||||||
stream_name,
|
stream_name,
|
||||||
trailing: show_button,
|
can_toggle_subscription,
|
||||||
subscribed,
|
subscribed,
|
||||||
deactivated,
|
deactivated,
|
||||||
just_unsubscribed,
|
just_unsubscribed,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{{! Client-side Mustache template for rendering the trailing bookend.}}
|
{{! Client-side Mustache template for rendering the trailing bookend.}}
|
||||||
<div class="{{#if trailing}}trailing_bookend{{/if}} bookend sub-unsub-message">
|
<div class="{{#if can_toggle_subscription}}trailing_bookend{{/if}} bookend sub-unsub-message">
|
||||||
{{#if is_spectator}}
|
{{#if is_spectator}}
|
||||||
<span class="recent-topics-link">
|
<span class="recent-topics-link">
|
||||||
<a href="#recent_topics">{{t "Browse recent topics" }}</a>
|
<a href="#recent_topics">{{t "Browse recent topics" }}</a>
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{#if trailing}}
|
{{#if can_toggle_subscription}}
|
||||||
<div class="sub_button_row new-style">
|
<div class="sub_button_row new-style">
|
||||||
<button class="button white rounded stream_sub_unsub_button {{#unless subscribed}}sea-green{{/unless}}" type="button" name="subscription">
|
<button class="button white rounded stream_sub_unsub_button {{#unless subscribed}}sea-green{{/unless}}" type="button" name="subscription">
|
||||||
{{#if subscribed}}
|
{{#if subscribed}}
|
||||||
|
|
Loading…
Reference in New Issue