diff --git a/src/public/app/services/hoisted_note.js b/src/public/app/services/hoisted_note.ts similarity index 69% rename from src/public/app/services/hoisted_note.js rename to src/public/app/services/hoisted_note.ts index d6a3916de..8ef8d2879 100644 --- a/src/public/app/services/hoisted_note.js +++ b/src/public/app/services/hoisted_note.ts @@ -1,7 +1,8 @@ import appContext from "../components/app_context.js"; -import treeService from "./tree.js"; +import treeService, { Node } from "./tree.js"; import dialogService from "./dialog.js"; import froca from "./froca.js"; +import NoteContext from "../components/note_context.js"; function getHoistedNoteId() { const activeNoteContext = appContext.tabManager.getActiveContext(); @@ -17,11 +18,11 @@ async function unhoist() { } } -function isTopLevelNode(node) { +function isTopLevelNode(node: Node) { return isHoistedNode(node.getParent()); } -function isHoistedNode(node) { +function isHoistedNode(node: Node) { // even though check for 'root' should not be necessary, we keep it just in case return node.data.noteId === "root" || node.data.noteId === getHoistedNoteId(); @@ -35,10 +36,10 @@ async function isHoistedInHiddenSubtree() { } const hoistedNote = await froca.getNote(hoistedNoteId); - return hoistedNote.isHiddenCompletely(); + return hoistedNote?.isHiddenCompletely(); } -async function checkNoteAccess(notePath, noteContext) { +async function checkNoteAccess(notePath: string, noteContext: NoteContext) { const resolvedNotePath = await treeService.resolveNotePath(notePath, noteContext.hoistedNoteId); if (!resolvedNotePath) { @@ -49,11 +50,15 @@ async function checkNoteAccess(notePath, noteContext) { const hoistedNoteId = noteContext.hoistedNoteId; if (!resolvedNotePath.includes(hoistedNoteId) && (!resolvedNotePath.includes('_hidden') || resolvedNotePath.includes('_lbBookmarks'))) { - const requestedNote = await froca.getNote(treeService.getNoteIdFromUrl(resolvedNotePath)); + const noteId = treeService.getNoteIdFromUrl(resolvedNotePath); + if (!noteId) { + return false; + } + const requestedNote = await froca.getNote(noteId); const hoistedNote = await froca.getNote(hoistedNoteId); - if ((!hoistedNote.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks')) - && !await dialogService.confirm(`Requested note '${requestedNote.title}' is outside of hoisted note '${hoistedNote.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) { + if ((!hoistedNote?.hasAncestor('_hidden') || resolvedNotePath.includes('_lbBookmarks')) + && !await dialogService.confirm(`Requested note '${requestedNote?.title}' is outside of hoisted note '${hoistedNote?.title}' subtree and you must unhoist to access the note. Do you want to proceed with unhoisting?`)) { return false; }