From bf94695abeda0d7bb296ae4cd0f9a53782587d4a Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 16:14:09 +0100 Subject: Update editor organisation --- editor/forms/add_page.ml | 22 +++++++++++++++++++++- editor/forms/add_page.mli | 6 +++++- editor/forms/delete_page.ml | 10 +++++++++- editor/forms/dune | 1 + editor/forms/events.ml | 17 ++++++++++++++++- 5 files changed, 52 insertions(+), 4 deletions(-) (limited to 'editor/forms') diff --git a/editor/forms/add_page.ml b/editor/forms/add_page.ml index 597e9d3..ac45824 100755 --- a/editor/forms/add_page.ml +++ b/editor/forms/add_page.ml @@ -1,9 +1,12 @@ open Brr open Brr_note open Note +module Js = Js_of_ocaml.Js + +type t = { title : Jstr.t } type Events.kind += - | AddPage of { title : Jstr.t } + | AddPage of t [@@unboxed] let create : unit -> Events.t @@ -34,3 +37,20 @@ let create [ input ] ] ] ) + +let key_of_title + : Jstr.t -> Jstr.t + = fun title -> + title + +let on_close + : 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 diff --git a/editor/forms/add_page.mli b/editor/forms/add_page.mli index 97b1d6c..6be1611 100755 --- a/editor/forms/add_page.mli +++ b/editor/forms/add_page.mli @@ -1,5 +1,9 @@ +type t = { title : Jstr.t } type Events.kind += - | AddPage of { title : Jstr.t } + | AddPage of t [@@unboxed] val create : unit -> Events.t + +val on_close + : t -> State.t -> State.t diff --git a/editor/forms/delete_page.ml b/editor/forms/delete_page.ml index 701162c..3328dd7 100755 --- a/editor/forms/delete_page.ml +++ b/editor/forms/delete_page.ml @@ -1,8 +1,10 @@ open Brr open Note +type t = Jstr.t + type Events.kind += - | DeletePage of Jstr.t [@@unboxed] + | DeletePage of t [@@unboxed] let create : Jstr.t -> Events.t @@ -23,3 +25,9 @@ let create , El.txt message ) +let on_close + : t -> State.t -> State.t + = fun id state -> + State.Storage.delete (fun () -> Some id); + let json = State.Storage.load None in + State.load_page None state json diff --git a/editor/forms/dune b/editor/forms/dune index 9876654..124ce01 100755 --- a/editor/forms/dune +++ b/editor/forms/dune @@ -7,6 +7,7 @@ js_lib blog application + state ) (preprocess (pps js_of_ocaml-ppx)) ) diff --git a/editor/forms/events.ml b/editor/forms/events.ml index 339e15d..f7f5711 100755 --- a/editor/forms/events.ml +++ b/editor/forms/events.ml @@ -1,5 +1,20 @@ -(** This type is designed to be extended for each form *) +(** This type is designed to be extended for each form. + + Each of them hold the values inside the form. + +*) type kind = .. +(** The signal has to be log in order to be completely working *) type t = kind Note.signal * Brr.El.t +module type Handler = sig + + type t + + val on_close: t -> State.t -> State.t + +end + +type event = Event : 'a * (module Handler with type t = 'a) -> event + -- cgit v1.2.3