summaryrefslogtreecommitdiff
path: root/editor/editor.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2022-02-07 16:03:16 +0100
committerSébastien Dailly <sebastien@dailly.me>2022-02-07 16:43:33 +0100
commit7c23b96ce5634550341b9554eda9d7c89a79e3c0 (patch)
treeda92baed0962717a882aa31e269243fba66ce0b3 /editor/editor.ml
parent896bfb14fa05cf07bb57216fdccd678e027bc4f9 (diff)
Update editor
Diffstat (limited to 'editor/editor.ml')
-rwxr-xr-xeditor/editor.ml48
1 files changed, 45 insertions, 3 deletions
diff --git a/editor/editor.ml b/editor/editor.ml
index 1c2b8a5..c3cad1e 100755
--- a/editor/editor.ml
+++ b/editor/editor.ml
@@ -1,6 +1,46 @@
-open Js_of_ocaml
+open StdLabels
open Brr
module PM = Prosemirror
+module Js = Js_of_ocaml.Js
+
+let populate_menu () =
+ match Blog.Sidebar.get () with
+ | None -> ()
+ | Some element ->
+ let () = Blog.Sidebar.clean element in
+ let uri = Brr.Window.location Brr.G.window in
+
+ let pages =
+
+ List.map (Storage.get_ids ())
+ ~f:(fun name ->
+ let target =
+ Jstr.( (Brr.Uri.path uri)
+ + (Jstr.v "?page=")
+ + name) in
+ El.li
+ [ El.a
+ ~at:[At.href target]
+ [ El.txt name ] ]
+ ) in
+
+ let childs =
+ [ El.button
+ ~at:At.[class' (Jstr.v "action-button")]
+ [ El.i
+ []
+ ~at:At.[ class' (Jstr.v "fa")
+ ; class' (Jstr.v "fa-2x")
+ ; class' (Jstr.v "fa-times-circle")
+ ]
+ ]
+ ; El.hr ()
+ ; El.ul
+ pages
+ ] in
+
+ El.append_children element childs
+
let prosemirror id content =
begin match (Jv.is_none id), (Jv.is_none content) with
@@ -22,8 +62,10 @@ let prosemirror id content =
None in
let mySchema = PM.Model.schema pm specs in
+ populate_menu ();
+
(* Create the initial state *)
- let state = Storage.load pm mySchema content in
+ let state = Storage.load pm mySchema (Jv.Id.of_jv content) Storage.page_id in
let props = PM.View.direct_editor_props () in
props##.state := state;
@@ -47,7 +89,7 @@ let prosemirror id content =
(* Attach an event on focus out *)
let _ = Brr_note.Evr.on_el
(Ev.focusout)
- (fun _ -> Storage.save view)
+ (fun _ -> Storage.save view Storage.page_id)
(Jv.Id.of_jv id) in
()