From 7067957899510eb261e3bc8cd49323e57c538e71 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 17 Aug 2023 17:25:24 +0200 Subject: [PATCH] cleaned up view --- src/main.ts | 3 +-- src/view.ts | 50 +++++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main.ts b/src/main.ts index 9fc0524..fb62f54 100644 --- a/src/main.ts +++ b/src/main.ts @@ -205,9 +205,8 @@ export default class JustSharePleasePlugin extends Plugin { text = text.replace(/^---\s*\n.*?\n---\s*\n(.*)$/s, "$1"); // include note name - if (this.settings.includeNoteName) { + if (this.settings.includeNoteName) text = `# ${file.basename}\n\n${text}`; - } // embed attachments directly let attachments = /!\[(.*)]\((.+)\)|!\[\[(.+)]]/g; diff --git a/src/view.ts b/src/view.ts index ff64e8f..7151f85 100644 --- a/src/view.ts +++ b/src/view.ts @@ -16,34 +16,38 @@ export class JSPView extends ItemView { public refresh(): void { this.contentEl.empty(); let content = this.contentEl.createDiv({cls: "just-share-please-view"}); - for (let shared of this.plugin.settings.shared) { - let file = this.plugin.app.vault.getAbstractFileByPath(shared.path) as TFile; - let div = content.createDiv({cls: "just-share-please-shared-item"}); - div.createSpan({cls: "just-share-please-shared-name", text: basename(shared.path, extname(shared.path))}); - new ButtonComponent(div) - .setClass("clickable-icon") - .setTooltip("Copy JSP link") - .setIcon("link") - .onClick(async () => this.plugin.copyShareLink(shared)); - if (file) { + if (this.plugin.settings.shared.length > 0) { + for (let shared of this.plugin.settings.shared) { + let file = this.plugin.app.vault.getAbstractFileByPath(shared.path) as TFile; + let div = content.createDiv({cls: "just-share-please-shared-item"}); + div.createSpan({cls: "just-share-please-shared-name", text: basename(shared.path, extname(shared.path))}); new ButtonComponent(div) .setClass("clickable-icon") - .setTooltip("Open in Obsidian") - .setIcon("edit") - .onClick(async () => { - // TODO open in obsidian - }); + .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 () => { + // TODO open in obsidian + }); + 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."}); } }