From 0f0ea75a2103b59a96a6edd3d4c39dca07fedc83 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Wed, 17 Aug 2022 16:17:36 +0800 Subject: [PATCH] DEV: Display Sidebar template for anonymous user (#17962) Setup the stage for the sidebar which will be shown to anonymous users. --- .../discourse/app/components/sidebar.js | 1 + .../components/sidebar/anonymous-sections.hbs | 3 +++ .../components/sidebar/anonymous-sections.js | 3 +++ .../app/components/sidebar/footer.js | 12 +++++++++ .../discourse/app/controllers/application.js | 6 +---- .../app/templates/components/sidebar.hbs | 9 +++++-- .../acceptance/sidebar-anonymous-user-test.js | 26 +++++++++++++++++++ .../tests/acceptance/sidebar-test.js | 14 ---------- 8 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js create mode 100644 app/assets/javascripts/discourse/app/components/sidebar/footer.js create mode 100644 app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js diff --git a/app/assets/javascripts/discourse/app/components/sidebar.js b/app/assets/javascripts/discourse/app/components/sidebar.js index c9fdd81ac42..f4316c392a6 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar.js +++ b/app/assets/javascripts/discourse/app/components/sidebar.js @@ -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); diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs new file mode 100644 index 00000000000..17f3217c72e --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.hbs @@ -0,0 +1,3 @@ + diff --git a/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js new file mode 100644 index 00000000000..e7adf2382ca --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/anonymous-sections.js @@ -0,0 +1,3 @@ +import Component from "@glimmer/component"; + +export default class SidebarAnonymousSectuons extends Component {} diff --git a/app/assets/javascripts/discourse/app/components/sidebar/footer.js b/app/assets/javascripts/discourse/app/components/sidebar/footer.js new file mode 100644 index 00000000000..68b8c7afe7e --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/sidebar/footer.js @@ -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"); + } +} diff --git a/app/assets/javascripts/discourse/app/controllers/application.js b/app/assets/javascripts/discourse/app/controllers/application.js index b6d0f25c8bd..80c07b17b29 100644 --- a/app/assets/javascripts/discourse/app/controllers/application.js +++ b/app/assets/javascripts/discourse/app/controllers/application.js @@ -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 diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs index 31cda7a3058..03f183e0b54 100644 --- a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs @@ -1,6 +1,11 @@ diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js new file mode 100644 index 00000000000..0bdab3fc292 --- /dev/null +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-anonymous-user-test.js @@ -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" + ); + }); +}); diff --git a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js index f75d4b22486..38edead380c 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/sidebar-test.js @@ -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) {