Skip to content

Commit

Permalink
Merge pull request #8 from jamesmagoo/highlights
Browse files Browse the repository at this point in the history
Highlights
  • Loading branch information
jamesmagoo authored Apr 18, 2024
2 parents 11a4960 + 7dba81c commit fe8ebd3
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 6 deletions.
33 changes: 32 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "./src/settings";
import { PublishedView, PUBLISHED_VIEW } from "./src/PublishedView";
import { ReaderView, READER_VIEW } from "./src/ReaderView";
import { HighlightsView , HIGHLIGHTS_VIEW } from "./src/HighlightsView";

export default class NostrWriterPlugin extends Plugin {
nostrService: NostrService;
Expand All @@ -31,16 +32,26 @@ export default class NostrWriterPlugin extends Plugin {
(leaf) => new ReaderView(leaf, this, this.nostrService)
);

this.registerView(
HIGHLIGHTS_VIEW,
(leaf) => new HighlightsView(leaf, this, this.nostrService)
);

// icon candidates : 'checkmark', 'blocks', 'scroll', 'pin'
this.addRibbonIcon("blocks", "See notes published to Nostr", () => {
this.togglePublishedView();
});

// icon candidates: 'bookmark', 'magnifying-glass', 'star-list', 'blocks'
// icon candidates: 'bookmark', 'magnifying-glass', 'star-list', 'blocks', 'sheets-in-box'
this.addRibbonIcon("star-list", "See your Nostr Bookmarks", () => {
this.toggleReaderView();
});

// icon candidates: "lines-of-text",'quote-glyph'
this.addRibbonIcon("lines-of-text", "See your Nostr Highlights", () => {
this.toggleHighlightsView();
});

this.addRibbonIcon(
"file-up",
"Publish this note to Nostr",
Expand Down Expand Up @@ -138,6 +149,23 @@ export default class NostrWriterPlugin extends Plugin {
);
};

toggleHighlightsView = async (): Promise<void> => {
const existing = this.app.workspace.getLeavesOfType(HIGHLIGHTS_VIEW);
if (existing.length) {
this.app.workspace.revealLeaf(existing[0]);
return;
}

await this.app.workspace.getRightLeaf(false).setViewState({
type: HIGHLIGHTS_VIEW,
active: true,
});

this.app.workspace.revealLeaf(
this.app.workspace.getLeavesOfType(HIGHLIGHTS_VIEW)[0]
);
};


onunload(): void {
this.nostrService.shutdownRelays();
Expand All @@ -147,6 +175,9 @@ export default class NostrWriterPlugin extends Plugin {
this.app.workspace
.getLeavesOfType(READER_VIEW)
.forEach((leaf) => leaf.detach());
this.app.workspace
.getLeavesOfType(HIGHLIGHTS_VIEW)
.forEach((leaf) => leaf.detach());
}

startupNostrService() {
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "nostr-writer",
"name": "Nostr Writer",
"version": "2.1.1",
"version": "2.2.0",
"minAppVersion": "0.15.0",
"description": "Publish your writing directly to Nostr.",
"author": "jamesmagoo",
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nostr-writer",
"version": "2.1.1",
"version": "2.2.0",
"description": "Publish your writing seamlessly to Nostr.",
"main": "main.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/ConfirmPublishModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export default class ConfirmPublishModal extends Modal {

// TODO check out Progress Bar Component...

if(this.file.extension !== "md"){
new Notice("❌ Only markdown files can be published.")
this.close()
return;
}

const frontmatterRegex = /---\s*[\s\S]*?\s*---/g;
const content = (await this.app.vault.read(this.file)).replace(frontmatterRegex, "").trim();

Expand Down Expand Up @@ -142,7 +148,6 @@ export default class ConfirmPublishModal extends Modal {


imageNameDiv.textContent = selectedBannerImage.name;
console.log(file)
new Notice(`✅ Selected image : ${file.name}`);
}
} else {
Expand Down Expand Up @@ -249,7 +254,7 @@ export default class ConfirmPublishModal extends Modal {
.setButtonText("Confirm and Publish")
.setCta()
.onClick(async () => {
if (confirm(`Are you sure you want to publish this note ${publishAsDraft ? "as a draft" : "publically" } to Nostr?`)) {
if (confirm(`Are you sure you want to publish this note ${publishAsDraft ? "as a draft" : "publically"} to Nostr?`)) {
// Disable the button and change the text to show a loading state
publishButton.setButtonText("Publishing...").setDisabled(true);
setTimeout(async () => {
Expand Down
Loading

0 comments on commit fe8ebd3

Please sign in to comment.