Skip to content

A platform for community discussion. Free, open, simple.

FEATURE: Store sidebar section display state in local storage (#17281)

Alan Guo Xiang Tan3a6e87ca4fdd
diff --git a/app/assets/javascripts/discourse/app/components/sidebar/section.js b/app/assets/javascripts/discourse/app/components/sidebar/section.js
index 59e16c49d0c..47cc438546f 100644
--- a/app/assets/javascripts/discourse/app/components/sidebar/section.js
+++ b/app/assets/javascripts/discourse/app/components/sidebar/section.js
@@ -4,11 +4,27 @@ import { action } from "@ember/object";
import { tracked } from "@glimmer/tracking";
export default class SidebarSection extends GlimmerComponent {
- @tracked displaySection = true;
+ @tracked displaySection;
+ collapsedSidebarSectionKey = `sidebar-section-${this.args.sectionName}-collapsed`;
+
+ constructor() {
+ super(...arguments);
+
+ this.displaySection =
+ this.keyValueStore.getItem(this.collapsedSidebarSectionKey) === undefined
+ ? true
+ : false;
+ }
@action
toggleSectionDisplay() {
this.displaySection = !this.displaySection;
+
+ if (this.displaySection) {
+ this.keyValueStore.remove(this.collapsedSidebarSectionKey);
+ } else {
+ this.keyValueStore.setItem(this.collapsedSidebarSectionKey, true);
+ }
}
get headerCaretIcon() {
diff --git a/app/assets/stylesheets/common/base/sidebar.scss b/app/assets/stylesheets/common/base/sidebar.scss
index 9a38add8d82..2c0cc828c24 100644
--- a/app/assets/stylesheets/common/base/sidebar.scss
+++ b/app/assets/stylesheets/common/base/sidebar.scss
@@ -155,12 +155,6 @@
border: none;
background: transparent;
padding: 0.25em 0;
- opacity: 0;
- transition: opacity 0.25s;
-
- &:hover {
- opacity: 100;
- }
svg {
display: block;