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 28, 2023
1 parent 443d21f commit 6f60f67
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 @@ -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) => {
Expand Down Expand Up @@ -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
Expand All @@ -212,7 +212,7 @@ class ElementEditor extends HTMLElement {
)
}

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

0 comments on commit 6f60f67

Please sign in to comment.