refactor(note-create): change order of noteCreate intoPath and intoInbox to improve code compatibility

This commit is contained in:
Jakob Schlanstedt 2025-10-12 18:54:39 +02:00
parent 1bb6149dbe
commit 384d8c9c37

View File

@ -39,35 +39,6 @@ interface DuplicateResponse {
note: FNote;
}
/**
* Creates a new note inside the user's Inbox.
*
* @param {CreateNoteOpts} [options] - Optional settings such as title, type, template, or content.
* @returns {Promise<{ note: FNote | null; branch: FBranch | undefined }>}
* Resolves with the created note and its branch, or `{ note: null, branch: undefined }` if the inbox is missing.
*/
async function createNoteIntoInbox(
options: CreateNoteOpts = {}
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
const inboxNote = await dateNoteService.getInboxNote();
if (!inboxNote) {
console.warn("Missing inbox note.");
// always return a defined object
return { note: null, branch: undefined };
}
if (options.isProtected === undefined) {
options.isProtected =
inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable();
}
const result = await createNoteIntoPath(inboxNote.noteId, {
...options,
target: "into",
});
return result;
}
/**
* Core function that creates a new note under the specified parent note path.
*
@ -149,6 +120,36 @@ async function createNoteIntoPath(
};
}
/**
* Creates a new note inside the user's Inbox.
*
* @param {CreateNoteOpts} [options] - Optional settings such as title, type, template, or content.
* @returns {Promise<{ note: FNote | null; branch: FBranch | undefined }>}
* Resolves with the created note and its branch, or `{ note: null, branch: undefined }` if the inbox is missing.
*/
async function createNoteIntoInbox(
options: CreateNoteOpts = {}
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
const inboxNote = await dateNoteService.getInboxNote();
if (!inboxNote) {
console.warn("Missing inbox note.");
// always return a defined object
return { note: null, branch: undefined };
}
if (options.isProtected === undefined) {
options.isProtected =
inboxNote.isProtected && protectedSessionHolder.isProtectedSessionAvailable();
}
const result = await createNoteIntoPath(inboxNote.noteId, {
...options,
target: "into",
});
return result;
}
async function chooseNoteType() {
return new Promise<ChooseNoteTypeResponse>((res) => {
appContext.triggerCommand("chooseNoteType", { callback: res });