Skip to content

Commit

Permalink
fix: 🐛 More safety checks if no next/prev yet
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Nov 18, 2021
1 parent 58691c4 commit 918b3e0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 83 deletions.
110 changes: 52 additions & 58 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20401,30 +20401,36 @@ const getInNeighbours = (g, node) => g.hasNode(node) ? g.inNeighbors(node) : [];
function getPrevNext(plugin, currNode) {
const [rPrev, rNext, iPrev, iNext] = [[], [], [], []];
const { userHierarchies } = plugin.settings;
plugin.currGraphs.main.forEachEdge(currNode, (k, a, s, t) => {
const { fieldName } = a;
if (a.dir === "next" && s === currNode) {
rNext.push({ to: t, real: true, fieldName });
}
if (a.dir === "prev" && t === currNode) {
iNext.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
if (a.dir === "prev" && s === currNode) {
rPrev.push({ to: t, real: true, fieldName });
}
if (a.dir === "next" && t === currNode) {
iPrev.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
});
return { rPrev, rNext, iPrev, iNext };
try {
plugin.currGraphs.main.forEachEdge(currNode, (k, a, s, t) => {
const { fieldName } = a;
if (a.dir === "next" && s === currNode) {
rNext.push({ to: t, real: true, fieldName });
}
if (a.dir === "prev" && t === currNode) {
iNext.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
if (a.dir === "prev" && s === currNode) {
rPrev.push({ to: t, real: true, fieldName });
}
if (a.dir === "next" && t === currNode) {
iPrev.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
});
return { rPrev, rNext, iPrev, iNext };
}
catch (e) {
console.log(e);
return { rPrev, rNext, iPrev, iNext };
}
}

function noop$1() { }
Expand Down Expand Up @@ -22251,6 +22257,7 @@ class MatrixView extends obsidian.ItemView {
}
getHierSquares(userHierarchies, data, currFile, settings) {
const { basename } = currFile;
const { iNext: iNextInfo, iPrev: iPrevInfo, rNext: rNextInfo, rPrev: rPrevInfo, } = getPrevNext(this.plugin, basename);
return userHierarchies.map((hier, i) => {
const { up, same, down } = data[i];
let [rUp, rSame, rDown, iUp, iDown] = [
Expand All @@ -22260,40 +22267,6 @@ class MatrixView extends obsidian.ItemView {
this.squareItems(down, currFile, settings, false),
this.squareItems(up, currFile, settings, false),
];
const rNext = [];
const rPrev = [];
let iNext = [];
let iPrev = [];
this.plugin.currGraphs.main.forEachEdge(basename, (k, a, s, t) => {
if (a.dir === "next" && s === basename) {
rNext.push({
to: t,
cls: linkClass(this.app, t, true),
alt: this.getAlt(t, settings),
});
}
if (a.dir === "prev" && t === basename) {
iNext.push({
to: s,
cls: linkClass(this.app, s, false),
alt: this.getAlt(s, settings),
});
}
if (a.dir === "prev" && s === basename) {
rPrev.push({
to: t,
cls: linkClass(this.app, t, true),
alt: this.getAlt(t, settings),
});
}
if (a.dir === "next" && t === basename) {
iPrev.push({
to: s,
cls: linkClass(this.app, s, false),
alt: this.getAlt(s, settings),
});
}
});
// SECTION Implied Siblings
/// Notes with the same parents
let iSameArr = [];
Expand Down Expand Up @@ -22333,6 +22306,24 @@ class MatrixView extends obsidian.ItemView {
/// A real sibling implies the reverse sibling
iSameArr.push(...this.squareItems(same, currFile, settings, false));
// !SECTION
let [iNext, iPrev, rNext, rPrev] = [
iNextInfo,
iPrevInfo,
rNextInfo,
rPrevInfo,
].map((info) => {
return info
.filter((item) => hier.next.includes(item.fieldName) ||
hier.prev.includes(item.fieldName))
.map((item) => {
const { to } = item;
return {
to,
cls: linkClass(this.app, to, item.real),
alt: this.getAlt(to, settings),
};
});
});
iUp = this.removeDuplicateImplied(rUp, iUp);
iSameArr = this.removeDuplicateImplied(rSame, iSameArr);
iDown = this.removeDuplicateImplied(rDown, iDown);
Expand Down Expand Up @@ -35272,6 +35263,9 @@ class BCPlugin extends obsidian.Plugin {
prev: {},
};
DIRECTIONS.forEach((dir) => {
if (!hier[dir]) {
hier[dir] = [];
}
hier[dir].forEach((dirField) => {
newGraphs[dir][dirField] = new graphology_umd_min();
});
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,9 @@ export default class BCPlugin extends Plugin {
};

DIRECTIONS.forEach((dir: Directions) => {
if (!hier[dir]) {
hier[dir] = [];
}
hier[dir].forEach((dirField) => {
newGraphs[dir][dirField] = new Graph();
});
Expand Down
54 changes: 29 additions & 25 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,29 +818,33 @@ export const getInNeighbours = (g: Graph, node: string): string[] =>
export function getPrevNext(plugin: BCPlugin, currNode: string) {
const [rPrev, rNext, iPrev, iNext]: PrevNext[][] = [[], [], [], []];
const { userHierarchies } = plugin.settings;

plugin.currGraphs.main.forEachEdge(currNode, (k, a, s, t) => {
const { fieldName } = a;
if (a.dir === "next" && s === currNode) {
rNext.push({ to: t, real: true, fieldName });
}
if (a.dir === "prev" && t === currNode) {
iNext.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
if (a.dir === "prev" && s === currNode) {
rPrev.push({ to: t, real: true, fieldName });
}
if (a.dir === "next" && t === currNode) {
iPrev.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
});
return { rPrev, rNext, iPrev, iNext };
try {
plugin.currGraphs.main.forEachEdge(currNode, (k, a, s, t) => {
const { fieldName } = a;
if (a.dir === "next" && s === currNode) {
rNext.push({ to: t, real: true, fieldName });
}
if (a.dir === "prev" && t === currNode) {
iNext.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
if (a.dir === "prev" && s === currNode) {
rPrev.push({ to: t, real: true, fieldName });
}
if (a.dir === "next" && t === currNode) {
iPrev.push({
to: s,
real: false,
fieldName: getOppFields(userHierarchies, fieldName)[0],
});
}
});
return { rPrev, rNext, iPrev, iNext };
} catch (e) {
console.log(e);
return { rPrev, rNext, iPrev, iNext };
}
}

0 comments on commit 918b3e0

Please sign in to comment.