From 2cb4dbe0bba5cdb137c2b6c351b2921b1979ffd7 Mon Sep 17 00:00:00 2001 From: Kayla Firestack Date: Tue, 21 May 2024 17:45:24 -0400 Subject: [PATCH] cleanup(ts/hooks/useDetour): replace `state` with `snapshot` from `createDetourMachine` --- assets/src/components/detours/diversionPage.tsx | 14 +++++++------- assets/src/hooks/useDetour.ts | 13 ++----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/assets/src/components/detours/diversionPage.tsx b/assets/src/components/detours/diversionPage.tsx index e46bcbe86..5007e85a8 100644 --- a/assets/src/components/detours/diversionPage.tsx +++ b/assets/src/components/detours/diversionPage.tsx @@ -7,7 +7,7 @@ import React, { } from "react" import { DiversionPanel } from "./diversionPanel" import { DetourMap } from "./detourMap" -import { DetourState, useDetour } from "../../hooks/useDetour" +import { useDetour } from "../../hooks/useDetour" import { Alert, Button, CloseButton, Modal } from "react-bootstrap" import * as BsIcons from "../../helpers/bsIcons" import { OriginalRoute } from "../../models/detour" @@ -31,7 +31,7 @@ export const DiversionPage = ({ showConfirmCloseModal, }: DiversionPageProps) => { const { - state, + snapshot, addConnectionPoint, addWaypoint, @@ -99,7 +99,7 @@ export const DiversionPage = ({
- {state === DetourState.Edit && ( + {snapshot.matches({ "Detour Drawing": "Editing" }) ? ( - )} - {state === DetourState.Finished && editDetour && ( + ) : snapshot.matches({ "Detour Drawing": "Share Detour" }) && + editDetour ? ( - )} + ) : null}
- {state === DetourState.Finished && ( + {snapshot.matches({ "Detour Drawing": "Share Detour" }) && ( }, [shapePoints]), }) -export enum DetourState { - Edit, - Finished, -} - export const useDetour = ({ routePatternId, shape }: OriginalRoute) => { const [snapshot, send] = useMachine(createDetourMachine) @@ -128,12 +123,8 @@ export const useDetour = ({ routePatternId, shape }: OriginalRoute) => { })) return { - /** The current state of the detour machine */ - state: snapshot.matches({ "Detour Drawing": "Editing" }) - ? DetourState.Edit - : snapshot.matches({ "Detour Drawing": "Share Detour" }) - ? DetourState.Finished - : DetourState.Edit, + /** The current state machine snapshot */ + snapshot, /** Creates a new waypoint if all of the following criteria is met: * - {@link startPoint} is set