Skip to content
Snippets Groups Projects
Commit e914415d authored by Tóth Miklós Tibor's avatar Tóth Miklós Tibor :shrug:
Browse files

Fix off by one

parent b3ea7c50
Branches
No related tags found
No related merge requests found
......@@ -9,17 +9,17 @@ import pekstuff.trimAsPrinciple
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
class GSheet private constructor(sheet: sheets.Spreadsheet): DataSource, NoteDataSource {
class GSheet private constructor(sheet: sheets.Spreadsheet, sheetNum: Int = 0): DataSource, NoteDataSource {
companion object {
private val filterList = listOf(
"szumma", "színes belépő"
)
suspend fun new(url: String): GSheet {
suspend fun new(url: String, sheetNum: Int = 0): GSheet {
if (!isSignedIn) throw Error("You must sign in to get gapi.sheets")
val sheet = getSheetFromUrl(url)
window.asDynamic().test = sheet
return GSheet(sheet)
return GSheet(sheet, sheetNum)
}
@NoLiveLiterals
......@@ -36,7 +36,7 @@ class GSheet private constructor(sheet: sheets.Spreadsheet): DataSource, NoteDat
}
}
private val rows = sheet.sheets!![0].data!![0].rowData!!
private val rows = sheet.sheets!![sheetNum].data!![0].rowData!!
private val principleIndexes = rows[0].values!!.mapIndexed { i, data ->
(data.formattedValue?.trimAsPrinciple() ?: "") to i
......
......@@ -37,6 +37,7 @@ private object SheetsModal: ModalType {
}
var sheetUrl by remember { mutableStateOf("") }
var sheetNum by remember { mutableStateOf(1) }
var sheet by remember { mutableStateOf<GSheet?>(null) }
setHint(
......@@ -86,13 +87,26 @@ private object SheetsModal: ModalType {
value(sheetUrl)
})
}
withLabel("Hányadik sheet (fül)") { id ->
Input(type = InputType.Number, attrs = {
id(id)
classes("uk-input")
onInput {
sheetNum = it.value?.toInt() ?: return@onInput
if (sheetNum <= 0) {
sheetNum = 1
}
}
value(sheetNum)
})
}
Hr { }
divFloatRight {
Button({
classes("uk-button", "uk-button-primary")
onClick {
scope.launch {
sheet = GSheet.new(sheetUrl)
sheet = GSheet.new(sheetUrl, sheetNum-1)
sheet?.process { setState(ImportInProgress(it)) }
setState(Ready)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment