Skip to content

Commit

Permalink
refactor: clozeNumbers -> clozeOrds
Browse files Browse the repository at this point in the history
  • Loading branch information
BrayanDSO authored and lukstbit committed Mar 20, 2024
1 parent 260b636 commit ed5f1e5
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TemplatePreviewerViewModel(

private val note: Deferred<Note>
private val templateNames: Deferred<List<String>>
private val clozeNumbers: Deferred<List<Int>>?
private val clozeOrds: Deferred<List<Int>>?

init {
note = asyncIO {
Expand All @@ -72,16 +72,19 @@ class TemplatePreviewerViewModel(
}
}
if (isCloze) {
clozeNumbers = asyncIO {
val clozeNumbers = asyncIO {
val note = note.await()
withCol { clozeNumbersInNote(note) }
}
clozeOrds = asyncIO {
clozeNumbers.await().map { it - 1 }
}
templateNames = asyncIO {
val tr = CollectionManager.TR
clozeNumbers.await().map { tr.cardTemplatesCard(it) }
}
} else {
clozeNumbers = null
clozeOrds = null
templateNames = CompletableDeferred(notetype.templatesNames)
}
}
Expand Down Expand Up @@ -134,7 +137,7 @@ class TemplatePreviewerViewModel(
fun onTabSelected(position: Int) {
launchCatchingIO {
val ord = if (isCloze) {
clozeNumbers!!.await()[position] - 1
clozeOrds!!.await()[position]
} else {
position
}
Expand All @@ -145,7 +148,7 @@ class TemplatePreviewerViewModel(
@CheckResult
suspend fun getCurrentTabIndex(): Int {
return if (isCloze) {
clozeNumbers!!.await().indexOf(ordFlow.value + 1)
clozeOrds!!.await().indexOf(ordFlow.value)
} else {
ordFlow.value
}
Expand Down

0 comments on commit ed5f1e5

Please sign in to comment.