Skip to content

Commit

Permalink
Store collapsed ingredient groups in localStorage
Browse files Browse the repository at this point in the history
sessionStorage gets emptied after the user closes the browser.
Using localStorage the groups state persists even after the user
logs out.
  • Loading branch information
tvdeyen committed Nov 16, 2023
1 parent 3dcdefc commit f35e9ab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/javascript/alchemy_admin/components/element_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ class ElementEditor extends AlchemyHTMLElement {
})
}

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) => {
Expand Down Expand Up @@ -189,7 +189,7 @@ class ElementEditor extends AlchemyHTMLElement {
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
Expand All @@ -203,7 +203,7 @@ class ElementEditor extends AlchemyHTMLElement {
)
}

sessionStorage.setItem(
localStorage.setItem(
"Alchemy.expanded_ingredient_groups",
JSON.stringify(expanded_ingredient_groups)
)
Expand Down

0 comments on commit f35e9ab

Please sign in to comment.