module Js = Js_of_ocaml.Js module App = Editor_app let uncheck_import ~previous ~update = let _ = previous and _ = update in true let check_import ~previous ~update = Js.Opt.case previous##.date (fun () -> true) (fun previous_date -> Js.Opt.case update##.date (fun () -> true) (fun update_date -> update_date >= previous_date) ) module M = struct type t = Forms.Selector.t let process : t -> State.t -> State.t = fun t state -> match t.Forms.Selector.file with | None -> state | Some file -> let content = file.Elements.Input.content in let check = if t.Forms.Selector.preserve_newest then check_import else uncheck_import in ( match State.Storage.of_json ~check content with | Error _ -> state | Ok _obj -> State.load_page state.State.page_id state ) end let create () = let title = Jstr.v "Importer des notes" in let form = Forms.Selector.create () in let ev = Elements.Popup.create ~title ~form ~valid_on: (Note.S.map (fun form -> form.Forms.Selector.file != None) (fst form)) () in Note.E.map (fun v -> App.dispatch (module M) v) (Note.E.Option.on_some ev)