mirror of
https://github.com/Ellpeck/ObsidianJustSharePlease.git
synced 2024-11-26 12:18:35 +01:00
bleh type checks
This commit is contained in:
parent
46cfbdfd36
commit
d852b61a67
1 changed files with 29 additions and 28 deletions
57
src/view.ts
57
src/view.ts
|
@ -17,39 +17,40 @@ export class JSPView extends ItemView {
|
||||||
let content = this.contentEl.createDiv({cls: "just-share-please-view"});
|
let content = this.contentEl.createDiv({cls: "just-share-please-view"});
|
||||||
if (this.plugin.settings.shared.length > 0) {
|
if (this.plugin.settings.shared.length > 0) {
|
||||||
for (let shared of this.plugin.settings.shared) {
|
for (let shared of this.plugin.settings.shared) {
|
||||||
let file = this.plugin.app.vault.getAbstractFileByPath(shared.path) ;
|
let abstractFile = this.plugin.app.vault.getAbstractFileByPath(shared.path);
|
||||||
if(!(file instanceof TFile))
|
if (abstractFile instanceof TFile) {
|
||||||
continue;
|
let file = abstractFile;
|
||||||
let div = content.createDiv({cls: "just-share-please-shared-item"});
|
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()});
|
div.createSpan({cls: "just-share-please-shared-name", text: removeExtension(shared.path).split(/[/\\]/g).pop()});
|
||||||
if (file?.path.match(/[/\\]/))
|
if (file?.path.match(/[/\\]/))
|
||||||
div.createSpan({cls: "just-share-please-shared-path", text: removeExtension(file.path)});
|
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) {
|
|
||||||
new ButtonComponent(div)
|
new ButtonComponent(div)
|
||||||
.setClass("clickable-icon")
|
.setClass("clickable-icon")
|
||||||
.setTooltip("Open in Obsidian")
|
.setTooltip("Copy JSP link")
|
||||||
.setIcon("edit")
|
.setIcon("link")
|
||||||
.onClick(async e => {
|
.onClick(async () => this.plugin.copyShareLink(shared));
|
||||||
let leaf = this.app.workspace.getLeaf(e.ctrlKey);
|
if (file) {
|
||||||
await leaf.openFile(file);
|
new ButtonComponent(div)
|
||||||
this.app.workspace.setActiveLeaf(leaf, {focus: true});
|
.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)
|
new ButtonComponent(div)
|
||||||
.setClass("clickable-icon")
|
.setClass("clickable-icon")
|
||||||
.setTooltip("Update in JSP")
|
.setTooltip("Delete from JSP")
|
||||||
.setIcon("share")
|
.setIcon("trash")
|
||||||
.onClick(async () => this.plugin.updateFile(shared, file));
|
.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 {
|
} else {
|
||||||
content.createSpan({text: "You have not shared any items yet."});
|
content.createSpan({text: "You have not shared any items yet."});
|
||||||
|
|
Loading…
Reference in a new issue