Skip to content

Commit

Permalink
add error handling and header links to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorpark24 committed Jul 18, 2024
1 parent a641029 commit f7371c4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 12 deletions.
29 changes: 23 additions & 6 deletions RefresherModal.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { App, Modal } from "obsidian";
import { App, Modal, TFile } from "obsidian";

export class RefresherModal extends Modal {
private summaries: { name: string; summary: string }[] | null;
private summaries: { file: TFile; summary: string }[] | null;

constructor(
app: App,
summaries: { name: string; summary: string }[] | null
summaries: { file: TFile; summary: string }[] | null
) {
super(app);
this.summaries = summaries;
Expand All @@ -27,8 +27,17 @@ export class RefresherModal extends Modal {
contentEl.createEl("h2", { text: "Daily refresher" });

this.summaries?.forEach((note) => {
const noteName = note.name.replace(/\.md$/, "");
contentEl.createEl("h3", { text: noteName });
const noteName = note.file.basename;
const noteLink = contentEl.createEl("a", {
text: noteName,
href: note.file.path,
cls: "note-link",
});
noteLink.addEventListener("click", (e) => {
e.preventDefault();
this.app.workspace.openLinkText(note.file.path, note.file.path);
this.close();
});
contentEl.createEl("p", { text: note.summary });
});
}
Expand All @@ -38,8 +47,16 @@ export class RefresherModal extends Modal {
contentEl.empty();
}

updateSummaries(summaries: { name: string; summary: string }[]) {
updateSummaries(summaries: { file: TFile; summary: string }[]) {
this.summaries = summaries;
this.displaySummaries(this.contentEl);
}

displayError(errorMessage: string) {
this.summaries = [];
const { contentEl } = this;
contentEl.empty();
contentEl.createEl("h2", { text: "Daily refresher" });
contentEl.createEl("p", { text: "Error: " + errorMessage });
}
}
15 changes: 12 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ export default class NotesRefresher extends Plugin {
this.addSettingTab(new NotesRefresherSettingTab(this.app, this));

this.addRibbonIcon("clock-4", "Get note summaries", async () => {
if (!this.settings.apiKey) {
const modal = new RefresherModal(this.app, null);
modal.open();
modal.displayError(
"API key is not provided. Please enter your OpenAI API key in settings."
);
return;
}

const modal = new RefresherModal(this.app, null);
modal.open();

Expand Down Expand Up @@ -89,8 +98,8 @@ export default class NotesRefresher extends Plugin {

async summarizeNotes(
notes: TFile[]
): Promise<{ name: string; summary: string }[]> {
const summaries: { name: string; summary: string }[] = [];
): Promise<{ file: TFile; summary: string }[]> {
const summaries: { file: TFile; summary: string }[] = [];
const apiKey = this.settings.apiKey;

const llm = new ChatOpenAI({
Expand Down Expand Up @@ -119,7 +128,7 @@ export default class NotesRefresher extends Plugin {
const fullSummary = result.text;

summaries.push({
name: note.name,
file: note,
summary: fullSummary.trim(),
});
}
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": "notes-refresher",
"name": "Notes Refresher",
"version": "1.0.2",
"version": "1.1.0",
"minAppVersion": "1.6.5",
"description": "Provides AI-generated summaries (GPT) of three notes from your Vault every day.",
"author": "Connor Park",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "notes-refresher",
"version": "1.0.2",
"version": "1.1.0",
"description": "Provides AI-generated summaries (GPT) of three notes from your Vault every day.",
"main": "main.js",
"scripts": {
Expand Down
8 changes: 8 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@
margin: 0 auto;
}


@keyframes spin {
to {
transform: rotate(360deg);
}
}

.note-link {
font-size: 1.5em;
font-weight: 600;
display: block;
margin-bottom: 0.5em;
}
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"1.0.0": "1.6.5",
"1.0.1": "1.6.5",
"1.0.2": "1.6.5"
"1.0.2": "1.6.5",
"1.1.0": "1.6.5"
}

0 comments on commit f7371c4

Please sign in to comment.