DEV: Display Sidebar template for anonymous user (#17962)

Setup the stage for the sidebar which will be shown to anonymous users.
This commit is contained in:
Alan Guo Xiang Tan 2022-08-17 16:17:36 +08:00 committed by GitHub
parent 42c64abe15
commit 0f0ea75a21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 53 additions and 21 deletions

View File

@ -5,6 +5,7 @@ import { inject as service } from "@ember/service";
export default class Sidebar extends Component {
@service appEvents;
@service site;
@service currentUser;
constructor() {
super(...arguments);

View File

@ -0,0 +1,3 @@
<div class="sidebar-sections sidebar-sections-anonymous">
{{!-- add sections for anonymous user --}}
</div>

View File

@ -0,0 +1,3 @@
import Component from "@glimmer/component";
export default class SidebarAnonymousSectuons extends Component {}

View File

@ -0,0 +1,12 @@
import Component from "@glimmer/component";
import { getOwner } from "discourse-common/lib/get-owner";
import { inject as service } from "@ember/service";
export default class SidebarFooter extends Component {
@service site;
@service siteSettings;
get capabilities() {
return getOwner(this).lookup("capabilities:main");
}
}

View File

@ -17,11 +17,7 @@ export default Controller.extend({
init() {
this._super(...arguments);
this.showSidebar =
this.currentUser &&
!this.site.mobileView &&
!this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
this.showSidebar = !this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
},
@discourseComputed

View File

@ -1,6 +1,11 @@
<DSection @pageClass="has-sidebar" @class="sidebar-container" @scrollTop={{false}}>
<div class="sidebar-scroll-wrap">
{{#if this.currentUser}}
<Sidebar::Sections @collapsableSections={{true}}/>
<Sidebar::Footer @tagName=""/>
<Sidebar::Footer />
{{else}}
<Sidebar::AnonymousSections />
<Sidebar::Footer />
{{/if}}
</div>
</DSection>

View File

@ -0,0 +1,26 @@
import { test } from "qunit";
import { visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance("Sidebar - Anonymous User", function (needs) {
needs.settings({
enable_experimental_sidebar_hamburger: true,
enable_sidebar: true,
});
test("sidebar is displayed", async function (assert) {
await visit("/");
assert.ok(
document.body.classList.contains("has-sidebar-page"),
"adds sidebar utility class to body"
);
assert.ok(
exists(".sidebar-container"),
"sidebar exists for anonymouse user"
);
});
});

View File

@ -4,20 +4,6 @@ import { test } from "qunit";
import { click, visit } from "@ember/test-helpers";
import { acceptance, exists } from "discourse/tests/helpers/qunit-helpers";
acceptance("Sidebar - Anon User", function () {
// Don't show sidebar for anon user until we know what we want to display
test("sidebar is not displayed", async function (assert) {
await visit("/");
assert.ok(
!document.body.classList.contains("has-sidebar-page"),
"does not add sidebar utility class to body"
);
assert.ok(!exists(".sidebar-container"));
});
});
acceptance(
"Sidebar - Experimental sidebar and hamburger setting disabled",
function (needs) {