summaryrefslogtreecommitdiff
path: root/editor/state/state.ml
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/state/state.ml
parent72e3b16bbd258e63f047392c973ba5e8f0a823c8 (diff)
Added import button in editor
Diffstat (limited to 'editor/state/state.ml')
-rwxr-xr-xeditor/state/state.ml26
1 files changed, 24 insertions, 2 deletions
diff --git a/editor/state/state.ml b/editor/state/state.ml
index 649473c..2662a48 100755
--- a/editor/state/state.ml
+++ b/editor/state/state.ml
@@ -60,8 +60,9 @@ let state_of_storage
PM.State.fromJSON pm obj page_content)
let load_page
- : Jstr.t option -> t -> Storage.content Js.t -> t
- = fun page_id state json ->
+ : Jstr.t option -> t -> t
+ = fun page_id state ->
+ let json = Storage.load page_id in
let editor_state = state_of_storage state.pm json state.view##.state##.schema in
let () = state.view##updateState editor_state
and () = set_title json in
@@ -74,6 +75,27 @@ let load_page
{ state with page_id
; last_backup }
+let new_page
+ : Jstr.t option -> title:Jstr.t -> t -> t
+ = fun page_id ~title state ->
+ 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
+ let editor_state = state_of_storage state.pm content_obj state.view##.state##.schema in
+ let () = state.view##updateState editor_state
+ and () = set_title content_obj in
+
+ let last_backup =
+ Js.Opt.case content_obj##.date
+ (fun () -> state.last_backup )
+ (fun v -> v) in
+
+ { state with page_id
+ ; last_backup }
+
let init
: PM.t -> PM.View.editor_view Js.t -> float -> Jstr.t option -> t