Summary.res.mjs
1// Generated by ReScript, PLEASE EDIT WITH CARE
2
3import * as Time from "../lib/Time.res.mjs";
4import * as Panel from "./Panel.res.mjs";
5import * as State from "../State.res.mjs";
6import * as Units from "../lib/Units.res.mjs";
7import * as Preact from "../ffi/Preact.res.mjs";
8import * as Core__Array from "@rescript/core/lib/es6/src/Core__Array.res.mjs";
9import * as Core__Option from "@rescript/core/lib/es6/src/Core__Option.res.mjs";
10import * as LucidePreact from "lucide-preact";
11import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
12import * as JsxRuntime from "preact/jsx-runtime";
13import * as Menu from "@base-ui/react/menu";
14
15function getLongestDistance(wp) {
16 let d = wp.from;
17 if (d !== undefined) {
18 return Core__Array.reduce(Object.entries(d), 0.0, (a, param) => {
19 let dist = Core__Option.getOr(param[1].d, 0.0);
20 if (dist > a) {
21 return dist;
22 } else {
23 return a;
24 }
25 });
26 } else {
27 return 0.0;
28 }
29}
30
31function getLongestTime(wp) {
32 let d = wp.from;
33 if (d !== undefined) {
34 return Core__Array.reduce(Object.entries(d), 0.0, (a, param) => {
35 let time = Core__Option.getOr(param[1].t, 0.0);
36 if (time > a) {
37 return time;
38 } else {
39 return a;
40 }
41 });
42 } else {
43 return 0.0;
44 }
45}
46
47function Summary$StatusText(props) {
48 return JsxRuntime.jsx("div", {
49 children: props.status,
50 ref: Primitive_option.some(elem => {
51 Core__Option.map((elem == null) ? undefined : Primitive_option.some(elem), elem => {
52 elem.classList.remove("md:opacity-0");
53 });
54 setTimeout(() => {
55 Core__Option.map((elem == null) ? undefined : Primitive_option.some(elem), elem => {
56 elem.classList.add("md:opacity-0");
57 });
58 }, 5000);
59 }),
60 className: "hidden md:block md:transition-opacity md:ease-in-out md:duration-1000",
61 id: props.id
62 });
63}
64
65let StatusText = {
66 make: Summary$StatusText
67};
68
69function Summary(props) {
70 let doc = props.doc;
71 let wp = State.waypoints.get(doc);
72 let distance = wp !== undefined ? Core__Array.reduce(Primitive_option.valFromOption(wp).value, 0.0, (total, wp) => total + getLongestDistance(wp)) : 0.0;
73 let wp$1 = State.waypoints.get(doc);
74 let time = wp$1 !== undefined ? Core__Array.reduce(Primitive_option.valFromOption(wp$1).value, 0.0, (total, wp) => total + getLongestTime(wp)) : 0.0;
75 let wp$2 = State.waypoints.get(doc);
76 let numPoints = wp$2 !== undefined ? Primitive_option.valFromOption(wp$2).value.length : 0;
77 let status = State.ysweetStatus.value;
78 let tmp;
79 switch (status) {
80 case "Offline" :
81 tmp = JsxRuntime.jsx(Summary$StatusText, {
82 id: "status-offline",
83 status: "Offline"
84 });
85 break;
86 case "Connecting" :
87 tmp = JsxRuntime.jsx(Summary$StatusText, {
88 id: "status-connecting",
89 status: "Connecting"
90 });
91 break;
92 case "Synced" :
93 tmp = JsxRuntime.jsx(Summary$StatusText, {
94 id: "status-synced",
95 status: "Saved"
96 });
97 break;
98 case "Saving" :
99 tmp = JsxRuntime.jsx(Summary$StatusText, {
100 id: "status-saving",
101 status: "Saving"
102 });
103 break;
104 }
105 let tmp$1;
106 switch (status) {
107 case "Offline" :
108 tmp$1 = JsxRuntime.jsx(LucidePreact.GlobeOff, {
109 size: 14,
110 strokeWidth: 3
111 });
112 break;
113 case "Connecting" :
114 tmp$1 = JsxRuntime.jsx(LucidePreact.WifiSync, {
115 size: 14,
116 strokeWidth: 3
117 });
118 break;
119 case "Synced" :
120 tmp$1 = JsxRuntime.jsx(LucidePreact.Check, {
121 size: 14,
122 strokeWidth: 4
123 });
124 break;
125 case "Saving" :
126 tmp$1 = JsxRuntime.jsx(LucidePreact.CloudUpload, {
127 size: 14,
128 strokeWidth: 3
129 });
130 break;
131 }
132 return JsxRuntime.jsx("div", {
133 children: JsxRuntime.jsxs("div", {
134 children: [
135 JsxRuntime.jsxs("div", {
136 children: [
137 JsxRuntime.jsxs("div", {
138 children: [
139 JsxRuntime.jsx("div", {
140 children: "WAYPOINTS",
141 className: "capitalize"
142 }),
143 JsxRuntime.jsx("div", {
144 children: numPoints.toFixed(),
145 className: "font-extrabold"
146 })
147 ],
148 className: "flex flex-row gap-2"
149 }),
150 JsxRuntime.jsxs("div", {
151 children: [
152 JsxRuntime.jsx("div", {
153 children: "DISTANCE",
154 className: "capitalize"
155 }),
156 JsxRuntime.jsx("div", {
157 children: Units.distance(distance, "km"),
158 className: "font-extrabold"
159 })
160 ],
161 className: "flex flex-row gap-2"
162 }),
163 JsxRuntime.jsxs("div", {
164 children: [
165 JsxRuntime.jsx("div", {
166 children: "TIME",
167 className: "capitalize"
168 }),
169 JsxRuntime.jsx("div", {
170 children: Time.humanize(time),
171 className: "font-extrabold"
172 })
173 ],
174 className: "flex flex-row gap-2"
175 })
176 ],
177 className: "flex flex-row gap-4 md:gap-8 text-xs items-center justify-start bg-paper px-4 py-2"
178 }),
179 State.readonly.value ? JsxRuntime.jsx("div", {
180 children: JsxRuntime.jsxs(Menu.Menu.Root, {
181 children: [
182 JsxRuntime.jsxs(Menu.Menu.Trigger, {
183 children: [
184 JsxRuntime.jsx(LucidePreact.Split, {
185 className: "my-auto"
186 }),
187 "Edit"
188 ],
189 className: "flex flex-row gap-1 rounded-full bg-orange"
190 }),
191 JsxRuntime.jsx(Menu.Menu.Portal, {
192 children: JsxRuntime.jsx(Menu.Menu.Positioner, {
193 align: "end",
194 side: "top",
195 children: JsxRuntime.jsx(Menu.Menu.Popup, {
196 children: JsxRuntime.jsxs(Menu.Menu.Group, {
197 children: [
198 JsxRuntime.jsx(Menu.Menu.GroupLabel, {
199 children: "This document is read-only. If you want to make changes, you can fork it to create your own editable copy."
200 }),
201 JsxRuntime.jsx(Menu.Menu.LinkItem, {
202 href: `fork/` + doc,
203 className: "",
204 children: "Fork a copy of this document"
205 })
206 ]
207 }),
208 className: "flex flex-col gap-2 w-40"
209 })
210 })
211 })
212 ]
213 }),
214 className: ""
215 }) : null,
216 JsxRuntime.jsx("div", {
217 children: JsxRuntime.jsxs("div", {
218 children: [
219 tmp,
220 JsxRuntime.jsx("div", {
221 children: tmp$1,
222 className: Preact.cls("m-auto", {
223 "text-yellow": status === "Connecting" || status === "Saving",
224 "text-green": status === "Synced",
225 "text-red": status === "Offline"
226 })
227 })
228 ],
229 className: "flex flex-row items-center justify-center gap-1 text-xs"
230 }),
231 className: "px-4 py-2"
232 })
233 ],
234 className: "flex flex-row justify-between"
235 }),
236 className: Preact.cls("fixed box-border bottom-0 left-0 w-[100cqw] rounded-sm shadow-xl", {
237 "border-t-2 border-gray-300": !Panel.isMinimized.value
238 }),
239 id: `summary-` + doc
240 });
241}
242
243let make = Summary;
244
245export {
246 getLongestDistance,
247 getLongestTime,
248 StatusText,
249 make,
250}
251/* Panel Not a pure module */