aboutsummaryrefslogtreecommitdiff
path: root/editor/forms/selector.ml
blob: d4e4795d8b98d6dd75acd626184a19f04af0941a (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
51
52
53
54
55
56
57
58
59
60
61
62
63
open Brr

type file = Elements.Input.file

type t =
  { file : file option
  ; preserve_newest : bool
  }

let update
  : 'a -> t -> t
  = fun event state ->
    match event with
    | `Add_file v -> {state with file = Some v}
    | `Check v -> { state with preserve_newest = v}

let create
  : unit -> t Note.signal * El.t
  = fun () ->

    let i, add_file_event = Elements.Input.file_loader
        (Jstr.v ".json")

    and checkbox = El.input ()
        ~at:(At.
               [ type' (Jstr.v "checkbox")
               ; id (Jstr.v "check_date")
               ; checked
               ])

    and label = El.label
        ~at:(At.[
            for' (Jstr.v "check_date")
          ])
        [El.txt' "Conserver les notes plus récentes"] in

    let check_event = Brr_note.Evr.on_el
        Brr.Ev.change
        (fun _ -> `Check (El.prop (El.Prop.checked) checkbox))
        checkbox in

    let init =
      { file = None
      ; preserve_newest = true} in

    let update_event =
      (Note.E.map update)
        (Note.E.select
           [ Note.E.map (fun v -> `Add_file v) add_file_event
           ; check_event
           ]) in

    let state = Note.S.accum
        init
        update_event
    in
    ( state
    , El.div
        [ i
        ; El.div
            [ checkbox
            ; label ]
        ])