aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/reading/component/Index.scala
blob: 8c2fdd602c5e3a654d4807b076ff0735f2335247 (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
package reading.component

import rx._
import Ctx.Owner.Unsafe._

import scalatags.JsDom.all._
import scalacss.Defaults._
import scalacss.ScalatagsCss._

import reading.Books
import reading.component.style.{ Index => IndexStyle }
import reading.component.index.{ FiltersMenu, Filters, Books => BooksComponent }
import reading.models.{ Book, Filter }
import reading.utils.RxTag

object Index {
  def apply(initialFilters: Seq[Filter]): HtmlTag = {
    val filters: Var[Seq[Filter]] = Var(initialFilters)
    val books: Rx[Seq[Book]] = Rx {
      if (filters().isEmpty) Books() else Book.filter(Books(), filters())
    }
    val count: Rx[Int] = Rx(books().length)

    div(
      IndexStyle.render,

      div(
        IndexStyle.header,
        RxTag { implicit context =>
          span(s"Conseils de lecture, ${count()} livre${if (count() > 1) "s" else ""}")
        }
      ),

      div(
        IndexStyle.page,
        FiltersMenu(books, filters),
        div(
          IndexStyle.main,
          Filters(filters),
          BooksComponent(books)
        )
      )
    )
  }
}