blob: 66d44232db4736549cc18cf731bfce4049ee4203 (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
|
package reading.component.index
import rx._
import Ctx.Owner.Unsafe._
import scalatags.JsDom.all._
import scalacss.Defaults._
import scalacss.ScalatagsCss._
import reading.component.index.style.{ Books => BooksStyle }
import reading.component.widget.Popup
import reading.models.{ Book }
import reading.utils.{ RxTag, RxAttr }
object Books {
def apply(books: Rx[Seq[Book]]): Frag = {
val focus: Var[Option[Book]] = Var(None)
div(
BooksStyle.render,
RxTag { implicit context =>
div(
div(
BooksStyle.books,
books().sorted.map { book =>
div(
BooksStyle.book,
img(
BooksStyle.cover,
src := s"cover/${book.title}.jpg",
alt := s"${book.title}, ${book.author}",
RxAttr(onclick, Rx(() => focus() = Some(book)))
)
)
}
),
RxTag { implicit context =>
focus() match {
case Some(book) => Popup(onClose = focus() = None)(BookDetail(book))
case None => span("")
}
}
)
}
)
}
}
|