summaryrefslogtreecommitdiff
path: root/editor/forms
diff options
context:
space:
mode:
Diffstat (limited to 'editor/forms')
-rwxr-xr-xeditor/forms/selector.ml63
1 files changed, 55 insertions, 8 deletions
diff --git a/editor/forms/selector.ml b/editor/forms/selector.ml
index de11499..d4e4795 100755
--- a/editor/forms/selector.ml
+++ b/editor/forms/selector.ml
@@ -1,16 +1,63 @@
+open Brr
+
type file = Elements.Input.file
-type t = file option
+
+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 * Brr.El.t
+ : unit -> t Note.signal * El.t
= fun () ->
- let add_file_event, i = Elements.Input.file_loader
- (Jstr.v ".json") in
+ 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.hold
- None
- (Note.E.map (fun v -> Some v) add_file_event)
+ let state = Note.S.accum
+ init
+ update_event
in
( state
- , i )
+ , El.div
+ [ i
+ ; El.div
+ [ checkbox
+ ; label ]
+ ])