Stats.res
1@jsx.component
2let make = (~dist: Geo.result, ~time: Geo.result, ~waypoints: array<Waypoint.attributes>) => {
3 // let originLabel = switch Waypoint.getOrigin(waypoints) {
4 // | Some(origin) => origin.label
5 // | None => "origin"
6 // }
7 let getLabel = (id: string, orElse: string) => {
8 switch Waypoint.findById(waypoints, id) {
9 | Some(wp) => wp.label
10 | None => orElse
11 }
12 }
13 let previousLabel = switch dist.previousID {
14 | Some(id) => getLabel(id, "previous waypoint")
15 | None => "previous waypoint"
16 }
17 let nextLabel = switch dist.nextID {
18 | Some(id) => getLabel(id, "next waypoint")
19 | None => "next waypoint"
20 }
21 let headers = "font-bold col-span-2 flex flex-row items-center h-fit"
22 let stat = "font-mono justify-self-end h-fit leading-none"
23 <div className="grid md:grid-cols-4 grid-cols-2 items-center">
24 // from previous waypoint
25 <div className={headers}>
26 {("From " ++ previousLabel)->Preact.string}
27 //<Icons.ArrowUpFromDot className="text-blue w-4 ml-1 rotate-90" />
28 </div>
29 <div className={stat}> {dist.fromPreviousWaypoint->Units.distance(#km)->Preact.string} </div>
30 <div className={stat}> {time.fromPreviousWaypoint->Time.humanize->Preact.string} </div>
31 // to next waypoint
32 <div className={headers}>
33 //<Icons.ArrowUpFromDot className="text-blue w-4 ml-1 rotate-90" />
34 {("To " ++ nextLabel)->Preact.string}
35 </div>
36 <div className={stat}> {dist.toNextWaypoint->Units.distance(#km)->Preact.string} </div>
37 <div className={stat}> {time.toNextWaypoint->Time.humanize->Preact.string} </div>
38
39 // {if previousLabel == originLabel {
40 // <> </>
41 // } else {
42 // switch dist.fromStart {
43 // | m if m->Map.size == 0 => <> </>
44 // | m if m->Map.size == 1 => {
45 // let d =
46 // m
47 // ->Map.values
48 // ->Iterator.toArray
49 // ->Array.get(0)
50 // ->Option.getOr(0.0)
51 // ->Float.toFixed(~digits=1)
52 // let t =
53 // time.fromStart
54 // ->Map.values
55 // ->Iterator.toArray
56 // ->Array.get(0)
57 // ->Option.getOr(0.0)
58 // ->Time.humanize
59 // <>
60 // <div className={headers}>
61 // {originLabel->Preact.string}
62 // <Icons.ArrowRightFromLine className="text-blue w-4 ml-1" />
63 // </div>
64 // <div className={stat}> {(d ++ "km")->Preact.string} </div>
65 // <div className={stat}> {t->Preact.string} </div>
66 // </>
67 // }
68 // | _ =>
69 // // TODO: needs to deal with multiple routes to this point by calculating set difference
70 // // and finding a shorthand way to display it like "From <origin> via <set difference>"
71 // <> </>
72 // }
73 // }}
74 </div>
75}