Skip to content

Commit

Permalink
Add refresh button to published view
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmagoo committed Aug 13, 2023
1 parent 8db8025 commit 6c52581
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/PublishedView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export const PUBLISHED_VIEW = "published-view";

export class PublishedView extends ItemView {
plugin: NostrWriterPlugin;
private refreshDisplay: () => void;


constructor(leaf: WorkspaceLeaf, plugin: NostrWriterPlugin) {
super(leaf);
this.plugin = plugin;
this.refreshDisplay = () => this.onOpen()
}

getViewType() {
Expand All @@ -27,16 +29,26 @@ export class PublishedView extends ItemView {
async onOpen() {
const container = this.containerEl.children[1];
container.empty();
const banner = container.createEl("h4", { text: "Published" });
let banner = container.createEl("div", {
cls: "published-banner-div",
});
banner.createEl("h4", { text: "Published" });
new ButtonComponent(banner)
.setIcon("refresh-cw")
.setCta()
.setTooltip("Refresh view")
.onClick(() => {
this.refreshDisplay()
new Notice("View refreshed")
});

const publishedFilePath = `${this.plugin.manifest.dir}/published.json`;
try {
const file = await this.app.vault.adapter.read(publishedFilePath);
const publishedNotes = JSON.parse(file);

if(publishedNotes){

container.createEl("p", {text: `Total: ${publishedNotes.length} 📝` })
if(publishedNotes){
container.createEl("p", {text: `Total: ${publishedNotes.length} ✅` })
publishedNotes
.reverse()
.forEach((note: { tags: any[]; created_at: number , id : string, filepath: string}) => {
Expand Down Expand Up @@ -78,7 +90,7 @@ export class PublishedView extends ItemView {
cls: "published-id",
});

let copyButton = new ButtonComponent(detailsDiv)
new ButtonComponent(detailsDiv)
.setIcon("copy")
.setCta()
.setTooltip("Copy Nostr event ID")
Expand All @@ -96,7 +108,7 @@ export class PublishedView extends ItemView {
});
});

let gotoFileButton = new ButtonComponent(detailsDiv)
new ButtonComponent(detailsDiv)
.setIcon("file-text")
.setCta()
.setTooltip("Go to file in Obsidian")
Expand Down
9 changes: 9 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@
color: #b6b5b5;
}

.published-banner-div {
display: flex;
align-items: center;
justify-content: space-between;
padding: 5px 0;
/* border-bottom: 1px solid #ddd; subtle line to separate each item */
font-size: 12px;
}

.published-details-div p {
margin: 0;
}
Expand Down

0 comments on commit 6c52581

Please sign in to comment.