mirror of
https://github.com/zadam/trilium.git
synced 2025-12-04 22:44:25 +01:00
refactor(note_create): reorder function order to simplify diff
This commit is contained in:
parent
72c17b22df
commit
3c39026739
@ -101,6 +101,75 @@ interface DuplicateResponse {
|
|||||||
note: FNote;
|
note: FNote;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* We are overloading createNote for each type */
|
||||||
|
async function createNote(
|
||||||
|
options: CreateNoteIntoURLOpts
|
||||||
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
||||||
|
|
||||||
|
async function createNote(
|
||||||
|
options: CreateNoteAfterURLOpts
|
||||||
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
||||||
|
|
||||||
|
async function createNote(
|
||||||
|
options: CreateNoteBeforeURLOpts
|
||||||
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
||||||
|
|
||||||
|
async function createNote(
|
||||||
|
options: CreateNoteIntoInboxURLOpts
|
||||||
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
||||||
|
|
||||||
|
async function createNote(
|
||||||
|
options: BaseCreateNoteOpts
|
||||||
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||||
|
|
||||||
|
let resolvedOptions = { ...options };
|
||||||
|
|
||||||
|
// handle prompts centrally to write once fix for all
|
||||||
|
if (options.promptForType) {
|
||||||
|
const { success, noteType, templateNoteId, notePath } = await chooseNoteType();
|
||||||
|
|
||||||
|
if (!success) return {
|
||||||
|
note: null, branch: undefined
|
||||||
|
};
|
||||||
|
|
||||||
|
resolvedOptions = {
|
||||||
|
...resolvedOptions,
|
||||||
|
promptForType: false,
|
||||||
|
type: noteType,
|
||||||
|
templateNoteId,
|
||||||
|
} as BaseCreateNoteOpts;
|
||||||
|
|
||||||
|
if (notePath) {
|
||||||
|
resolvedOptions = resolvedOptions as CreateNoteIntoURLOpts;
|
||||||
|
resolvedOptions = {
|
||||||
|
...resolvedOptions,
|
||||||
|
target: CreateNoteTarget.IntoNoteURL,
|
||||||
|
parentNoteUrl: notePath,
|
||||||
|
} as CreateNoteIntoURLOpts;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (resolvedOptions.target) {
|
||||||
|
case CreateNoteTarget.IntoNoteURL:
|
||||||
|
return await createNoteIntoNote(resolvedOptions as CreateNoteIntoURLOpts);
|
||||||
|
|
||||||
|
case CreateNoteTarget.BeforeNoteURL:
|
||||||
|
return await createNoteBeforeNote(resolvedOptions as CreateNoteBeforeURLOpts);
|
||||||
|
|
||||||
|
case CreateNoteTarget.AfterNoteURL:
|
||||||
|
return await createNoteAfterNote(resolvedOptions as CreateNoteAfterURLOpts);
|
||||||
|
|
||||||
|
case CreateNoteTarget.IntoInbox:
|
||||||
|
return await createNoteIntoInbox(resolvedOptions as CreateNoteIntoInboxURLOpts);
|
||||||
|
|
||||||
|
default: {
|
||||||
|
console.warn("[createNote] Unknown target:", options.target, resolvedOptions);
|
||||||
|
toastService.showMessage("Unknown note creation target."); // optional
|
||||||
|
return { note: null, branch: undefined };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core function that creates a new note under the specified parent note path.
|
* Core function that creates a new note under the specified parent note path.
|
||||||
*
|
*
|
||||||
@ -185,6 +254,8 @@ async function createNoteAtNote(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Small wrapper functions for @see createNoteAtNote, using it a certain way to
|
||||||
|
// remove code duplication
|
||||||
async function createNoteIntoNote(
|
async function createNoteIntoNote(
|
||||||
options: CreateNoteIntoURLOpts
|
options: CreateNoteIntoURLOpts
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
||||||
@ -241,75 +312,6 @@ async function chooseNoteType() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We are overloading createNote for each type */
|
|
||||||
async function createNote(
|
|
||||||
options: CreateNoteIntoURLOpts
|
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
|
||||||
|
|
||||||
async function createNote(
|
|
||||||
options: CreateNoteAfterURLOpts
|
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
|
||||||
|
|
||||||
async function createNote(
|
|
||||||
options: CreateNoteBeforeURLOpts
|
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
|
||||||
|
|
||||||
async function createNote(
|
|
||||||
options: CreateNoteIntoInboxURLOpts
|
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }>;
|
|
||||||
|
|
||||||
async function createNote(
|
|
||||||
options: BaseCreateNoteOpts
|
|
||||||
): Promise<{ note: FNote | null; branch: FBranch | undefined }> {
|
|
||||||
|
|
||||||
let resolvedOptions = { ...options };
|
|
||||||
|
|
||||||
// handle prompts centrally to write once fix for all
|
|
||||||
if (options.promptForType) {
|
|
||||||
const { success, noteType, templateNoteId, notePath } = await chooseNoteType();
|
|
||||||
|
|
||||||
if (!success) return {
|
|
||||||
note: null, branch: undefined
|
|
||||||
};
|
|
||||||
|
|
||||||
resolvedOptions = {
|
|
||||||
...resolvedOptions,
|
|
||||||
promptForType: false,
|
|
||||||
type: noteType,
|
|
||||||
templateNoteId,
|
|
||||||
} as BaseCreateNoteOpts;
|
|
||||||
|
|
||||||
if (notePath) {
|
|
||||||
resolvedOptions = resolvedOptions as CreateNoteIntoURLOpts;
|
|
||||||
resolvedOptions = {
|
|
||||||
...resolvedOptions,
|
|
||||||
target: CreateNoteTarget.IntoNoteURL,
|
|
||||||
parentNoteUrl: notePath,
|
|
||||||
} as CreateNoteIntoURLOpts;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (resolvedOptions.target) {
|
|
||||||
case CreateNoteTarget.IntoNoteURL:
|
|
||||||
return await createNoteIntoNote(resolvedOptions as CreateNoteIntoURLOpts);
|
|
||||||
|
|
||||||
case CreateNoteTarget.BeforeNoteURL:
|
|
||||||
return await createNoteBeforeNote(resolvedOptions as CreateNoteBeforeURLOpts);
|
|
||||||
|
|
||||||
case CreateNoteTarget.AfterNoteURL:
|
|
||||||
return await createNoteAfterNote(resolvedOptions as CreateNoteAfterURLOpts);
|
|
||||||
|
|
||||||
case CreateNoteTarget.IntoInbox:
|
|
||||||
return await createNoteIntoInbox(resolvedOptions as CreateNoteIntoInboxURLOpts);
|
|
||||||
|
|
||||||
default: {
|
|
||||||
console.warn("[createNote] Unknown target:", options.target, resolvedOptions);
|
|
||||||
toastService.showMessage("Unknown note creation target."); // optional
|
|
||||||
return { note: null, branch: undefined };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the first element is heading, parse it out and use it as a new heading. */
|
/* If the first element is heading, parse it out and use it as a new heading. */
|
||||||
function parseSelectedHtml(selectedHtml: string) {
|
function parseSelectedHtml(selectedHtml: string) {
|
||||||
const dom = $.parseHTML(selectedHtml);
|
const dom = $.parseHTML(selectedHtml);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user