aboutsummaryrefslogtreecommitdiff
path: root/editor/actions
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2022-02-07 15:27:05 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit28417d795a6922c3df3c2c0aea78a51648b0428e (patch)
tree28af6bd86e2127003855574b4c777efa1cd07207 /editor/actions
parent72e3b16bbd258e63f047392c973ba5e8f0a823c8 (diff)
Added import button in editor
Diffstat (limited to 'editor/actions')
-rwxr-xr-xeditor/actions/add_page.ml8
-rwxr-xr-xeditor/actions/delete_page.ml3
-rwxr-xr-xeditor/actions/editor_actions.ml11
-rwxr-xr-xeditor/actions/export.ml16
-rwxr-xr-xeditor/actions/import.ml31
-rwxr-xr-xeditor/actions/load_page.ml3
6 files changed, 47 insertions, 25 deletions
diff --git a/editor/actions/add_page.ml b/editor/actions/add_page.ml
index 4a3fcf3..e5e8541 100755
--- a/editor/actions/add_page.ml
+++ b/editor/actions/add_page.ml
@@ -13,13 +13,7 @@ module M = struct
: t -> State.t -> State.t
= fun {title} state ->
let page_id = key_of_title title in
- let new_date = (new%js Js.date_now)##getTime in
- let content_obj = object%js
- val content = Js.null
- val title = Js.some title
- val date = Js.some new_date
- end in
- State.load_page (Some page_id) state content_obj
+ State.new_page ~title (Some page_id) state
end
(** Create a new element *)
diff --git a/editor/actions/delete_page.ml b/editor/actions/delete_page.ml
index fb600bd..58c1d32 100755
--- a/editor/actions/delete_page.ml
+++ b/editor/actions/delete_page.ml
@@ -9,8 +9,7 @@ module M = struct
| None -> state
| Some page_id ->
State.Storage.delete (fun () -> Some page_id);
- let json = State.Storage.load None in
- State.load_page None state json
+ State.load_page None state
end
diff --git a/editor/actions/editor_actions.ml b/editor/actions/editor_actions.ml
index 8c47363..70b078b 100755
--- a/editor/actions/editor_actions.ml
+++ b/editor/actions/editor_actions.ml
@@ -72,11 +72,17 @@ let populate_menu
add_button)
and export_event =
+ Evr.on_el
+ Ev.click
+ (fun _ -> Export.create ())
+ export_button
+
+ and import_event =
Note.E.join (
Evr.on_el
Ev.click
- (fun _ -> Export.create ())
- export_button)
+ (fun _ -> Import.create ())
+ load_button)
in
@@ -147,4 +153,5 @@ let populate_menu
; redirect_event
; add_event
; export_event
+ ; import_event
])
diff --git a/editor/actions/export.ml b/editor/actions/export.ml
index a97eeac..71e3b64 100755
--- a/editor/actions/export.ml
+++ b/editor/actions/export.ml
@@ -31,16 +31,8 @@ end
(** Create a new element *)
let create
- : unit -> State.event Note.event
+ : unit -> State.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)
+ State.E
+ ( ()
+ , (module M : State.Event with type t = M.t ))
diff --git a/editor/actions/import.ml b/editor/actions/import.ml
new file mode 100755
index 0000000..fd4bef8
--- /dev/null
+++ b/editor/actions/import.ml
@@ -0,0 +1,31 @@
+module Js = Js_of_ocaml.Js
+
+module M = struct
+
+ type t = Forms.Selector.t
+
+ let update
+ : t -> State.t -> State.t
+ = fun t state ->
+ match t with
+ | None -> state
+ | Some file ->
+ (* Back to UTF-16 *)
+ let content = file.Forms.Selector.content in
+ Brr.Console.(log [content] );
+ match State.Storage.of_json 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 ev = Elements.Popup.create
+ ~title
+ ~form:(Some (Forms.Selector.create ())) in
+ Note.E.map
+ (fun v -> State.E
+ ( v
+ , (module M : State.Event with type t = M.t )))
+ (Note.E.Option.on_some ev)
diff --git a/editor/actions/load_page.ml b/editor/actions/load_page.ml
index ceee038..349eaad 100755
--- a/editor/actions/load_page.ml
+++ b/editor/actions/load_page.ml
@@ -5,8 +5,7 @@ module M = struct
let update
: t -> State.t -> State.t
= fun page_id state ->
- let json = State.Storage.load page_id in
- State.load_page page_id state json
+ State.load_page page_id state
end