mirror of
https://github.com/rifts-obsidian-laboratory/anki-integration.git
synced 2026-07-22 05:42:50 +00:00
Refactoring - Added GenerateDeckSelector()
This commit is contained in:
parent
0776a8aecd
commit
390d27cbb1
3 changed files with 24 additions and 21 deletions
|
|
@ -19,6 +19,8 @@ import {
|
|||
ReadFileContent
|
||||
} from "../utils";
|
||||
import {ProcessAddNote} from "../AnkiConnect";
|
||||
import {GenerateDeckSelector} from "./modalsUtils";
|
||||
import {Drop} from "esbuild";
|
||||
|
||||
/**
|
||||
* A modal dialog for creating a new Anki note by using a code block content as pre-filled values.
|
||||
|
|
@ -75,18 +77,7 @@ export class AddNoteFromCodeBlockModal extends Modal {
|
|||
"ankiIntegrationModal__dropdownContainer--flex"
|
||||
])
|
||||
|
||||
/**
|
||||
* @type {DropdownComponent} deckSelector
|
||||
* @description Dropdown allowing the user to select a deck among those that are synchronized.
|
||||
*/
|
||||
const deckSelector: DropdownComponent = AddDropdown(dropdownContainer, "Choose a deck");
|
||||
|
||||
/**
|
||||
* @type {string[]} deckKeys
|
||||
* @description An array containing the keys of all available decks.
|
||||
*/
|
||||
const deckKeys: string[] = Object.keys(ankiData["decksData"]);
|
||||
AddOptionsToDropdownFromDataset(deckSelector, deckKeys, "name", "name", ankiData["decksData"]);
|
||||
const deckSelector: DropdownComponent = GenerateDeckSelector(dropdownContainer, ankiData);
|
||||
|
||||
/**
|
||||
* @type {DropdownComponent} modelSelector
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import {
|
|||
AddTitle, AutoAssignDeck, AutoAssignModel, AutoGenerateFields, BuildTagsArray, CreateFieldsGroupData,
|
||||
FetchModelByName
|
||||
} from "../utils";
|
||||
import {GenerateDeckSelector} from "./modalsUtils";
|
||||
|
||||
/**
|
||||
* A modal dialog for creating a new Anki note by using metadata as pre-filled values.
|
||||
|
|
@ -86,15 +87,7 @@ export class AddNoteFromMetadataModal extends Modal {
|
|||
"ankiIntegrationModal__dropdownContainer--flex"
|
||||
]);
|
||||
|
||||
// Create and configure the deck selector dropdown.
|
||||
const deckSelector = AddDropdown(dropdownContainer, "Choose a deck");
|
||||
|
||||
/**
|
||||
* @type {string[]} deckKeys
|
||||
* @description An array containing the keys of all available decks.
|
||||
*/
|
||||
const deckKeys: string[] = Object.keys(ankiData["decksData"]);
|
||||
AddOptionsToDropdownFromDataset(deckSelector, deckKeys, "name", "name", ankiData["decksData"]);
|
||||
const deckSelector = GenerateDeckSelector(dropdownContainer, ankiData);
|
||||
|
||||
// Create and configure the model selector dropdown.
|
||||
const modelSelector = AddDropdown(dropdownContainer, "Choose a model");
|
||||
|
|
|
|||
19
src/modals/modalsUtils.ts
Normal file
19
src/modals/modalsUtils.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import {DropdownComponent} from "obsidian";
|
||||
import {AddDropdown, AddOptionsToDropdownFromDataset} from "../utils";
|
||||
|
||||
export function GenerateDeckSelector(parent: HTMLDivElement, ankiData: Object) {
|
||||
/**
|
||||
* @type {DropdownComponent} deckSelector
|
||||
* @description Dropdown allowing the user to select a deck among those that are synchronized.
|
||||
*/
|
||||
const deckSelector: DropdownComponent = AddDropdown(parent, "Choose a deck");
|
||||
|
||||
/**
|
||||
* @type {string[]} deckKeys
|
||||
* @description An array containing the keys of all available decks.
|
||||
*/
|
||||
const deckKeys: string[] = Object.keys(ankiData["decksData"]);
|
||||
AddOptionsToDropdownFromDataset(deckSelector, deckKeys, "name", "name", ankiData["decksData"]);
|
||||
|
||||
return deckSelector;
|
||||
}
|
||||
Loading…
Reference in a new issue