Skip to content

Commit

Permalink
refactor: use async/await insted of promise
Browse files Browse the repository at this point in the history
  • Loading branch information
levirs565 committed May 18, 2023
1 parent 7d62f9e commit 86653c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
7 changes: 3 additions & 4 deletions src/components/NoteComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@
node.appendChild(getIcon("right-triangle")!);
};
function createCurrentNote() {
async function createCurrentNote() {
const path = getNotePath(note);
const plugin = getPlugin();
plugin.createNote(path).then((file) => {
openFile(plugin.app, file);
});
const file = await plugin.createNote(path);
openFile(plugin.app, file);
}
function deleteCurrentNote() {
Expand Down
9 changes: 4 additions & 5 deletions src/modal/invalid-root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ export class InvalidRootModal extends Modal {
button
.setButtonText("Create")
.setCta()
.onClick(() => {
this.plugin.createRootFolder().then(() => {
this.plugin.onRootFolderChanged();
this.close();
});
.onClick(async () => {
await this.plugin.createRootFolder();
this.plugin.onRootFolderChanged();
this.close();
});
});
}
Expand Down
7 changes: 3 additions & 4 deletions src/modal/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ export class LookupModal extends SuggestModal<Note | null> {
el.append(getIcon("plus")!);
});
}
onChooseSuggestion(note: Note | null, evt: MouseEvent | KeyboardEvent) {
async onChooseSuggestion(note: Note | null, evt: MouseEvent | KeyboardEvent) {
if (note && note.file) {
openFile(this.app, note.file);
return;
}

const path = note ? getNotePath(note) : this.inputEl.value;
this.plugin.createNote(path).then((file) => {
return openFile(this.app, file);
});
const file = await this.plugin.createNote(path);
return openFile(this.app, file);
}
}

0 comments on commit 86653c4

Please sign in to comment.