Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Dec 25, 2024
1 parent b672763 commit 753f68f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions JL.Core/Mining/Anki/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ internal sealed class Note(
string deckName,
string modelName,
Dictionary<string, string> fields,
string[]? tags,
Dictionary<string, object>? options,
Dictionary<string, object>? audio,
Dictionary<string, object>? picture,
Dictionary<string, object>? video)
string[]? tags = null,
Dictionary<string, object>? options = null,
Dictionary<string, object>? audio = null,
Dictionary<string, object>? picture = null,
Dictionary<string, object>? video = null)
{
[JsonPropertyName("deckName")] public string DeckName { get; } = deckName;
[JsonPropertyName("modelName")] public string ModelName { get; } = modelName;
[JsonPropertyName("fields")] public Dictionary<string, string> Fields { get; } = fields;
[JsonPropertyName("tags")] public string[]? Tags { get; } = tags;
[JsonPropertyName("tags")] public string[]? Tags { get; set; } = tags;
[JsonPropertyName("options")] public Dictionary<string, object>? Options { get; set; } = options;
[JsonPropertyName("audio")] public Dictionary<string, object>? Audio { get; set; } = audio;
[JsonPropertyName("picture")] public Dictionary<string, object>? Picture { get; set; } = picture;
Expand Down
24 changes: 12 additions & 12 deletions JL.Core/Mining/MiningUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,12 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex
ankiConfig = ankiConfigDict.GetValueOrDefault(MineType.Other);
}

if (ankiConfig is null)
if (ankiConfig is null || ankiConfig.Fields.Count is 0)
{
continue;
}

OrderedDictionary<string, JLField> userFields = ankiConfig.Fields;
(string firstFieldName, JLField firstField) = userFields.GetAt(0);
(string firstFieldName, JLField firstField) = ankiConfig.Fields.GetAt(0);
string? firstFieldValue = GetMiningParameter(firstField, lookupResult, currentText, currentCharPosition);
if (string.IsNullOrEmpty(firstFieldValue))
{
Expand All @@ -791,7 +790,7 @@ public static async Task MineToFile(LookupResult lookupResult, string currentTex
{ firstFieldName, firstFieldValue }
};

Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields, null, null, null, null, null);
Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields);
notes.Add(note);
positions.Add(i);
}
Expand Down Expand Up @@ -861,7 +860,7 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str

// Audio/Picture/Video shouldn't be set here
// Otherwise AnkiConnect will place them under the "collection.media" folder even when it's a duplicate note
Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields, ankiConfig.Tags, null, null, null, null);
Note note = new(ankiConfig.DeckName, ankiConfig.ModelName, fields);
bool? canAddNote = await AnkiUtils.CanAddNote(note).ConfigureAwait(false);
if (canAddNote is null)
{
Expand All @@ -877,6 +876,14 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str
return;
}

note.Tags = ankiConfig.Tags;
note.Options = new Dictionary<string, object>(1, StringComparer.Ordinal)
{
{
"allowDuplicate", coreConfigManager.AllowDuplicateCards
}
};

List<string> audioFields = FindFields(JLField.Audio, userFields);
bool needsAudio = audioFields.Count > 0;
string reading = lookupResult.Readings?[0] ?? lookupResult.PrimarySpelling;
Expand Down Expand Up @@ -933,13 +940,6 @@ public static async Task Mine(LookupResult lookupResult, string currentText, str
};
}

note.Options = new Dictionary<string, object>(1, StringComparer.Ordinal)
{
{
"allowDuplicate", coreConfigManager.AllowDuplicateCards
}
};

Response? response = await AnkiConnect.AddNoteToDeck(note).ConfigureAwait(false);
if (response is null)
{
Expand Down

0 comments on commit 753f68f

Please sign in to comment.