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

Clean code up

parent 2085d71e
No related branches found
No related tags found
No related merge requests found
Pipeline #30550 passed
import androidx.compose.runtime.*
import gapi.initGapi
import gapi.loadGapi
import kotlinx.browser.document
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.jetbrains.compose.web.attributes.disabled
import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.renderComposable
import processing.format
import ui.*
import ui.State
val thingsToTry = listOf(
{ replaceTitle() },
{ pontozas() },
)
fun main() {
pontozas()
thingsToTry.forEach {
try {
it()
} catch (_: dynamic) {}
}
}
fun replaceTitle() {
document.title = document.title.replace("PéK", "PéK \uD83D\uDC68\u200D\uD83C\uDF73")
}
......@@ -7,24 +7,18 @@ import org.w3c.dom.Element
import org.w3c.dom.HTMLInputElement
import org.w3c.dom.HTMLTableElement
fun getPeople() =
object PekTable {
val people get() =
document.querySelectorAll("#name-list > li > a")
.toList()
.map { it.textContent!! }
fun getPrinciples() =
val principles get() =
document.querySelector("#points-table > tbody > tr")!!
.querySelectorAll("td > div > span.tooltiptext")
.toList()
.map { it.textContent!!.trimAsPrinciple() }
object PekTable {
val people by lazy { getPeople() }
val principles by lazy { getPrinciples() }
private val tableElem = document.querySelector("#points-table") as HTMLTableElement
private val table by lazy {
private val table get() =
document.querySelectorAll("#points-table > tbody > tr")
.toList()
.map {
......@@ -32,7 +26,6 @@ object PekTable {
.querySelectorAll("td > div > input")
.toList()
}
}
operator fun get(person: String, principle: String): Int {
val pers = people.indexOf(person)
......
......@@ -50,20 +50,11 @@ fun String.trimAsPrinciple(): String {
return ret.trim()
}
fun NodeList.toList(): List<Node> {
val ret = mutableListOf<Node>()
for (i in 0 until this.length) {
val elem = this[i]
elem?.let {
ret.add(it)
}
}
return ret
}
fun NodeList.toList(): List<Node> = List(length) { i -> this[i] }.filterNotNull()
fun Node.trigger() {
val event = document.createEvent("HTMLEvents")
event.initEvent("change", false, true)
event.initEvent("change", bubbles = false, cancelable = true)
this.dispatchEvent(event)
}
......@@ -93,3 +84,17 @@ suspend fun PekTable.clear(
}
}
}
fun showComments() {
val h3 = document.querySelector("#comment-accordion > h3.uk-accordion-title")
val div = document.querySelector("""#comment-accordion > div[data-wrapper="true"]""") as? HTMLDivElement
if (h3 == null || div == null) {
return
}
h3.classList.add("uk-active")
div.style.height = "auto"
div.style.overflowX = ""
div.style.overflowY = ""
div.setAttribute("aria-expanded", "true")
}
\ No newline at end of file
......@@ -23,8 +23,6 @@ fun pontozas() {
fixNameSpacing()
document.title = document.title.replace("PéK", "PéK \uD83D\uDC68\u200D\uD83C\uDF73")
renderComposable(root = rootDiv) {
var google by remember { mutableStateOf(false) }
var state by remember { mutableStateOf<State>(Ready) }
......
......@@ -6,6 +6,7 @@ import kotlinx.coroutines.delay
import pekstuff.PekDelay
import pekstuff.PekNote
import pekstuff.PekTable
import pekstuff.showComments
import kotlin.math.max
class ProcessingError(private val errors: List<String>): Exception(errors.toString()) {
......@@ -18,9 +19,10 @@ class ProcessingError(private val errors: List<String>): Exception(errors.toStri
suspend fun DataSource.process(
progress: (Double) -> Unit = {}
) {
// todo show comment stuff
progress(0.0)
showComments()
val principleMappings = principles.associateWith {
PekTable.principles.findClosestMatch(it)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment