From 6f60f67b9f7d358ed7518f003a275fcd5a145151 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 16 Nov 2023 23:23:02 +0100 Subject: [PATCH] Store collapsed ingredient groups in localStorage sessionStorage gets emptied after the user closes the browser. Using localStorage the groups state persists even after the user logs out. --- .../alchemy_admin/components/element_editor.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/alchemy_admin/components/element_editor.js b/app/javascript/alchemy_admin/components/element_editor.js index b5c0437368..3786dc80e8 100644 --- a/app/javascript/alchemy_admin/components/element_editor.js +++ b/app/javascript/alchemy_admin/components/element_editor.js @@ -90,16 +90,16 @@ class ElementEditor extends HTMLElement { }) } - if (sessionStorage.hasOwnProperty("Alchemy.expanded_ingredient_groups")) { + if (localStorage.hasOwnProperty("Alchemy.expanded_ingredient_groups")) { this.expandIngredientGroups() } } /** - * Expands ingredient groups that are stored in sessionStorage as expanded + * Expands ingredient groups that are stored in localStorage as expanded */ expandIngredientGroups() { - const expanded_ingredient_groups = sessionStorage.getItem( + const expanded_ingredient_groups = localStorage.getItem( "Alchemy.expanded_ingredient_groups" ) Array.from(JSON.parse(expanded_ingredient_groups)).forEach((header_id) => { @@ -198,7 +198,7 @@ class ElementEditor extends HTMLElement { group_div.classList.toggle("expanded") let expanded_ingredient_groups = JSON.parse( - sessionStorage.getItem("Alchemy.expanded_ingredient_groups") || "[]" + localStorage.getItem("Alchemy.expanded_ingredient_groups") || "[]" ) // Add or remove depending on whether this ingredient group is expanded @@ -212,7 +212,7 @@ class ElementEditor extends HTMLElement { ) } - sessionStorage.setItem( + localStorage.setItem( "Alchemy.expanded_ingredient_groups", JSON.stringify(expanded_ingredient_groups) )