Skip to content

Commit

Permalink
Retain palette collapse and filter to localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
GogoVega committed Mar 25, 2024
1 parent 50baad9 commit 9a07fc0
Showing 1 changed file with 12 additions and 1 deletion.
Expand Up @@ -73,11 +73,15 @@ RED.palette = (function() {
$("#red-ui-palette-header-"+category+" i").addClass("expanded");
},
toggle: function() {
const collapse = JSON.parse(localStorage.getItem("palette-collapse") || "[]");
if (catDiv.hasClass("red-ui-palette-open")) {
categoryContainers[category].close();
collapse.push(category);
} else {
categoryContainers[category].open();
collapse.splice(collapse.indexOf(category), 1);
}
localStorage.setItem("palette-collapse", JSON.stringify(collapse.filter((c, i, array) => array.indexOf(c) === i)));
}
};

Expand Down Expand Up @@ -602,8 +606,9 @@ RED.palette = (function() {
delay: 100,
change: function() {
filterChange($(this).val());
localStorage.setItem("palette-filter", $(this).val());
}
})
});

sidebarControls = $('<div class="red-ui-sidebar-control-left"><i class="fa fa-chevron-left"></i></div>').appendTo($("#red-ui-palette"));
RED.popover.tooltip(sidebarControls,RED._("keyboard.togglePalette"),"core:toggle-palette");
Expand Down Expand Up @@ -669,6 +674,12 @@ RED.palette = (function() {
togglePalette(state);
}
});

const collapse = JSON.parse(localStorage.getItem("palette-collapse") || "[]");
setTimeout(function () {
collapse.forEach((category) => categoryContainers[category]?.close());
$("#red-ui-palette-search input").searchBox("value", (localStorage.getItem("palette-filter") || ""));
}, 1000);
}
function togglePalette(state) {
if (!state) {
Expand Down

0 comments on commit 9a07fc0

Please sign in to comment.