Skip to content

Commit

Permalink
Fix issue requiring collapseIcon to be clicked twice to expand/collap…
Browse files Browse the repository at this point in the history
…sed deck tree (#656)

* Fix issue requiring collapseIcon to be clicked twice to expand/collapse deck tree

* Format with prettier
  • Loading branch information
adam-jw-casey authored Apr 9, 2023
1 parent 86287bd commit 76c1707
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/flashcard-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -843,13 +843,14 @@ export class Deck {
);
const shouldBeInitiallyExpanded: boolean =
modal.plugin.data.settings.initiallyExpandAllSubdecksInTree;
let collapsed = shouldBeInitiallyExpanded;
let collapsed = !shouldBeInitiallyExpanded;
let collapseIconEl: HTMLElement | null = null;
if (this.subdecks.length > 0) {
collapseIconEl = deckViewSelf.createDiv("tree-item-icon collapse-icon");
collapseIconEl.innerHTML = COLLAPSE_ICON;
(collapseIconEl.childNodes[0] as HTMLElement).style.transform =
shouldBeInitiallyExpanded ? "" : "rotate(-90deg)";
(collapseIconEl.childNodes[0] as HTMLElement).style.transform = collapsed
? "rotate(-90deg)"
: "";
}

const deckViewInner: HTMLElement = deckViewSelf.createDiv("tree-item-inner");
Expand Down Expand Up @@ -887,7 +888,7 @@ export class Deck {
);

const deckViewChildren: HTMLElement = deckView.createDiv("tree-item-children");
deckViewChildren.style.display = shouldBeInitiallyExpanded ? "block" : "none";
deckViewChildren.style.display = collapsed ? "none" : "block";
if (this.subdecks.length > 0) {
collapseIconEl.addEventListener("click", () => {
if (collapsed) {
Expand Down

0 comments on commit 76c1707

Please sign in to comment.