Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
refactor(panel): Simplify toggle logic
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Oct 9, 2022
1 parent 3d51016 commit ea7cf8a
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions packages/userscript/source/ui/components/SettingsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,8 @@ export class SettingsPanel {
const itemsElement = SettingsPanel.makeItemsToggle(host, id).text(
initiallyExpanded ? "-" : "+"
);
itemsElement.data("expanded", initiallyExpanded);
itemsElement.on("click", () => {
list.element.toggle();
const itemsExpanded = !itemsElement.data("expanded");

itemsElement.data("expanded", itemsExpanded);
itemsElement.prop(
"title",
itemsExpanded ? host.engine.i18n("ui.itemsHide") : host.engine.i18n("ui.itemsShow")
);
itemsElement.text(itemsExpanded ? "-" : "+");
this.toggle();
});

element.element.append(itemsElement, list.element);
Expand All @@ -78,16 +69,14 @@ export class SettingsPanel {
this._element.refreshUi();
}

toggle(expand: boolean | undefined) {
toggle(expand: boolean | undefined = undefined) {
this._mainChildVisible = expand !== undefined ? expand : !this._mainChildVisible;
if (this._mainChildVisible) {
this.list.show();
this.expando.data("expanded", true);
this.expando.prop("title", this.host.engine.i18n("ui.itemsHide"));
this.expando.text("-");
} else {
this.list.hide();
this.expando.data("expanded", false);
this.expando.prop("title", this.host.engine.i18n("ui.itemsShow"));
this.expando.text("+");
}
Expand Down

0 comments on commit ea7cf8a

Please sign in to comment.