From d852b61a675af2eb87097797a955d84b62569ee3 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 18 Aug 2023 12:58:43 +0200 Subject: [PATCH] bleh type checks --- src/view.ts | 57 +++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/view.ts b/src/view.ts index 68f3e08..c7bccb8 100644 --- a/src/view.ts +++ b/src/view.ts @@ -17,39 +17,40 @@ export class JSPView extends ItemView { let content = this.contentEl.createDiv({cls: "just-share-please-view"}); if (this.plugin.settings.shared.length > 0) { for (let shared of this.plugin.settings.shared) { - let file = this.plugin.app.vault.getAbstractFileByPath(shared.path) ; - if(!(file instanceof TFile)) - continue; - let div = content.createDiv({cls: "just-share-please-shared-item"}); - div.createSpan({cls: "just-share-please-shared-name", text: removeExtension(shared.path).split(/[/\\]/g).pop()}); - if (file?.path.match(/[/\\]/)) - div.createSpan({cls: "just-share-please-shared-path", text: removeExtension(file.path)}); - new ButtonComponent(div) - .setClass("clickable-icon") - .setTooltip("Copy JSP link") - .setIcon("link") - .onClick(async () => this.plugin.copyShareLink(shared)); - if (file) { + let abstractFile = this.plugin.app.vault.getAbstractFileByPath(shared.path); + if (abstractFile instanceof TFile) { + let file = abstractFile; + let div = content.createDiv({cls: "just-share-please-shared-item"}); + div.createSpan({cls: "just-share-please-shared-name", text: removeExtension(shared.path).split(/[/\\]/g).pop()}); + if (file?.path.match(/[/\\]/)) + div.createSpan({cls: "just-share-please-shared-path", text: removeExtension(file.path)}); new ButtonComponent(div) .setClass("clickable-icon") - .setTooltip("Open in Obsidian") - .setIcon("edit") - .onClick(async e => { - let leaf = this.app.workspace.getLeaf(e.ctrlKey); - await leaf.openFile(file); - this.app.workspace.setActiveLeaf(leaf, {focus: true}); - }); + .setTooltip("Copy JSP link") + .setIcon("link") + .onClick(async () => this.plugin.copyShareLink(shared)); + if (file) { + new ButtonComponent(div) + .setClass("clickable-icon") + .setTooltip("Open in Obsidian") + .setIcon("edit") + .onClick(async e => { + let leaf = this.app.workspace.getLeaf(e.ctrlKey); + await leaf.openFile(file); + this.app.workspace.setActiveLeaf(leaf, {focus: true}); + }); + new ButtonComponent(div) + .setClass("clickable-icon") + .setTooltip("Update in JSP") + .setIcon("share") + .onClick(async () => this.plugin.updateFile(shared, file)); + } new ButtonComponent(div) .setClass("clickable-icon") - .setTooltip("Update in JSP") - .setIcon("share") - .onClick(async () => this.plugin.updateFile(shared, file)); + .setTooltip("Delete from JSP") + .setIcon("trash") + .onClick(async () => this.plugin.deleteFile(shared)); } - new ButtonComponent(div) - .setClass("clickable-icon") - .setTooltip("Delete from JSP") - .setIcon("trash") - .onClick(async () => this.plugin.deleteFile(shared)); } } else { content.createSpan({text: "You have not shared any items yet."});