From fe2cced55e1b44dbae57e55fe0f459c85e7369cb Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Mon, 7 Feb 2022 16:21:26 +0100 Subject: Application unification --- editor/actions/actions.ml | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'editor/actions/actions.ml') diff --git a/editor/actions/actions.ml b/editor/actions/actions.ml index e8b4d71..b150279 100755 --- a/editor/actions/actions.ml +++ b/editor/actions/actions.ml @@ -7,16 +7,17 @@ module Event = Event type button_actions = { delete : Event.t Note.event - ; redirect : Jstr.t option Note.event + ; redirect : Event.t Note.event ; add: Event.t Note.event } let populate_menu - : Forms.Events.event option Note.E.send -> button_actions option - = fun sender -> + : unit -> button_actions option + = fun () -> match Blog.Sidebar.get () with | None -> None | Some element -> + let () = Blog.Sidebar.clean element in let delete_button = El.button @@ -39,24 +40,27 @@ let populate_menu ~at:At.[ class' (Jstr.v "fa") ; class' (Jstr.v "fa-2x") ; class' (Jstr.v "fa-plus") ] ] - in + (* We are waiting for event inside another event ( form validation inside + popup creation. + + Note.E.join is used here in order to get only te popup validation. *) let delete_event = - Evr.on_el - Ev.click - (fun _ -> Event.E - ( sender - , (module Delete_page: Event.Handler with type t = Delete_page.t)) ) - delete_button + Note.E.join ( + Evr.on_el + Ev.click + (fun _ -> Delete_page.create ()) + delete_button) + (* Event on popup creation *) and add_event = - Evr.on_el - Ev.click - (fun _ -> Event.E - ( sender - , (module Add_page: Event.Handler with type t = Add_page.t)) ) - add_button in + Note.E.join ( + Evr.on_el + Ev.click + (fun _ -> Add_page.create ()) + add_button) in + let stored_pages = State.Storage.get_ids () in let pages = @@ -73,8 +77,7 @@ let populate_menu El.li [ El.a ~at:[At.href target] - [ El.txt name ] ] - ) in + [ El.txt name ] ]) in (* Wait for a click on an existing page in order to sent the associated event. @@ -82,17 +85,21 @@ let populate_menu We compose the resulting event with both : - the home button - the list for all the pages presents in the sidebar *) + + let redirect_handler = + (module Load_page.M : Event.Handler with type t = Load_page.M.t ) in + let redirect_event = Note.E.select (( Evr.on_el Ev.click - (fun _ -> None) + (fun _ -> Event.E (None, redirect_handler)) home_button ) :: ( List.map2 stored_pages pages ~f:(fun name el -> Evr.on_el Ev.click - (fun _ -> Some name) + (fun _ -> Event.E ((Some name), redirect_handler)) el ))) in let childs = -- cgit v1.2.3