diff options
Diffstat (limited to 'src/main/scala/reading/component/index/Book.scala')
-rw-r--r-- | src/main/scala/reading/component/index/Book.scala | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/scala/reading/component/index/Book.scala b/src/main/scala/reading/component/index/Book.scala new file mode 100644 index 0000000..ffa3c6b --- /dev/null +++ b/src/main/scala/reading/component/index/Book.scala @@ -0,0 +1,48 @@ +package reading.component.index + +import scalatags.JsDom.all._ +import scalacss.Defaults._ +import scalacss.ScalatagsCss._ + +import reading.component.index.style.{ Book => BookStyle } +import reading.models.{ Program, Book => BookModel } + +object Book { + def apply(book: BookModel): HtmlTag = + div( + BookStyle.render, + BookStyle.detail, + + img( + BookStyle.cover, + src := s"cover/${book.title}.jpg" + ), + + div( + div(BookStyle.title, book.title), + div(BookStyle.author, s", ${book.author}"), + 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) + } + ) + ) + + private def item(key: String, value: String): Frag = + div( + BookStyle.item, + span(BookStyle.itemKey, key), + span(BookStyle.itemValue, value) + ) +} |