diff options
author | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:14:09 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | bf94695abeda0d7bb296ae4cd0f9a53782587d4a (patch) | |
tree | 06dac432cfaa57dc6ad428b116332fdf777c84d8 /editor/forms | |
parent | 4d35508a76676a548ac45e0bff2d63eafaf014e2 (diff) |
Update editor organisation
Diffstat (limited to 'editor/forms')
-rwxr-xr-x | editor/forms/add_page.ml | 22 | ||||
-rwxr-xr-x | editor/forms/add_page.mli | 6 | ||||
-rwxr-xr-x | editor/forms/delete_page.ml | 10 | ||||
-rwxr-xr-x | editor/forms/dune | 1 | ||||
-rwxr-xr-x | editor/forms/events.ml | 17 |
5 files changed, 52 insertions, 4 deletions
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 + |