From b5e0dfbb403c21ec0866a258212f84efa0e43dda Mon Sep 17 00:00:00 2001 From: James McGauran Date: Wed, 2 Aug 2023 19:43:56 +0100 Subject: [PATCH] Changes as per PR review --- README.md | 6 ++-- main.ts | 8 ++--- manifest.json | 5 ++- src/ConfirmPublishModal.ts | 25 +++++++------- src/ShortFormModal.ts | 68 +++++++++++++++++--------------------- src/nostr/NostrService.ts | 5 ++- src/settings.ts | 8 ++--- styles.css | 29 +++++++++++++--- 8 files changed, 82 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 439ad34..263c405 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ > Directly publish from Obsidian to Nostr ## A Match Made.. -**Obsidian** is an amazing markdown editor, word processor, note organiser, and idea synthesiser: the perfect tool for writers. +[**Obsidian**](https://obsidian.md/) is an amazing markdown editor, word processor, note organiser, and idea synthesiser: the perfect tool for writers. -**Nostr** represents the future of how we communicate and distribute the written word: decentralised, free, independent, incorruptible. +[**Nostr**](https://nostr.com/) represents the future of how we communicate and distribute the written word: decentralised, free, independent, incorruptible. They seem to me to be a match made in heaven... *** @@ -61,7 +61,7 @@ Therefore, it's important to ensure the overall security of your device and your > Remember, the security of your private key is your responsibility. ## SEND⚡️SATS need ☕️ -lighting address: +lightning address: ```text lnbc200u1pjv5400pp57cuefdhuwrmyvum62afe07x4dtxzyqmde6fc7nnf8cjujyqsfxeqdqsdfsk6etnd4skwmm0cqzzsxqyz5vqsp50fueknz7xnj828gv2n9tjnqhhkx7jyyvh6sg9r0jr8zeuy0d27ws9qyyssqeuwmtrhjt45vpky00cn5a63gl552wt8dxtdgeea6733l47ytl7kqwn90dp2859neswg0958tq8dwh7pjwyqdxwh02gx3teglk5zm06cpmmhau9 ``` \ No newline at end of file diff --git a/main.ts b/main.ts index fee1bdc..6ec0fd6 100644 --- a/main.ts +++ b/main.ts @@ -20,7 +20,7 @@ export default class NostrWriterPlugin extends Plugin { const ribbonIconEl = this.addRibbonIcon( "file-up", - "Publish This Note To Nostr", + "Publish this note to Nostr", async (evt: MouseEvent) => { await this.checkAndPublish(); } @@ -28,7 +28,7 @@ export default class NostrWriterPlugin extends Plugin { this.addCommand({ id: "publish-note-to-nostr", - name: "Publish Note to Nostr", + name: "Publish", callback: async() => { await this.checkAndPublish(); }, @@ -36,7 +36,7 @@ export default class NostrWriterPlugin extends Plugin { this.addCommand({ id: "get-pub", - name: "See Your Public Key", + name: "See your public key", callback: async () => { let pubKey = this.nostrService.getPublicKey(); new Notice(`Public Key: ${pubKey}`); @@ -45,7 +45,7 @@ export default class NostrWriterPlugin extends Plugin { this.addCommand({ id: "get-pub-clipboard", - name: "Copy Public Key to Clipboard", + name: "Copy public key to clipboard", callback: async () => { let pubKey = this.nostrService.getPublicKey(); navigator.clipboard.writeText(pubKey).then(() => { diff --git a/manifest.json b/manifest.json index 88f251d..4d1da37 100644 --- a/manifest.json +++ b/manifest.json @@ -1,12 +1,11 @@ { "id": "nostr-writer", "name": "Nostr Writer", - "version": "1.0.0", + "version": "1.0.1", "minAppVersion": "0.15.0", "description": "Publish your writing directly to Nostr..", "author": "James McGauran", "authorUrl": "https://github.com/jamesmagoo", - "fundingUrl": { - "Buy Me a Coffee" : "https://bmc.link/jamesmagoo"}, + "fundingUrl": {"Buy Me a Coffee" : "https://bmc.link/jamesmagoo"}, "isDesktopOnly": true } diff --git a/src/ConfirmPublishModal.ts b/src/ConfirmPublishModal.ts index 5d1a99a..02051ba 100644 --- a/src/ConfirmPublishModal.ts +++ b/src/ConfirmPublishModal.ts @@ -37,15 +37,18 @@ export default class ConfirmPublishModal extends Modal { ) .setValue(""); - imageUrlText.inputEl.style.width = "100%"; - imageUrlText.inputEl.style.marginBottom = "10px"; - imageUrlText.inputEl.style.marginTop = "10px"; + imageUrlText.inputEl.setCssStyles({ + width: "100%", + marginBottom: "10px", + marginTop: "10px", + }); - // Image Preview Section let imagePreview = contentEl.createEl("img"); - imagePreview.src = ""; // Set initial src - imagePreview.style.maxWidth = "100%"; - imagePreview.style.display = "none"; // Hide initially + imagePreview.setCssStyles({ + maxWidth: "100%", + display: "none", + }); + imagePreview.src = ""; // Update Image Preview on URL change imageUrlText.inputEl.addEventListener("input", () => { @@ -101,11 +104,9 @@ export default class ConfirmPublishModal extends Modal { }, 3000); }); - contentEl.style.fontFamily = "Arial, sans-serif"; - contentEl.style.padding = "15px"; - publishButton.buttonEl.style.display = "block"; - publishButton.buttonEl.style.margin = "auto"; - summaryText.inputEl.style.width = "100%"; + contentEl.classList.add("publish-modal-content"); + publishButton.buttonEl.classList.add("publish-modal-button"); + summaryText.inputEl.classList.add("publish-modal-input"); } } diff --git a/src/ShortFormModal.ts b/src/ShortFormModal.ts index 43c0dd9..5a4e444 100644 --- a/src/ShortFormModal.ts +++ b/src/ShortFormModal.ts @@ -3,25 +3,21 @@ import { ButtonComponent, Modal, Notice, - TextAreaComponent + TextAreaComponent, } from "obsidian"; import NostrService from "./nostr/NostrService"; export default class ShortFormModal extends Modal { - constructor( - app: App, - private nostrService: NostrService ) { + constructor(app: App, private nostrService: NostrService) { super(app); } async onOpen() { let { contentEl } = this; - contentEl.createEl("h2", { text: `Write A Short Note` }); - // let noteInfo = contentEl.createEl("p"); - // noteInfo.setText(`Write a short note to Nostr...`); + contentEl.createEl("h2", { text: `Write A Short Note` }); let summaryText = new TextAreaComponent(contentEl) .setPlaceholder("Write a Nostr message here...") - .setValue("") + .setValue(""); contentEl.createEl("p", { text: `Are you sure you want to send this message to Nostr?`, @@ -32,36 +28,34 @@ export default class ShortFormModal extends Modal { .setCta() .onClick(async () => { // Disable the button and change the text to show a loading state - if(summaryText.getValue().length > 1) { - publishButton.setButtonText("Sending...").setDisabled(true); - setTimeout(async () => { - // After 3 seconds, execute the publishing action - const summary = summaryText.getValue(); - const success = await this.nostrService.publishShortFormNote(summary); - if (success) { - new Notice(`Successfully sent note to Nostr.`); - } else { - new Notice(`Failed to send note to Nostr.`); - } - - // Change the button text back and enable it - publishButton - .setButtonText("Confirm and Publish") - .setDisabled(false); - - this.close(); - }, 3000); - } else { - new Notice(`Please enter text to publish to Nostr`); - } - + if (summaryText.getValue().length > 1) { + publishButton.setButtonText("Sending...").setDisabled(true); + setTimeout(async () => { + const summary = summaryText.getValue(); + const success = + await this.nostrService.publishShortFormNote( + summary + ); + if (success) { + new Notice(`Successfully sent note to Nostr.`); + } else { + new Notice(`Failed to send note to Nostr.`); + } + + // Change the button text back and enable it + publishButton + .setButtonText("Confirm and Publish") + .setDisabled(false); + + this.close(); + }, 3000); + } else { + new Notice(`Please enter text to publish to Nostr`); + } }); - // Add some style - contentEl.style.fontFamily = "Arial, sans-serif"; - contentEl.style.padding = "15px"; - publishButton.buttonEl.style.display = "block"; - publishButton.buttonEl.style.margin = "auto"; - summaryText.inputEl.style.width = "100%"; + contentEl.classList.add("short-form-modal-content"); + publishButton.buttonEl.classList.add("short-form-modal-button"); + summaryText.inputEl.classList.add("short-form-modal-input"); } } diff --git a/src/nostr/NostrService.ts b/src/nostr/NostrService.ts index 821002a..95f5e3c 100644 --- a/src/nostr/NostrService.ts +++ b/src/nostr/NostrService.ts @@ -24,7 +24,6 @@ export default class NostrService { constructor(plugin: NostrWriterPlugin, app: App, relayUrl: string, settings: NostrWriterPluginSettings) { console.log(`Initializing NostrService. with relayUrl: ${relayUrl}`); - const basePath = (app.vault.adapter as any).basePath; if (!settings.privateKey) { console.error( "YourPlugin requires a private key to be set in the settings." @@ -210,7 +209,7 @@ export default class NostrService { } async savePublishedEvent(finalEvent: Event) { - const pathToPlugin = normalizePath(app.vault.configDir + "//plugins/obsidian-nostr-writer/"); + const pathToPlugin = normalizePath(this.app.vault.configDir + "//plugins/obsidian-nostr-writer/"); const filePath = `${pathToPlugin}/published.json`; let publishedEvents; try { @@ -220,6 +219,6 @@ export default class NostrService { publishedEvents = []; } publishedEvents.push(finalEvent); - await app.vault.adapter.write(filePath, JSON.stringify(publishedEvents)); + await this.app.vault.adapter.write(filePath, JSON.stringify(publishedEvents)); } } diff --git a/src/settings.ts b/src/settings.ts index 0b7f1ca..15a37eb 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -1,12 +1,10 @@ -import NostrWriterPlugin from "../main"; import { App, - PluginSettingTab, - Setting, - Plugin, Notice, - TextAreaComponent, + PluginSettingTab, + Setting } from "obsidian"; +import NostrWriterPlugin from "../main"; export interface NostrWriterPluginSettings { privateKey: string; diff --git a/styles.css b/styles.css index 71cc60f..d145a5e 100644 --- a/styles.css +++ b/styles.css @@ -1,8 +1,27 @@ -/* +.short-form-modal-content { + font-family: Arial, sans-serif; + padding: 15px; +} -This CSS file will be included with your plugin, and -available in the app when your plugin is enabled. +.short-form-modal-button { + display: block; + margin: auto; +} -If your plugin does not need CSS, delete this file. +.short-form-modal-input { + width: 100%; +} -*/ +.publish-modal-content { + padding: 15px; + } + + .publish-modal-button { + display: block; + margin: auto; + } + + .publish-modal-input { + width: 100%; + } +