summaryrefslogtreecommitdiff
path: root/editor/app.ml
diff options
context:
space:
mode:
Diffstat (limited to 'editor/app.ml')
-rwxr-xr-xeditor/app.ml50
1 files changed, 23 insertions, 27 deletions
diff --git a/editor/app.ml b/editor/app.ml
index 219ce80..4559044 100755
--- a/editor/app.ml
+++ b/editor/app.ml
@@ -2,11 +2,10 @@ open Brr
module Js = Js_of_ocaml.Js
type events =
- | DeleteEvent
| StoreEvent
| LoadEvent of Jstr.t option
- | AddEvent
| ClosePopup of Forms.Events.event option
+ | Generic of Actions.Event.t
let key_of_title
: Jstr.t -> Jstr.t
@@ -18,41 +17,27 @@ let key_of_title
The function take a new event, and apply it to the current state. *)
let update
- : Forms.Events.event option Note.E.send -> (events, State.t) Application.t
- = fun close_sender event state ->
+ : (events, State.t) Application.t
+ = fun event state ->
match event with
+ | Generic (E (t, (module EventHandler))) ->
+ EventHandler.apply t state
+
+
| ClosePopup result ->
+ (* First close the last popin. *)
let state = match state.window with
| [] -> { state with window = [] }
| el::tl -> El.remove el
; { state with window = tl } in
+ (* Call the handler associated with the event *)
begin match result with
| None -> state
| Some (Event (t, (module Handler))) ->
Handler.on_close t state
end
- | AddEvent ->
- let title = Jstr.v "Nouvelle page" in
- let popup = Ui.popup
- ~title
- ~form:(Some (Forms.Add_page.create ()))
- close_sender in
- { state with window = popup::state.window}
-
- | DeleteEvent ->
- begin match state.page_id with
- | None -> state
- | Some page_id ->
- let title = Jstr.v "Confirmation" in
- let popup = Ui.popup
- ~title
- ~form:(Some (Forms.Delete_page.create page_id))
- close_sender in
- { state with window = popup::state.window}
- end
-
| StoreEvent ->
let title_element = Document.find_el_by_id G.document (Jstr.v "title") in
@@ -80,12 +65,23 @@ let update
- more recent (if the content has been updated elsewhere)
but older shoud be a bug. *)
- date <= state.last_backup)) in
+ let is_ok = date <= state.last_backup in
+ if (not is_ok) then (
+ let open Console in
+ log
+ [ Jstr.v "Last backup date is "
+ ; new%js Js.date_fromTimeValue state.last_backup
+ ; Jstr.v " but date is "
+ ; new%js Js.date_fromTimeValue date] );
+ is_ok)) in
begin match save with
| Ok true -> { state with last_backup = new_date }
- | other ->
+ | Ok false ->
+ Console.(log [Jstr.v "Didn't save"]);
+ state
+ | Error other ->
(* TODO In case of error, notify the user *)
- Console.(log [other]);
+ Console.(log [Jstr.v "Couldn't save" ; other]);
state
end