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)