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 ] ])