blob: 58e991b11cc9ed5faa385fd73ba8dfb2f3ad7a4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
module Js = Js_of_ocaml.Js
module App = Editor_app
module M = struct
type t = Forms.Add_page.t
let key_of_title : Jstr.t -> Jstr.t = fun title -> title
let process : t -> State.t -> State.t =
fun { title } state ->
let page_id = key_of_title title in
State.new_page ~title (Some page_id) state
end
(** Create a new element *)
let create : unit -> App.event Note.event =
fun () ->
let title = Jstr.v "Nouvelle page" in
let form = Forms.Add_page.create () in
let valid_on =
Note.S.map
(fun Forms.Add_page.{ title } -> not @@ Jstr.equal Jstr.empty title)
(fst form)
in
let ev = Elements.Popup.create ~title ~form ~valid_on () in
Note.E.map
(fun v -> App.dispatch (module M) v)
(* Option.on_some trigger the event only when the pop up is validated.
Closing the popup doesn't do anything.
*)
(Note.E.Option.on_some ev)
|