mirror of
https://github.com/zadam/trilium.git
synced 2025-12-08 08:24:24 +01:00
refactor(note_autocomplete): simplify big switch statement removing duplicate logic
This commit is contained in:
parent
767ae6d528
commit
961e59f0b4
@ -479,11 +479,21 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- CREATE NOTE INTO INBOX ---
|
case SuggestionAction.CreateNoteIntoInbox:
|
||||||
case SuggestionAction.CreateNoteIntoInbox: {
|
case SuggestionAction.CreateAndLinkNoteIntoInbox:
|
||||||
|
case SuggestionAction.CreateNoteIntoPath:
|
||||||
|
case SuggestionAction.CreateAndLinkNoteIntoPath: {
|
||||||
|
let target = "inbox";
|
||||||
|
if (
|
||||||
|
suggestion.action === SuggestionAction.CreateNoteIntoPath ||
|
||||||
|
suggestion.action === SuggestionAction.CreateAndLinkNoteIntoPath
|
||||||
|
) {
|
||||||
|
target = "path";
|
||||||
|
}
|
||||||
|
|
||||||
const { note } = await noteCreateService.createNote(
|
const { note } = await noteCreateService.createNote(
|
||||||
{
|
{
|
||||||
target: "inbox",
|
target: target,
|
||||||
title: suggestion.noteTitle,
|
title: suggestion.noteTitle,
|
||||||
activate: true,
|
activate: true,
|
||||||
promptForType: true,
|
promptForType: true,
|
||||||
@ -500,68 +510,6 @@ function initNoteAutocomplete($el: JQuery<HTMLElement>, options?: Options) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SuggestionAction.CreateAndLinkNoteIntoInbox: {
|
|
||||||
const { note } = await noteCreateService.createNote(
|
|
||||||
{
|
|
||||||
target: "inbox",
|
|
||||||
title: suggestion.noteTitle,
|
|
||||||
activate: false,
|
|
||||||
promptForType: true,
|
|
||||||
} as CreateNoteIntoInboxOpts,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!note) return;
|
|
||||||
|
|
||||||
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
|
||||||
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
|
||||||
|
|
||||||
$el.trigger("autocomplete:noteselected", [suggestion]);
|
|
||||||
$el.autocomplete("close");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SuggestionAction.CreateNoteIntoPath: {
|
|
||||||
const { note } = await noteCreateService.createNote(
|
|
||||||
{
|
|
||||||
target: "into",
|
|
||||||
parentNoteUrl: suggestion.parentNoteId,
|
|
||||||
title: suggestion.noteTitle,
|
|
||||||
activate: true,
|
|
||||||
promptForType: true,
|
|
||||||
} as CreateNoteWithUrlOpts,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!note) return;
|
|
||||||
|
|
||||||
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
|
||||||
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
|
||||||
|
|
||||||
$el.trigger("autocomplete:noteselected", [suggestion]);
|
|
||||||
$el.autocomplete("close");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SuggestionAction.CreateAndLinkNoteIntoPath: {
|
|
||||||
const { note } = await noteCreateService.createNote(
|
|
||||||
{
|
|
||||||
target: "into",
|
|
||||||
parentNoteUrl: suggestion.parentNoteId,
|
|
||||||
title: suggestion.noteTitle,
|
|
||||||
activate: false,
|
|
||||||
promptForType: true,
|
|
||||||
} as CreateNoteWithUrlOpts
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!note) return;
|
|
||||||
|
|
||||||
const hoistedNoteId = appContext.tabManager.getActiveContext()?.hoistedNoteId;
|
|
||||||
suggestion.notePath = note?.getBestNotePathString(hoistedNoteId);
|
|
||||||
|
|
||||||
$el.trigger("autocomplete:noteselected", [suggestion]);
|
|
||||||
$el.autocomplete("close");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case SuggestionAction.SearchNotes: {
|
case SuggestionAction.SearchNotes: {
|
||||||
const searchString = suggestion.noteTitle;
|
const searchString = suggestion.noteTitle;
|
||||||
appContext.triggerCommand("searchNotes", { searchString });
|
appContext.triggerCommand("searchNotes", { searchString });
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user