FIX: hide sidebar toggle button when no sidebar ()

When sidebar is not available (for example for anonymous user for sites which requires log in), toggle button should be hidden as well.
This commit is contained in:
Krzysztof Kotlarek 2022-08-24 14:09:40 +10:00 committed by GitHub
parent 6771673a1b
commit 7a58bd8827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 5 deletions
app/assets/javascripts/discourse
app/controllers
tests/acceptance

View File

@ -18,8 +18,7 @@ export default Controller.extend({
init() {
this._super(...arguments);
this.showSidebar =
(this.currentUser || !this.siteSettings.login_required) &&
!this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
this.canDisplaySidebar && !this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
},
@discourseComputed
@ -31,6 +30,11 @@ export default Controller.extend({
);
},
@discourseComputed
canDisplaySidebar() {
return this.currentUser || !this.siteSettings.login_required;
},
@discourseComputed
loginRequired() {
return this.siteSettings.login_required && !this.currentUser;
@ -60,9 +64,18 @@ export default Controller.extend({
@discourseComputed(
"enable_sidebar",
"siteSettings.enable_sidebar",
"router.currentRouteName"
"router.currentRouteName",
"canDisplaySidebar"
)
sidebarEnabled(sidebarQueryParamOverride, enableSidebar, currentRouteName) {
sidebarEnabled(
sidebarQueryParamOverride,
enableSidebar,
currentRouteName,
canDisplaySidebar
) {
if (!canDisplaySidebar) {
return false;
}
if (sidebarQueryParamOverride === "1") {
return true;
}

View File

@ -22,6 +22,11 @@ acceptance("Sidebar - Anonymous User", function (needs) {
exists(".sidebar-container"),
"sidebar exists for anonymous user"
);
assert.ok(
exists(".header-sidebar-toggle"),
"toggle button for anonymous user"
);
});
});
@ -32,12 +37,17 @@ acceptance("Sidebar - Anonymous User - Login Required", function (needs) {
login_required: true,
});
test("sidebar is hidden", async function (assert) {
test("sidebar and toggle button is hidden", async function (assert) {
await visit("/");
assert.ok(
!exists(".sidebar-container"),
"sidebar is hidden for anonymous user"
);
assert.ok(
!exists(".header-sidebar-toggle"),
"toggle button is hidden for anonymous user"
);
});
});