/
Client.scala
37 lines (35 loc) · 887 Bytes
/
Client.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package simple
import scalatags.JsDom.all._
import scalajs.concurrent.JSExecutionContext.Implicits.runNow
import org.scalajs.dom
import dom.html
import dom.ext.Ajax
import scalajs.js.annotation.JSExport
@JSExport
object Client extends{
@JSExport
def main(container: html.Div) = {
val inputBox = input.render
val outputBox = ul.render
def update() = Ajax.post("/ajax/list", inputBox.value).foreach{ xhr =>
val data = upickle.default.read[Seq[FileData]](xhr.responseText)
outputBox.innerHTML = ""
for(FileData(name, size) <- data){
outputBox.appendChild(
li(
b(name), " - ", size, " bytes"
).render
)
}
}
inputBox.onkeyup = (e: dom.Event) => update()
update()
container.appendChild(
div(
h1("File Search"),
inputBox,
outputBox
).render
)
}
}