diff --git a/assets/src/components/detours/diversionPage.tsx b/assets/src/components/detours/diversionPage.tsx index 7e2839f31..bd12128c8 100644 --- a/assets/src/components/detours/diversionPage.tsx +++ b/assets/src/components/detours/diversionPage.tsx @@ -177,9 +177,226 @@ export const DiversionPage = ({ } } + const detourPanel = () => { + if (snapshot.matches({ "Detour Drawing": "Pick Route Pattern" })) { + return ( + { + if (route) { + send({ + type: "detour.route-pattern.select-route", + route, + }) + } else { + send({ + type: "detour.route-pattern.delete-route", + }) + } + }} + onSelectRoutePattern={(routePattern) => { + routePattern && + send({ + type: "detour.route-pattern.select-pattern", + routePattern, + }) + }} + onConfirm={() => send({ type: "detour.route-pattern.done" })} + /> + ) + } else if ( + snapshot.matches({ "Detour Drawing": "Editing" }) && + routePattern + ) { + return ( + send({ type: "detour.route-pattern.open" })} + /> + ) + } else if ( + snapshot.matches({ "Detour Drawing": "Share Detour" }) && + editDetour + ) { + return ( + { + send({ type: "detour.share.open-activate-modal" }) + } + : undefined + } + > + {snapshot.matches({ + "Detour Drawing": { + "Share Detour": "Activating", + }, + }) ? ( + { + send({ type: "detour.share.activate-modal.cancel" }) + }} + onBack={ + snapshot.can({ type: "detour.share.activate-modal.back" }) + ? () => { + send({ type: "detour.share.activate-modal.back" }) + } + : undefined + } + onNext={ + snapshot.can({ type: "detour.share.activate-modal.next" }) + ? () => { + send({ type: "detour.share.activate-modal.next" }) + } + : undefined + } + onActivate={ + snapshot.can({ + type: "detour.share.activate-modal.activate", + }) + ? () => { + send({ type: "detour.share.activate-modal.activate" }) + } + : undefined + } + > + {snapshot.matches({ + "Detour Drawing": { + "Share Detour": { Activating: "Selecting Duration" }, + }, + }) ? ( + { + send({ + type: "detour.share.activate-modal.select-duration", + duration: selectedDuration, + }) + }} + selectedDuration={selectedDuration} + /> + ) : snapshot.matches({ + "Detour Drawing": { + "Share Detour": { Activating: "Selecting Reason" }, + }, + }) ? ( + { + send({ + type: "detour.share.activate-modal.select-reason", + reason: selectedReason, + }) + }} + selectedReason={selectedReason} + /> + ) : snapshot.matches({ + "Detour Drawing": { + "Share Detour": { Activating: "Confirming" }, + }, + }) ? ( + + ) : null} + + ) : null} + + ) + } else if (snapshot.matches({ "Detour Drawing": "Active" })) { + return ( + { + send({ type: "detour.active.open-deactivate-modal" }) + } + : undefined + } + > + {snapshot.matches({ + "Detour Drawing": { Active: "Deactivating" }, + }) ? ( + + send({ type: "detour.active.deactivate-modal.deactivate" }) + } + onCancel={() => + send({ type: "detour.active.deactivate-modal.cancel" }) + } + routeName={routeName || "??"} + routeDescription={routeDescription || "??"} + routeOrigin={routeOrigin || "??"} + routeDirection={routeDirection || "??"} + /> + ) : null} + + ) + } else if (snapshot.matches({ "Detour Drawing": "Past" })) { + return ( + + ) + } else { + return <> + } + } + return ( <> -
+
- {"snapshot" in useDetourProps ? ( + {"snapshot" in useDetourProps && ( <> @@ -203,7 +420,7 @@ export const DiversionPage = ({ {useDetourProps.author} - ) : null} + )}
@@ -216,204 +433,7 @@ export const DiversionPage = ({ : "text-bg-light", ])} > - {snapshot.matches({ "Detour Drawing": "Pick Route Pattern" }) ? ( - { - if (route) { - send({ - type: "detour.route-pattern.select-route", - route, - }) - } else { - send({ - type: "detour.route-pattern.delete-route", - }) - } - }} - onSelectRoutePattern={(routePattern) => { - routePattern && - send({ - type: "detour.route-pattern.select-pattern", - routePattern, - }) - }} - onConfirm={() => send({ type: "detour.route-pattern.done" })} - /> - ) : snapshot.matches({ "Detour Drawing": "Editing" }) && - routePattern ? ( - send({ type: "detour.route-pattern.open" })} - /> - ) : snapshot.matches({ "Detour Drawing": "Share Detour" }) && - editDetour ? ( - { - send({ type: "detour.share.open-activate-modal" }) - } - : undefined - } - > - {snapshot.matches({ - "Detour Drawing": { - "Share Detour": "Activating", - }, - }) ? ( - { - send({ type: "detour.share.activate-modal.cancel" }) - }} - onBack={ - snapshot.can({ type: "detour.share.activate-modal.back" }) - ? () => { - send({ type: "detour.share.activate-modal.back" }) - } - : undefined - } - onNext={ - snapshot.can({ type: "detour.share.activate-modal.next" }) - ? () => { - send({ type: "detour.share.activate-modal.next" }) - } - : undefined - } - onActivate={ - snapshot.can({ - type: "detour.share.activate-modal.activate", - }) - ? () => { - send({ type: "detour.share.activate-modal.activate" }) - } - : undefined - } - > - {snapshot.matches({ - "Detour Drawing": { - "Share Detour": { Activating: "Selecting Duration" }, - }, - }) ? ( - { - send({ - type: "detour.share.activate-modal.select-duration", - duration: selectedDuration, - }) - }} - selectedDuration={selectedDuration} - /> - ) : snapshot.matches({ - "Detour Drawing": { - "Share Detour": { Activating: "Selecting Reason" }, - }, - }) ? ( - { - send({ - type: "detour.share.activate-modal.select-reason", - reason: selectedReason, - }) - }} - selectedReason={selectedReason} - /> - ) : snapshot.matches({ - "Detour Drawing": { - "Share Detour": { Activating: "Confirming" }, - }, - }) ? ( - - ) : null} - - ) : null} - - ) : snapshot.matches({ "Detour Drawing": "Active" }) ? ( - { - send({ type: "detour.active.open-deactivate-modal" }) - } - : undefined - } - > - {snapshot.matches({ - "Detour Drawing": { Active: "Deactivating" }, - }) ? ( - - send({ type: "detour.active.deactivate-modal.deactivate" }) - } - onCancel={() => - send({ type: "detour.active.deactivate-modal.cancel" }) - } - routeName={routeName || "??"} - routeDescription={routeDescription || "??"} - routeOrigin={routeOrigin || "??"} - routeDirection={routeDirection || "??"} - /> - ) : null} - - ) : snapshot.matches({ "Detour Drawing": "Past" }) ? ( - - ) : null} + {detourPanel()}
{snapshot.matches({ "Detour Drawing": "Share Detour" }) && (