Skip to content

Commit cdc24a7

Browse files
committed
Solving the anki sync issue. The logic to recoup the anki deck id from the decks listing API call was doubly flawed:
1- WordListRepo.getOrCreate() didn't properly update the db 2- WordListRepo.getOrCreate() function didn't return an updated deck object, but the original object with the wrong id of 0
1 parent d022f77 commit cdc24a7

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

crossPlatform/src/commonMain/kotlin/fr/berliat/hskwidget/data/repo/WordListRepository.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ class WordListRepository(
321321
?: throw IllegalStateException("Couldn't fetch or create Deck in Anki."))
322322

323323
if (deck.ankiDeckId != ankiDeckId) {
324-
wordListDAO.updateAnkiDeckId(deck.id, deck.ankiDeckId)
324+
wordListDAO.updateAnkiDeckId(deck.id, ankiDeckId)
325+
326+
// Return an updated item with the right id
327+
return@withContext WordList(deck.name, deck.id, deck.creationDate,
328+
deck.lastModified, ankiDeckId, deck.listType)
325329
}
326330
}
327331

crossPlatform/src/commonMain/kotlin/fr/berliat/hskwidget/data/store/AnkiStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class AnkiStore(
9595
= withContext(AppDispatchers.IO) {
9696
Logger.d(tag = TAG, messageString = "importOrUpdateCard: ${word.simplified} to Anki")
9797
val modelId = getOrCreateModelId() ?: return@withContext null
98-
if (deck.ankiDeckId == WordList.Companion.ANKI_ID_EMPTY) throw IllegalStateException("Couldn't create a new Deck in Anki")
98+
if (deck.ankiDeckId == WordList.Companion.ANKI_ID_EMPTY)
99+
throw IllegalStateException("Couldn't create a new Deck in Anki")
99100

100101
with (word.annotation) {
101102
val fields = arrayOf(

0 commit comments

Comments
 (0)