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/actions | |
parent | f6a1a4f2f44e0af679467620f89d0732021cf934 (diff) |
Editor : on import, preserve the newest notes
Diffstat (limited to 'editor/actions')
-rwxr-xr-x | editor/actions/import.ml | 31 |
1 files changed, 27 insertions, 4 deletions
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 |