fix: address config modal review feedback

This commit is contained in:
2026-05-17 18:23:22 -07:00
parent c6537224f2
commit c369841827
17 changed files with 333 additions and 43 deletions
+21 -2
View File
@@ -177,14 +177,21 @@ export class AnkiConnectClient {
: [];
}
async fieldNamesForDeck(deckName: string, sampleSize = 100): Promise<string[]> {
private async noteInfosForDeck(
deckName: string,
sampleSize = 100,
): Promise<Record<string, unknown>[]> {
const escapedDeckName = deckName.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
const noteIds = await this.findNotes(`deck:"${escapedDeckName}"`, { maxRetries: 0 });
if (noteIds.length === 0) {
return [];
}
const noteInfos = await this.notesInfo(noteIds.slice(0, sampleSize));
return this.notesInfo(noteIds.slice(0, sampleSize));
}
async fieldNamesForDeck(deckName: string, sampleSize = 100): Promise<string[]> {
const noteInfos = await this.noteInfosForDeck(deckName, sampleSize);
const fields = new Set<string>();
for (const noteInfo of noteInfos) {
const noteFields = noteInfo.fields;
@@ -198,6 +205,18 @@ export class AnkiConnectClient {
return [...fields].sort();
}
async modelNamesForDeck(deckName: string, sampleSize = 100): Promise<string[]> {
const noteInfos = await this.noteInfosForDeck(deckName, sampleSize);
const modelNames = new Set<string>();
for (const noteInfo of noteInfos) {
const modelName = noteInfo.modelName;
if (typeof modelName === 'string' && modelName.length > 0) {
modelNames.add(modelName);
}
}
return [...modelNames].sort();
}
async notesInfo(noteIds: number[]): Promise<Record<string, unknown>[]> {
const result = await this.invoke('notesInfo', { notes: noteIds });
return (result as Record<string, unknown>[]) || [];