summaryrefslogtreecommitdiff
path: root/editor/state/state.ml
diff options
context:
space:
mode:
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