Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TEMPLATE_NAME := none.pgocaml
SERVER_PACKAGES := calendar
SERVER_PPX_PACKAGES := js_of_ocaml-ppx_deriving_json
# OCamlfind packages for the client
CLIENT_PACKAGES := calendar js_of_ocaml js_of_ocaml-lwt
CLIENT_PACKAGES := calendar js_of_ocaml js_of_ocaml-eio
CLIENT_PPX_PACKAGES := js_of_ocaml-ppx js_of_ocaml-ppx_deriving_json

# Debug package (yes/no): Debugging info in compilation
Expand Down
8 changes: 3 additions & 5 deletions src/widgets/ot_buttons.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

open Eliom_content.Html
open Eliom_content.Html.F

[%%client open Js_of_ocaml_lwt]
open%client Js_of_ocaml_eio

let%shared dropdown ?(a = []) ~menu content =
let dropdown =
Expand All @@ -16,8 +15,7 @@ let%shared dropdown ?(a = []) ~menu content =
(* the following does nothing, but still fixes hover anomalies on iPad *)
ignore
[%client
(Lwt.async @@ fun () ->
Lwt_js_events.clicks (To_dom.of_element ~%dropdown) (fun ev _ ->
Lwt.return_unit)
(Eliom_lib.fork @@ fun () ->
Eio_js_events.clicks (To_dom.of_element ~%dropdown) (fun ev -> ())
: _)];
dropdown
64 changes: 31 additions & 33 deletions src/widgets/ot_calendar.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ type button_labels =

[%%client.start]

open Lwt.Syntax
open Js_of_ocaml
open Js_of_ocaml_lwt
open Js_of_ocaml_eio

let default_intl =
{ i_days = ["S"; "M"; "T"; "W"; "T"; "F"; "S"]
Expand Down Expand Up @@ -178,12 +177,20 @@ let zeroth_displayed_day ~intl d =
then o
else CalendarLib.Date.prev o `Week

let select_action ?(size = 1) selector action =
let select_action
?(size = 1)
selector
(action :
?cancel_handler:bool
-> ?use_capture:bool
-> ?passive:bool
-> 'a
-> ('b -> unit)
-> unit)
=
let dom_select = Eliom_content.Html.To_dom.of_select selector in
Lwt.async (fun () ->
action dom_select (fun _ _ ->
dom_select##.size := size;
Lwt.return_unit))
Eliom_lib.fork (fun () ->
action dom_select (fun _ -> dom_select##.size := size))

let rec build_calendar
?prehilight
Expand Down Expand Up @@ -227,7 +234,7 @@ let rec build_calendar
else option ~a:[a_value y] (txt y)))
in
let () =
let open Lwt_js_events in
let open Eio_js_events in
let size = 10 in
select_action select_year mousedowns ~size;
select_action select_year changes;
Expand Down Expand Up @@ -356,19 +363,15 @@ let attach_events
and y = CalendarLib.Calendar.Date.year d in
let action =
match action with
| Some action ->
fun _ r ->
update_classes cal zero d;
let* _ = action y m dom in
Lwt.return_unit
| None -> fun _ r -> update_classes cal zero d; Lwt.return_unit
| Some action -> fun _ -> update_classes cal zero d; action y m dom
| None -> fun _ -> update_classes cal zero d
in
let set_onclick () =
if in_period d ~begin_p:period.begin_p ~end_p:period.end_p
then
let f () = Lwt_js_events.clicks c action in
Lwt.async f
else Lwt.async (fun () -> Lwt.return_unit)
let f () = Eio_js_events.clicks c action in
Eliom_lib.fork f
else ()
in
if List.exists (( = ) dom) highlight
then (
Expand All @@ -378,7 +381,7 @@ let attach_events
then set_onclick ()
else ()

let attach_events_lwt
let attach_events_async
?action
?click_non_highlighted
~intl
Expand All @@ -390,11 +393,10 @@ let attach_events_lwt
let f () =
let m = CalendarLib.Date.(month d |> int_of_month)
and y = CalendarLib.Date.year d in
let* highlight = highlight y m in
attach_events ?action ?click_non_highlighted ~intl ~period d cal highlight;
Lwt.return_unit
let highlight = highlight y m in
attach_events ?action ?click_non_highlighted ~intl ~period d cal highlight
in
Lwt.async f
Eliom_lib.fork f

let make_span_handler
selector
Expand Down Expand Up @@ -444,7 +446,7 @@ let attach_behavior
=
(match highlight with
| Some highlight ->
attach_events_lwt ?click_non_highlighted ?action ~intl ~period d cal
attach_events_async ?click_non_highlighted ?action ~intl ~period d cal
highlight
| None -> attach_events ?click_non_highlighted ?action ~intl ~period d cal []);
let s_y = To_dom.of_select select_year in
Expand Down Expand Up @@ -503,10 +505,10 @@ let attach_behavior

let make :
?init:int * int * int
-> ?highlight:(int -> int -> int list Lwt.t)
-> ?highlight:(int -> int -> int list)
-> ?click_non_highlighted:bool
-> ?update:(int * int * int) React.E.t
-> ?action:(int -> int -> int -> unit Lwt.t)
-> ?action:(int -> int -> int -> unit)
-> ?period:
CalendarLib.Date.field CalendarLib.Date.date
* CalendarLib.Date.field CalendarLib.Date.date
Expand Down Expand Up @@ -551,7 +553,7 @@ let make :
let f (y, m, d) =
CalendarLib.Date.make_year_month y m |> f_d_ym;
match action with
| Some action -> Lwt.async (fun () -> action y m d)
| Some action -> Eliom_lib.fork (fun () -> action y m d)
| None -> ()
in
Eliom_lib.Dom_reference.retain (To_dom.of_element elt)
Expand All @@ -561,10 +563,10 @@ let make :

let%server make :
?init:int * int * int
-> ?highlight:(int -> int -> int list Lwt.t) Eliom_client_value.t
-> ?highlight:(int -> int -> int list) Eliom_client_value.t
-> ?click_non_highlighted:bool
-> ?update:(int * int * int) React.E.t Eliom_client_value.t
-> ?action:(int -> int -> int -> unit Lwt.t) Eliom_client_value.t
-> ?action:(int -> int -> int -> unit) Eliom_client_value.t
-> ?period:
CalendarLib.Date.field CalendarLib.Date.date
* CalendarLib.Date.field CalendarLib.Date.date
Expand Down Expand Up @@ -599,11 +601,7 @@ let%shared make_date_picker ?init ?update ?button_labels ?intl ?period () =
CalendarLib.Date.(year d, month d |> int_of_month, day_of_month d)
in
let v, f = Eliom_shared.React.S.create init in
let action =
[%client
fun y m d ->
~%f (y, m, d);
Lwt.return_unit]
let action = [%client fun y m d -> ~%f (y, m, d)]
and click_non_highlighted = true in
let d =
make ~init ~click_non_highlighted ?update ?button_labels ?intl ?period
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ot_calendar.eliomi
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type button_labels =

val make :
?init:int * int * int
-> ?highlight:(int -> int -> int list Lwt.t) Eliom_client_value.t
-> ?highlight:(int -> int -> int list) Eliom_client_value.t
-> ?click_non_highlighted:bool
-> ?update:(int * int * int) React.E.t Eliom_client_value.t
-> ?action:(int -> int -> int -> unit Lwt.t) Eliom_client_value.t
-> ?action:(int -> int -> int -> unit) Eliom_client_value.t
-> ?period:
CalendarLib.Date.field CalendarLib.Date.date
* CalendarLib.Date.field CalendarLib.Date.date
Expand Down
Loading
Loading