From 179720a7f2c790ea5557bb5caabe22a926b3e106 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 15:19:47 +0100 Subject: Editor : on import, preserve the newest notes --- editor/actions/import.ml | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'editor/actions/import.ml') diff --git a/editor/actions/import.ml b/editor/actions/import.ml index cb0c16d..4cac76c 100755 --- a/editor/actions/import.ml +++ b/editor/actions/import.ml @@ -1,5 +1,21 @@ module Js = Js_of_ocaml.Js +let uncheck_import = + fun ~previous ~update -> + let _ = previous + and _ = update in + true + +let check_import = + fun ~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 @@ -7,13 +23,20 @@ module M = struct let update : t -> State.t -> State.t = fun t state -> - match t with + match t.Forms.Selector.file with | None -> state | Some file -> - (* Back to UTF-16 *) let content = file.Elements.Input.content in - Brr.Console.(log [content] ); - match State.Storage.of_json content with + 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 -- cgit v1.2.3