diff options
Diffstat (limited to 'src/main/scala/reading/component/index/Books.scala')
-rw-r--r-- | src/main/scala/reading/component/index/Books.scala | 61 |
1 files changed, 20 insertions, 41 deletions
diff --git a/src/main/scala/reading/component/index/Books.scala b/src/main/scala/reading/component/index/Books.scala index ed6265b..50a05a9 100644 --- a/src/main/scala/reading/component/index/Books.scala +++ b/src/main/scala/reading/component/index/Books.scala @@ -1,70 +1,49 @@ 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.models.{ Book, Program } -import reading.utils.RxTag +import reading.component.widget.Popup +import reading.models.{ Book => BookModel } +import reading.utils.{ RxTag, RxAttr } object Books { - def apply(books: Rx[Seq[Book]]): Frag = + def apply(books: Rx[Seq[BookModel]]): Frag = { + val focus: Var[Option[BookModel]] = Var(None) + div( BooksStyle.render, RxTag { implicit context => div( div( - BooksStyle.count, - s"${books().length} livres" - ), - - div( BooksStyle.books, books().sorted.map { book => div( BooksStyle.book, - div(BooksStyle.title, book.title), - div(BooksStyle.author, s", ${book.author}"), - div( - BooksStyle.detail, - img( - BooksStyle.cover, - src := s"cover/${book.title}.jpg" - ), - div( - if (book.programs.nonEmpty) { - div( - item("classe", book.programs.map(Program.grade(_).prettyPrint).distinct.sorted.mkString(", ")), - item("programme", book.programs.map(p => "« " ++ p.prettyPrint ++ " »").sorted.mkString(", ")) - ) - }, - if (book.themes.nonEmpty) { - item("thème", book.themes.sorted.map(_.prettyPrint).mkString(", ")) - }, - if (book.genres.nonEmpty) { - item("genre", book.genres.sorted.map(_.prettyPrint).mkString(", ")) - }, - book.period.map { period => - item("période", period.prettyPrint) - } - ) + img( + BooksStyle.cover, + src := s"cover/${book.title}.jpg", + RxAttr(onclick, Rx(() => focus() = Some(book))) ) ) } - ) + ), + + RxTag { implicit context => + focus() match { + case Some(book) => Popup(onClose = focus() = None)(Book(book)) + case None => span("") + } + } ) } ) - - def item(key: String, value: String): Frag = - div( - BooksStyle.item, - span(BooksStyle.itemKey, key), - span(BooksStyle.itemValue, value) - ) + } } |