Skip to content

Commit

Permalink
Changes as per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmagoo committed Aug 2, 2023
1 parent c219d57 commit b5e0dfb
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 72 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
***
Expand Down Expand Up @@ -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
```
8 changes: 4 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ 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();
}
);

this.addCommand({
id: "publish-note-to-nostr",
name: "Publish Note to Nostr",
name: "Publish",
callback: async() => {
await this.checkAndPublish();
},
});

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}`);
Expand All @@ -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(() => {
Expand Down
5 changes: 2 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -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
}
25 changes: 13 additions & 12 deletions src/ConfirmPublishModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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");
}
}

Expand Down
68 changes: 31 additions & 37 deletions src/ShortFormModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?`,
Expand All @@ -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");
}
}
5 changes: 2 additions & 3 deletions src/nostr/NostrService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -210,7 +209,7 @@ export default class NostrService {
}

async savePublishedEvent(finalEvent: Event<Kind.Article>) {
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 {
Expand All @@ -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));
}
}
8 changes: 3 additions & 5 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
29 changes: 24 additions & 5 deletions styles.css
Original file line number Diff line number Diff line change
@@ -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%;
}

0 comments on commit b5e0dfb

Please sign in to comment.