aboutsummaryrefslogtreecommitdiff
path: root/src/View
diff options
context:
space:
mode:
authorJoris2020-08-09 08:37:18 +0200
committerJoris2020-08-09 08:37:18 +0200
commitad6abcd5fc5e4e66062c8a01b511a1bd4bda2e94 (patch)
tree0dee6c63c45e34ce960ca6c445b4ee9dbdcb3087 /src/View
parent2cb752123d15916496e872c9fbd423c788c86c64 (diff)
Export as CSV
Diffstat (limited to 'src/View')
-rw-r--r--src/View/Form.ml2
-rw-r--r--src/View/Map.ml19
2 files changed, 12 insertions, 9 deletions
diff --git a/src/View/Form.ml b/src/View/Form.ml
index cc95210..53fbb7d 100644
--- a/src/View/Form.ml
+++ b/src/View/Form.ml
@@ -47,7 +47,7 @@ let color_input default_colors id label init_value on_input =
; HA.type_ "button"
|]
[| |])
- |> (fun xs -> Js.Array.concat xs [| input |]))
+ |> Fun.flip Js.Array.concat [| input |])
|]
let textarea id label init_value on_input =
diff --git a/src/View/Map.ml b/src/View/Map.ml
index eda934c..8f74b76 100644
--- a/src/View/Map.ml
+++ b/src/View/Map.ml
@@ -1,4 +1,4 @@
-let mapView =
+let mapView state =
H.div
[| HA.class_ "g-Layout__Page" |]
[| H.div
@@ -8,6 +8,9 @@ let mapView =
; HA.href "#"
|]
[| H.text "Map" |]
+ ; Button.text
+ [| HE.on_click (fun _ -> File.download "map.csv" (State.to_csv_string !state)) |]
+ [| H.text "Export" |]
|]
; H.div
[| HA.class_ "g-Map" |]
@@ -19,10 +22,9 @@ let mapView =
let state_from_hash () =
let hash = Js.String.sliceToEnd ~from:1 (Location.hash Document.location) in
- State.from_string hash
+ State.from_url_string hash
-let installMap () =
- let state = ref (state_from_hash ()) in
+let installMap state =
let map = Leaflet.map "g-Map__Content" in
let title_layer = Leaflet.title_layer "http://{s}.tile.osm.org/{z}/{x}/{y}.png" in
let markers = Leaflet.feature_group [| |] in
@@ -31,7 +33,7 @@ let installMap () =
let rec reload_from_hash focus =
let update_state new_state =
- let () = History.push_state "" "" ("#" ^ State.to_string new_state) () in
+ let () = History.push_state "" "" ("#" ^ State.to_url_string new_state) () in
reload_from_hash false
in
@@ -74,7 +76,7 @@ let installMap () =
let add_marker pos name color icon =
let new_marker = { State.pos = pos; name = name; color = color; icon = icon } in
let new_state = State.update !state pos new_marker in
- let () = History.push_state "" "" ("#" ^ State.to_string new_state) () in
+ let () = History.push_state "" "" ("#" ^ State.to_url_string new_state) () in
reload_from_hash false
in
@@ -96,5 +98,6 @@ let installMap () =
|])
let render () =
- let _ = Js.Global.setTimeout installMap 0 in
- mapView
+ let state = ref (state_from_hash ()) in
+ let _ = Js.Global.setTimeout (fun _ -> installMap state) 0 in
+ mapView state