From a3d6573d93281d1529fcae117cbd79a6b755df5e Mon Sep 17 00:00:00 2001 From: Dmitry Yankowski Date: Mon, 24 Feb 2020 23:34:06 -0500 Subject: [PATCH] Save collapsed sections to state When you refresh or navigate to a new page and back, your collapsed sections will be as you set them. --- components/section.vue | 26 ++- pages/graphql.vue | 441 ++++++++++++++++++----------------------- store/mutations.js | 6 + store/state.js | 55 ++--- 4 files changed, 248 insertions(+), 280 deletions(-) diff --git a/components/section.vue b/components/section.vue index 368da65c7..056d7ed4b 100644 --- a/components/section.vue +++ b/components/section.vue @@ -6,10 +6,13 @@ {{ label }} - {{ isCollapsed ? "expand_more" : "expand_less" }} + {{ isCollapsed(label) ? "expand_more" : "expand_less" }} -
+
@@ -26,15 +29,12 @@ export default { computed: { frameColorsEnabled() { return this.$store.state.postwoman.settings.FRAME_COLORS_ENABLED || false; + }, + sectionString() { + return `${this.$route.path}/${this.label}`; } }, - data() { - return { - isCollapsed: false - }; - }, - props: { label: { type: String, @@ -49,7 +49,15 @@ export default { collapse({ target }) { const parent = target.parentNode.parentNode; parent.querySelector(".collapsible").classList.toggle("hidden"); - this.isCollapsed = !this.isCollapsed; + // Save collapsed section to local state + this.$store.commit("setCollapsedSection", this.sectionString); + }, + isCollapsed(label) { + return ( + this.$store.state.theme.collapsedSections.includes( + this.sectionString + ) || false + ); } } }; diff --git a/pages/graphql.vue b/pages/graphql.vue index a430d4ff0..465e5fbdb 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -6,12 +6,7 @@