blob: fd8bdad04a98994e2723b148f61b840fdc9c653e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
import apiConnector from "./connector.js"
export default async function initSettings(settingsPageContainer) {
const inputList = Array.from(settingsPageContainer.querySelectorAll("[name]"))
const inputs = Object.fromEntries(inputList.map(e => [e.name, e]))
const currentConfig = await apiConnector.fetchConfig()
for (const [name, value] of Object.entries(currentConfig))
if (inputs[name])
inputs[name].value = value
settingsPageContainer.querySelector("#settings-submit").addEventListener("click", e => {
e.preventDefault()
apiConnector.updateConfig(Object.fromEntries(inputList.map(el => [el.name, el.type === "number" ? parseFloat(el.value) : el.value])))
})
}
|