From d76d5b20f3081bbe3e1191fece09f446c1a6800b Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Thu, 18 Nov 2021 12:25:46 +0200 Subject: [PATCH] fix: :bug: Fail silently if hier.next/prev is undefined --- main.js | 27 ++++++++++++------ src/BreadcrumbsSettingTab.ts | 53 ++++++++++++++++++++---------------- src/sharedFunctions.ts | 2 +- 3 files changed, 50 insertions(+), 32 deletions(-) diff --git a/main.js b/main.js index 7ea2274e..23f4b9a4 100644 --- a/main.js +++ b/main.js @@ -19952,7 +19952,8 @@ async function getJugglLinks(app, settings) { let typeDir = ""; DIRECTIONS.forEach((dir) => { userHierarchies.forEach((hier) => { - if (hier[dir].includes(type)) { + var _a; + if ((_a = hier[dir]) === null || _a === void 0 ? void 0 : _a.includes(type)) { typeDir = dir; return; } @@ -23573,22 +23574,31 @@ class BCSettingTab extends obsidian.PluginSettingTab { new obsidian.Setting(trailDetails) .setName("Views to show") .setDesc("Choose which of the views to show at the top of the note.\nTrail, Grid, and/or the Next-Previous view.") - .addToggle(toggle => { - toggle.setTooltip('Show Trail view').setValue(settings.showTrail).onChange(async (value) => { + .addToggle((toggle) => { + toggle + .setTooltip("Show Trail view") + .setValue(settings.showTrail) + .onChange(async (value) => { settings.showTrail = value; await plugin.saveSettings(); await plugin.drawTrail(); }); }) - .addToggle(toggle => { - toggle.setTooltip('Show Grid view').setValue(settings.showGrid).onChange(async (value) => { + .addToggle((toggle) => { + toggle + .setTooltip("Show Grid view") + .setValue(settings.showGrid) + .onChange(async (value) => { settings.showGrid = value; await plugin.saveSettings(); await plugin.drawTrail(); }); }) - .addToggle(toggle => { - toggle.setTooltip('Show Next/Previous view').setValue(settings.showPrevNext).onChange(async (value) => { + .addToggle((toggle) => { + toggle + .setTooltip("Show Next/Previous view") + .setValue(settings.showPrevNext) + .onChange(async (value) => { settings.showPrevNext = value; await plugin.saveSettings(); await plugin.drawTrail(); @@ -23718,7 +23728,8 @@ class BCSettingTab extends obsidian.PluginSettingTab { const checkboxStates = settings.limitWriteBCCheckboxStates; settings.userHierarchies.forEach((userHier) => { DIRECTIONS.forEach((dir) => { - userHier[dir].forEach(async (field) => { + var _a; + (_a = userHier[dir]) === null || _a === void 0 ? void 0 : _a.forEach(async (field) => { if (field === "") return; // First sort out limitWriteBCCheckboxStates diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 2b4acf7b..a189b931 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -357,9 +357,7 @@ export class BCSettingTab extends PluginSettingTab { new Setting(trailDetails) .setName("Show Breadcrumbs") - .setDesc( - "Show a set of different views at the top of the current note." - ) + .setDesc("Show a set of different views at the top of the current note.") .addToggle((toggle) => toggle.setValue(settings.showBCs).onChange(async (value) => { settings.showBCs = value; @@ -430,27 +428,36 @@ export class BCSettingTab extends PluginSettingTab { .setDesc( "Choose which of the views to show at the top of the note.\nTrail, Grid, and/or the Next-Previous view." ) - .addToggle(toggle => { - toggle.setTooltip('Show Trail view').setValue(settings.showTrail).onChange(async (value) => { - settings.showTrail = value; - await plugin.saveSettings(); - await plugin.drawTrail(); - }) - }) - .addToggle(toggle => { - toggle.setTooltip('Show Grid view').setValue(settings.showGrid).onChange(async (value) => { - settings.showGrid = value; - await plugin.saveSettings(); - await plugin.drawTrail(); - }) + .addToggle((toggle) => { + toggle + .setTooltip("Show Trail view") + .setValue(settings.showTrail) + .onChange(async (value) => { + settings.showTrail = value; + await plugin.saveSettings(); + await plugin.drawTrail(); + }); }) - .addToggle(toggle => { - toggle.setTooltip('Show Next/Previous view').setValue(settings.showPrevNext).onChange(async (value) => { - settings.showPrevNext = value; - await plugin.saveSettings(); - await plugin.drawTrail(); - }) + .addToggle((toggle) => { + toggle + .setTooltip("Show Grid view") + .setValue(settings.showGrid) + .onChange(async (value) => { + settings.showGrid = value; + await plugin.saveSettings(); + await plugin.drawTrail(); + }); }) + .addToggle((toggle) => { + toggle + .setTooltip("Show Next/Previous view") + .setValue(settings.showPrevNext) + .onChange(async (value) => { + settings.showPrevNext = value; + await plugin.saveSettings(); + await plugin.drawTrail(); + }); + }); new Setting(trailDetails) .setName("Grid view dots") @@ -619,7 +626,7 @@ export class BCSettingTab extends PluginSettingTab { settings.userHierarchies.forEach((userHier) => { DIRECTIONS.forEach((dir) => { - userHier[dir].forEach(async (field) => { + userHier[dir]?.forEach(async (field) => { if (field === "") return; // First sort out limitWriteBCCheckboxStates if (checkboxStates[field] === undefined) { diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index d90cb979..f1f056f8 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -174,7 +174,7 @@ export async function getJugglLinks( let typeDir: Directions | "" = ""; DIRECTIONS.forEach((dir) => { userHierarchies.forEach((hier) => { - if (hier[dir].includes(type)) { + if (hier[dir]?.includes(type)) { typeDir = dir; return; }