Skip to content

Commit

Permalink
fix(Hierarchy Note): 🐛 Handle top item
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 22, 2021
1 parent 3b1309f commit 9e738c4
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,30 +487,37 @@ export default class BCPlugin extends Plugin {
const { HNUpField } = settings;
const upFields = getFields(userHiers, "up");

hierarchyNotesArr.forEach((hnItem) => {
if (hnItem.parentNote === null) return;

hierarchyNotesArr.forEach((hnItem, i) => {
const upField = hnItem.field ?? (HNUpField || upFields[0]);
const downField =
getOppFields(userHiers, upField)[0] ?? `${upField}<down>`;

const aUp = {
dir: "up",
field: upField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote], aUp);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.currNote, hnItem.parentNote, aUp);

const aDown = {
dir: "down",
field: downField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote], aDown);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.parentNote, hnItem.currNote, aDown);
if (hnItem.parentNote === null) {
const s = hnItem.currNote;
const t = hierarchyNotesArr[i + 1].currNote;
//@ts-ignore
addNodesIfNot(mainG, [s, t], { dir: "down", field: downField });
//@ts-ignore
addEdgeIfNot(mainG, s, t, { dir: "down", field: downField });
} else {
const aUp = {
dir: "up",
field: upField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.currNote, hnItem.parentNote], aUp);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.currNote, hnItem.parentNote, aUp);

const aDown = {
dir: "down",
field: downField,
};
//@ts-ignore
addNodesIfNot(mainG, [hnItem.parentNote, hnItem.currNote], aDown);
//@ts-ignore
addEdgeIfNot(mainG, hnItem.parentNote, hnItem.currNote, aDown);
}
});
}

Expand Down

0 comments on commit 9e738c4

Please sign in to comment.