Notes/src/public/app/widgets/buttons/open_note_button_widget.js

35 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-09-16 23:09:48 +02:00
import ButtonWidget from "./button_widget.js";
import appContext from "../../services/app_context.js";
2021-10-05 22:08:02 +02:00
import froca from "../../services/froca.js";
2021-09-17 10:09:42 +02:00
2021-09-16 23:09:48 +02:00
export default class OpenNoteButtonWidget extends ButtonWidget {
targetNote(noteId) {
2021-10-05 22:08:02 +02:00
froca.getNote(noteId).then(note => {
2021-11-20 12:49:12 +01:00
if (!note) {
console.log(`Note ${noteId} has not been found. This might happen on the first run before the target note is created.`);
if (!this.retried) {
this.retried = true;
setTimeout(() => this.targetNote(noteId), 15000); // should be higher than timeout for createMissingSpecialNotes
}
return;
}
2021-10-05 22:08:02 +02:00
this.icon(note.getIcon());
this.title(note.title);
this.refreshIcon();
});
2021-09-16 23:09:48 +02:00
this.onClick(() => appContext.tabManager.openTabWithNoteWithHoisting(noteId, true));
return this;
}
2021-10-05 22:08:02 +02:00
initialRenderCompleteEvent() {
// we trigger refresh above
}
2021-09-16 23:09:48 +02:00
}