mirror of
https://github.com/rifts-obsidian-laboratory/anki-integration.git
synced 2026-07-22 05:42:50 +00:00
Code Refactoring - Turned tags array building's code into a reusable function in utils.ts
This commit is contained in:
parent
f0a533fb7e
commit
c85bd8bd2f
4 changed files with 34 additions and 41 deletions
|
|
@ -3,10 +3,19 @@ import AnkiIntegration from "../main";
|
|||
import {
|
||||
AddButton,
|
||||
AddContainer,
|
||||
AddDropdown, AddFieldGroups, AddInput,
|
||||
AddOptionsToDropdownFromDataset, AddParagraph,
|
||||
AddDropdown,
|
||||
AddFieldGroups,
|
||||
AddInput,
|
||||
AddOptionsToDropdownFromDataset,
|
||||
AddParagraph,
|
||||
AddSubtitle,
|
||||
AddTitle, AutoAssignDeck, AutoAssignModel, AutoGenerateFields, CreateFieldsGroupData, FetchModelByName,
|
||||
AddTitle,
|
||||
AutoAssignDeck,
|
||||
AutoAssignModel,
|
||||
AutoGenerateFields,
|
||||
BuildTagsArray,
|
||||
CreateFieldsGroupData,
|
||||
FetchModelByName,
|
||||
ReadFileContent
|
||||
} from "../utils";
|
||||
import {ProcessAddNote} from "../AnkiConnect";
|
||||
|
|
@ -209,12 +218,7 @@ export class AddNoteFromCodeBlockModal extends Modal {
|
|||
* @param {MouseEvent} event - The click event triggered by the submit button.
|
||||
*/
|
||||
submitButtonEl.onClick(async () => {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
});
|
||||
/**
|
||||
|
|
@ -225,12 +229,7 @@ export class AddNoteFromCodeBlockModal extends Modal {
|
|||
*/
|
||||
this.contentEl.addEventListener("keydown", async (event) => {
|
||||
if (event.shiftKey && event.key === "Enter") {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import {
|
|||
AddOptionsToDropdownFromDataset,
|
||||
AddParagraph,
|
||||
AddSubtitle,
|
||||
AddTitle, AutoAssignDeck, AutoAssignModel, AutoGenerateFields, CreateFieldsGroupData,
|
||||
AddTitle, AutoAssignDeck, AutoAssignModel, AutoGenerateFields, BuildTagsArray, CreateFieldsGroupData,
|
||||
FetchModelByName
|
||||
} from "../utils";
|
||||
|
||||
|
|
@ -220,12 +220,7 @@ export class AddNoteFromMetadataModal extends Modal {
|
|||
* @param {MouseEvent} event - The click event triggered by the submit button.
|
||||
*/
|
||||
submitButtonEl.onClick(async () => {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
});
|
||||
/**
|
||||
|
|
@ -236,12 +231,7 @@ export class AddNoteFromMetadataModal extends Modal {
|
|||
*/
|
||||
this.contentEl.addEventListener("keydown", async (event) => {
|
||||
if (event.shiftKey && event.key === "Enter") {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
AddOptionsToDropdownFromDataset,
|
||||
AddParagraph,
|
||||
AddSubtitle,
|
||||
AddTitle, CreateFieldsGroupData,
|
||||
AddTitle, BuildTagsArray, CreateFieldsGroupData,
|
||||
FetchModelByName
|
||||
} from "../utils";
|
||||
|
||||
|
|
@ -242,12 +242,7 @@ export class AddNoteModal extends Modal {
|
|||
* @param {MouseEvent} event - The click event triggered by the submit button.
|
||||
*/
|
||||
submitButtonEl.onClick(async () => {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
})
|
||||
|
||||
|
|
@ -259,12 +254,7 @@ export class AddNoteModal extends Modal {
|
|||
*/
|
||||
this.contentEl.addEventListener("keydown", async (event) => {
|
||||
if (event.shiftKey && event.key === "Enter") {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
const tags: Array<string> = BuildTagsArray();
|
||||
await ProcessAddNote(deckSelector, modelSelector, inputContainer, tags, this);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
14
src/utils.ts
14
src/utils.ts
|
|
@ -360,4 +360,18 @@ export function AutoGenerateFields(modal: AddNoteFromMetadataModal | AddNoteFrom
|
|||
} else {
|
||||
modal.AddFieldsGroupsToModal(inputContainer, modelSelector.getValue(), noteParameters);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an array that stores all tags entered by the user in the form used to add a note.
|
||||
* @return {Array<string>} tags
|
||||
*/
|
||||
export function BuildTagsArray(): Array<string> {
|
||||
const tagInputs = document.querySelectorAll('#tagInput');
|
||||
let tags: Array<string> = [];
|
||||
tagInputs.forEach((tagInput) => {
|
||||
// @ts-ignore
|
||||
tags.push(tagInput.value);
|
||||
})
|
||||
return tags;
|
||||
}
|
||||
Loading…
Reference in a new issue