diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 15:19:47 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | 179720a7f2c790ea5557bb5caabe22a926b3e106 (patch) | |
tree | eb3824ce5c82ea16d6499844ab0cb44df150ac26 /editor/forms | |
parent | f6a1a4f2f44e0af679467620f89d0732021cf934 (diff) |
Editor : on import, preserve the newest notes
Diffstat (limited to 'editor/forms')
-rwxr-xr-x | editor/forms/selector.ml | 63 |
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 ] + ]) |