From 72e3b16bbd258e63f047392c973ba5e8f0a823c8 Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Tue, 1 Jun 2021 13:11:58 +0200 Subject: Added export button in editor --- editor/actions/export.ml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 editor/actions/export.ml (limited to 'editor/actions/export.ml') diff --git a/editor/actions/export.ml b/editor/actions/export.ml new file mode 100755 index 0000000..a97eeac --- /dev/null +++ b/editor/actions/export.ml @@ -0,0 +1,46 @@ +module Js = Js_of_ocaml.Js + +module M = struct + + type t = unit + + let update + : t -> State.t -> State.t + = fun _ state -> + + (* Save this as a json element. The text may contains UTF-16 characters, + which will raise an error in the btoa function. + + As an easy solution, we convert them into UTF-8 through the native + OCaml representation of string. + *) + let json = State.Storage.to_json () + |> Jstr.to_string (* Encode into UTF-8 *) + |> Obj.magic (* Then type the element again as a string. *) + in + Elements.Transfert.send + ~mime_type:(Jstr.v "application/json") + ~filename:(Jstr.v "export.json") + json; + + (* The function does not actually update the state, and return it + unchanged *) + state + +end + +(** Create a new element *) +let create + : unit -> State.event Note.event + = fun () -> + let title = Jstr.v "Confirmation" + and message = Jstr.v "Exporter les notes" in + let ev = Elements.Popup.create + ~title + ~form:(Some (Forms.Validation.create message )) + in + Note.E.map + (fun v -> State.E + ( v + , (module M : State.Event with type t = M.t ))) + (Note.E.Option.on_some ev) -- cgit v1.2.3