From 99073338de6b5aaef714f61a90434e78c289b608 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Fri, 22 Jul 2022 13:06:47 +0800 Subject: [PATCH] FEATURE: Replace hamburger dropdown with Sidebar when undock (#17600) When the experimental Sidebar is enabled, the hamburger drop down is replaced by a sidebar drop down. A user is given the ability to dock and undock the sidebar depending on their personal preference. Do also note that the experimental sidebar is well, considered experimental at this point so I do not intend for the features here to be perfect. What I aim to do here is to ship the changes fast so that it can be used internally by the team to provide feedback. Custom links added by plugins and dark mode toggle has not been implemented as part of this commit as I aim to tackle it in another commit. Co-authored-by: awesomerobot --- .../discourse/app/components/d-button.js | 6 ++ .../app/components/sidebar/section.js | 13 ++- .../discourse/app/components/site-header.js | 24 +++++ .../discourse/app/controllers/application.js | 1 + .../discourse/app/initializers/mobile.js | 1 + .../discourse/app/routes/application.js | 4 + .../discourse/app/templates/application.hbs | 13 ++- .../app/templates/components/sidebar.hbs | 3 +- .../components/sidebar/categories-section.hbs | 3 +- .../templates/components/sidebar/footer.hbs | 30 ++++++ .../components/sidebar/hamburger-dropdown.hbs | 12 +++ .../components/sidebar/messages-section.hbs | 5 +- .../templates/components/sidebar/section.hbs | 18 ++-- .../templates/components/sidebar/sections.hbs | 11 +- .../components/sidebar/tags-section.hbs | 3 +- .../components/sidebar/topics-section.hbs | 3 +- .../discourse/app/widgets/header-contents.js | 3 - .../discourse/app/widgets/header.js | 99 +++++++++++------ .../discourse/app/widgets/sidebar-toggle.js | 16 --- .../discourse/app/widgets/widget.js | 2 + .../sidebar-categories-section-test.js | 14 +-- .../tests/acceptance/sidebar-mobile-test.js | 13 ++- .../acceptance/sidebar-plugin-api-test.js | 3 +- .../acceptance/sidebar-tags-section-test.js | 12 ++- .../tests/acceptance/sidebar-test.js | 61 +++++++++-- .../acceptance/sidebar-topics-section-test.js | 10 +- .../tests/helpers/sidebar-helpers.js | 5 + app/assets/stylesheets/color_definitions.scss | 1 + .../stylesheets/common/base/_index.scss | 1 + .../stylesheets/common/base/header.scss | 5 +- .../stylesheets/common/base/menu-panel.scss | 30 ++++++ .../common/base/sidebar-footer.scss | 101 ++++++++++++++++++ .../common/base/sidebar-section-link.scss | 1 + .../common/base/sidebar-section.scss | 8 +- .../stylesheets/common/base/sidebar.scss | 55 ++-------- app/assets/stylesheets/desktop/discourse.scss | 24 +++-- app/assets/stylesheets/mobile/discourse.scss | 27 +++-- app/assets/stylesheets/mobile/sidebar.scss | 6 ++ config/locales/client.en.yml | 1 + lib/svg_sprite.rb | 1 + 40 files changed, 477 insertions(+), 172 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/templates/components/sidebar/footer.hbs create mode 100644 app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs delete mode 100644 app/assets/javascripts/discourse/app/widgets/sidebar-toggle.js create mode 100644 app/assets/javascripts/discourse/tests/helpers/sidebar-helpers.js create mode 100644 app/assets/stylesheets/common/base/sidebar-footer.scss diff --git a/app/assets/javascripts/discourse/app/components/d-button.js b/app/assets/javascripts/discourse/app/components/d-button.js index f8177d44497..1726bb76d84 100644 --- a/app/assets/javascripts/discourse/app/components/d-button.js +++ b/app/assets/javascripts/discourse/app/components/d-button.js @@ -1,3 +1,4 @@ +import { inject as service } from "@ember/service"; import { empty, equal, notEmpty } from "@ember/object/computed"; import Component from "@ember/component"; import DiscourseURL from "discourse/lib/url"; @@ -22,6 +23,7 @@ export default Component.extend({ forwardEvent: false, preventFocus: false, onKeyDown: null, + router: service(), isLoading: computed({ set(key, value) { @@ -149,6 +151,10 @@ export default Component.extend({ } } + if (this.route) { + this.router.transitionTo(this.route); + } + if (this.href && this.href.length) { DiscourseURL.routeTo(this.href); } diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section.js b/app/assets/javascripts/discourse/app/components/sidebar/section.js index 79eda4f28aa..f01b8433a63 100644 --- a/app/assets/javascripts/discourse/app/components/sidebar/section.js +++ b/app/assets/javascripts/discourse/app/components/sidebar/section.js @@ -10,10 +10,15 @@ export default class SidebarSection extends GlimmerComponent { constructor() { super(...arguments); - this.displaySection = - this.keyValueStore.getItem(this.collapsedSidebarSectionKey) === undefined - ? true - : false; + if (this.args.collapsable) { + this.displaySection = + this.keyValueStore.getItem(this.collapsedSidebarSectionKey) === + undefined + ? true + : false; + } else { + this.displaySection = true; + } } willDestroy() { diff --git a/app/assets/javascripts/discourse/app/components/site-header.js b/app/assets/javascripts/discourse/app/components/site-header.js index 689108b01ae..9f3c0006309 100644 --- a/app/assets/javascripts/discourse/app/components/site-header.js +++ b/app/assets/javascripts/discourse/app/components/site-header.js @@ -231,10 +231,22 @@ const SiteHeaderComponent = MountWidget.extend( this.appEvents.on("header:show-topic", this, "setTopic"); this.appEvents.on("header:hide-topic", this, "setTopic"); + if (this.currentUser?.redesigned_user_menu_enabled) { this.appEvents.on("user-menu:rendered", this, "_animateMenu"); } + if ( + this.currentUser?.experimental_sidebar_enabled && + !this.site.mobileView + ) { + this.appEvents.on( + "sidebar:docked-state-updated", + this, + "queueRerender" + ); + } + this.dispatch("notifications:changed", "user-notifications"); this.dispatch("header:keyboard-trigger", "header"); this.dispatch("user-menu:navigation", "user-menu"); @@ -351,6 +363,17 @@ const SiteHeaderComponent = MountWidget.extend( this.appEvents.off("user-menu:rendered", this, "_animateMenu"); } + if ( + this.currentUser?.experimental_sidebar_enabled && + !this.site.mobileView + ) { + this.appEvents.off( + "sidebar:docked-state-updated", + this, + "queueRerender" + ); + } + if (this.currentUser) { this.currentUser.off("status-changed", this, "queueRerender"); } @@ -367,6 +390,7 @@ const SiteHeaderComponent = MountWidget.extend( return { topic: this._topic, canSignUp: this.canSignUp, + sidebarDocked: this.sidebarDocked, }; }, diff --git a/app/assets/javascripts/discourse/app/controllers/application.js b/app/assets/javascripts/discourse/app/controllers/application.js index 92b1e5abd7f..2e0bfcf8167 100644 --- a/app/assets/javascripts/discourse/app/controllers/application.js +++ b/app/assets/javascripts/discourse/app/controllers/application.js @@ -50,6 +50,7 @@ export default Controller.extend({ discourseDebounce(this, this._mainOutletAnimate, 250); this.toggleProperty("showSidebar"); + this.appEvents.trigger("sidebar:docked-state-updated"); if (!this.site.mobileView) { if (this.showSidebar) { diff --git a/app/assets/javascripts/discourse/app/initializers/mobile.js b/app/assets/javascripts/discourse/app/initializers/mobile.js index c0dbaa19548..7c992005cb1 100644 --- a/app/assets/javascripts/discourse/app/initializers/mobile.js +++ b/app/assets/javascripts/discourse/app/initializers/mobile.js @@ -12,6 +12,7 @@ export default { const site = container.lookup("site:main"); site.set("mobileView", Mobile.mobileView); + site.set("desktopView", !Mobile.mobileView); site.set("isMobileDevice", Mobile.isMobileDevice); setResolverOption("mobileView", Mobile.mobileView); diff --git a/app/assets/javascripts/discourse/app/routes/application.js b/app/assets/javascripts/discourse/app/routes/application.js index f26b798225a..558ab27bc11 100644 --- a/app/assets/javascripts/discourse/app/routes/application.js +++ b/app/assets/javascripts/discourse/app/routes/application.js @@ -51,6 +51,10 @@ const ApplicationRoute = DiscourseRoute.extend(OpenComposer, { mobile.toggleMobileView(); }, + toggleSidebar() { + this.controllerFor("application").send("toggleSidebar"); + }, + logout: unlessReadOnly( "_handleLogout", I18n.t("read_only_mode.logout_disabled") diff --git a/app/assets/javascripts/discourse/app/templates/application.hbs b/app/assets/javascripts/discourse/app/templates/application.hbs index be32149d8d9..a599818a5e4 100644 --- a/app/assets/javascripts/discourse/app/templates/application.hbs +++ b/app/assets/javascripts/discourse/app/templates/application.hbs @@ -2,7 +2,18 @@ - + + + diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs index 0750f30782f..1a082baaf82 100644 --- a/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar.hbs @@ -1,5 +1,6 @@ diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/categories-section.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/categories-section.hbs index ccd781ff5bc..2ab53b06dd5 100644 --- a/app/assets/javascripts/discourse/app/templates/components/sidebar/categories-section.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/categories-section.hbs @@ -4,7 +4,8 @@ @headerLinkText={{i18n "sidebar.sections.categories.header_link_text"}} @headerLinkTitle={{i18n "sidebar.sections.categories.header_link_title"}} @headerActions={{array (hash action=this.editTracked title=(i18n "sidebar.sections.categories.header_action_title"))}} - @headerActionsIcon="pencil-alt" > + @headerActionsIcon="pencil-alt" + @collapsable={{@collapsable}} > {{#if (gt this.sectionLinks.length 0)}} {{#each this.sectionLinks as |sectionLink|}} diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/footer.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/footer.hbs new file mode 100644 index 00000000000..62ce2ab0fb1 --- /dev/null +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/footer.hbs @@ -0,0 +1,30 @@ + diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs new file mode 100644 index 00000000000..7a55b9013f3 --- /dev/null +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/hamburger-dropdown.hbs @@ -0,0 +1,12 @@ +
+ +
diff --git a/app/assets/javascripts/discourse/app/templates/components/sidebar/messages-section.hbs b/app/assets/javascripts/discourse/app/templates/components/sidebar/messages-section.hbs index da67e0f84d0..e27bb15a612 100644 --- a/app/assets/javascripts/discourse/app/templates/components/sidebar/messages-section.hbs +++ b/app/assets/javascripts/discourse/app/templates/components/sidebar/messages-section.hbs @@ -6,7 +6,8 @@ @headerActions={{array (hash action=(fn (route-action "composePrivateMessage") null null))}} @headerActionsIcon="plus" @headerLinkText={{i18n "sidebar.sections.messages.header_link_text"}} - @headerLinkTitle={{i18n "sidebar.sections.messages.header_link_title"}} > + @headerLinkTitle={{i18n "sidebar.sections.messages.header_link_title"}} + @collapsable={{@collapsable}}> {{#each this.personalMessagesSectionLinks as |personalMessageSectionLink|}} {{#if personalMessageSectionLink.shouldDisplay}} @@ -21,8 +22,6 @@ {{/each}} {{#if (gt this.groupMessagesSectionLinks.length 0)}} -
- {{#each this.groupMessagesSectionLinks as |groupMessageSectionLink|}} {{#if groupMessageSectionLink.shouldDisplay}}