From 023e4c64af7e643a93a5d51fcadc9d0cbc0dafd0 Mon Sep 17 00:00:00 2001 From: Masanari Hamada Date: Thu, 5 Dec 2024 23:00:02 +0900 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20ISURIDE=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E6=8A=BC=E4=B8=8B=E6=99=82=E3=81=ABpost-message=E3=82=92?= =?UTF-8?q?=E9=A3=9B=E3=81=B0=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/components/primitives/modal/modal.tsx | 4 +--- frontend/app/routes/client._index/route.tsx | 14 ++++++-------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/frontend/app/components/primitives/modal/modal.tsx b/frontend/app/components/primitives/modal/modal.tsx index c1d7ff63..3da225ed 100644 --- a/frontend/app/components/primitives/modal/modal.tsx +++ b/frontend/app/components/primitives/modal/modal.tsx @@ -65,9 +65,7 @@ export const Modal = forwardRef<{ close: () => void }, ModalProps>( }} {...props} > -
- {children} -
+
{children}
); diff --git a/frontend/app/routes/client._index/route.tsx b/frontend/app/routes/client._index/route.tsx index b3212836..a11828a2 100644 --- a/frontend/app/routes/client._index/route.tsx +++ b/frontend/app/routes/client._index/route.tsx @@ -17,7 +17,7 @@ import { Modal } from "~/components/primitives/modal/modal"; import { Text } from "~/components/primitives/text/text"; import { useClientContext } from "~/contexts/client-context"; import { NearByChair, isClientApiError } from "~/types"; -import { sendClientReady } from "~/utils/post-message"; +import { sendClientReady, sendClientRunning } from "~/utils/post-message"; import { Arrived } from "./driving-state/arrived"; import { Carrying } from "./driving-state/carrying"; import { Enroute } from "./driving-state/enroute"; @@ -63,9 +63,7 @@ export default function Index() { } else if (direction === "to") { setDestLocation(selectedLocation); } - if (locationSelectorModalRef.current) { - locationSelectorModalRef.current.close(); - } + locationSelectorModalRef.current?.close(); }, [direction, selectedLocation]); const isStatusModalOpen = useMemo(() => { @@ -110,12 +108,13 @@ export default function Index() { } setInternalRideStatus("MATCHING"); try { - void (await fetchAppPostRides({ + const { ride_id } = await fetchAppPostRides({ body: { pickup_coordinate: currentLocation, destination_coordinate: destLocation, }, - })); + }); + sendClientRunning(window.parent, { rideId: ride_id }); } catch (error) { if (isClientApiError(error)) { console.error(error); @@ -129,8 +128,7 @@ export default function Index() { let abortController: AbortController | undefined; let timeoutId: NodeJS.Timeout | undefined; - const updateNearByChairs = async (coordinate: Coordinate) => { - const { latitude, longitude } = coordinate; + const updateNearByChairs = async ({ latitude, longitude }: Coordinate) => { try { abortController?.abort(); abortController = new AbortController(); From 51dc63d9bc75d38a0ede28f4f388222210512d1e Mon Sep 17 00:00:00 2001 From: Masanari Hamada Date: Thu, 5 Dec 2024 23:06:24 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20lint,=20=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/routes/client._index/route.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/frontend/app/routes/client._index/route.tsx b/frontend/app/routes/client._index/route.tsx index a11828a2..4cd8c1d0 100644 --- a/frontend/app/routes/client._index/route.tsx +++ b/frontend/app/routes/client._index/route.tsx @@ -36,6 +36,7 @@ type EstimatePrice = { fare: number; discount: number }; export default function Index() { const { data } = useClientContext(); + const emulateChairs = useGhostChairs(); const [internalRideStatus, setInternalRideStatus] = useState(); const [currentLocation, setCurrentLocation] = useState(); const [destLocation, setDestLocation] = useState(); @@ -44,19 +45,20 @@ export default function Index() { const [displayedChairs, setDisplayedChairs] = useState([]); const [centerCoordinate, setCenterCoodirnate] = useState(); const onCenterMove = useCallback( - (coordinate: Coordinate) => { - setCenterCoodirnate(coordinate); - }, - [setCenterCoodirnate], + (coordinate: Coordinate) => setCenterCoodirnate(coordinate), + [], + ); + const onSelectMove = useCallback( + (coordinate: Coordinate) => setSelectedLocation(coordinate), + [], ); - const onSelectMove = useCallback((coordinate: Coordinate) => { - setSelectedLocation(coordinate); - }, []); const [isLocationSelectorModalOpen, setLocationSelectorModalOpen] = useState(false); const locationSelectorModalRef = useRef void }>( null, ); + const statusModalRef = useRef void }>(null); + const [estimatePrice, setEstimatePrice] = useState(); const handleConfirmLocation = useCallback(() => { if (direction === "from") { setCurrentLocation(selectedLocation); @@ -75,10 +77,6 @@ export default function Index() { ); }, [internalRideStatus]); - const statusModalRef = useRef void }>(null); - const [estimatePrice, setEstimatePrice] = useState(); - const emulateChairs = useGhostChairs(); - useEffect(() => { setInternalRideStatus(data?.status); }, [data?.status]); From 5f6bf0993cb4a7eb2d34649e171a34cf21d174d9 Mon Sep 17 00:00:00 2001 From: Masanari Hamada Date: Fri, 6 Dec 2024 00:08:21 +0900 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/contexts/owner-context.tsx | 1 - frontend/app/contexts/simulator-context.tsx | 29 ++++++++++++++++++++- frontend/app/routes/client._index/route.tsx | 12 ++++----- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/frontend/app/contexts/owner-context.tsx b/frontend/app/contexts/owner-context.tsx index e7b35869..08eb56d1 100644 --- a/frontend/app/contexts/owner-context.tsx +++ b/frontend/app/contexts/owner-context.tsx @@ -77,7 +77,6 @@ export const OwnerProvider = ({ children }: { children: ReactNode }) => { void (async () => { try { const sales = await fetchOwnerGetSales({ - // TODO: 機能していない? queryParams: { since: timestamp(since), until: timestamp(until), diff --git a/frontend/app/contexts/simulator-context.tsx b/frontend/app/contexts/simulator-context.tsx index dec60fc9..de278ce6 100644 --- a/frontend/app/contexts/simulator-context.tsx +++ b/frontend/app/contexts/simulator-context.tsx @@ -18,14 +18,16 @@ import { fetchChairGetNotification, } from "~/api/api-components"; import { SimulatorChair } from "~/types"; -import { getSimulatorCurrentCoordinate } from "~/utils/storage"; import { getCookieValue } from "~/utils/get-cookie-value"; +import { Message, MessageTypes } from "~/utils/post-message"; +import { getSimulatorCurrentCoordinate } from "~/utils/storage"; type SimulatorContextProps = { chair?: SimulatorChair; data?: ChairGetNotificationResponse["data"]; setCoordinate?: (coordinate: Coordinate) => void; setToken?: (token: string) => void; + isAnotherSimulatorBeingUsed?: boolean; }; const SimulatorContext = createContext({}); @@ -186,6 +188,30 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => { return coordinate ?? { latitude: 0, longitude: 0 }; }); + const [clientRideId, setClientRideId] = useState(); + const isAnotherSimulatorBeingUsed = !!( + clientRideId && + data?.ride_id && + clientRideId !== data.ride_id + ); + + console.log(isAnotherSimulatorBeingUsed); + + useEffect(() => { + const onMessage = ({ + data, + }: MessageEvent) => { + const isSameOrigin = origin == location.origin; + if (isSameOrigin && data.type === MessageTypes.ClientRideRequested) { + setClientRideId(data?.payload?.rideId); + } + }; + window.addEventListener("message", onMessage); + return () => { + window.removeEventListener("message", onMessage); + }; + }, []); + return ( { chair: simulateChair ? { ...simulateChair, coordinate } : undefined, setCoordinate, setToken, + isAnotherSimulatorBeingUsed, }} > {children} diff --git a/frontend/app/routes/client._index/route.tsx b/frontend/app/routes/client._index/route.tsx index 4cd8c1d0..380900ba 100644 --- a/frontend/app/routes/client._index/route.tsx +++ b/frontend/app/routes/client._index/route.tsx @@ -16,8 +16,8 @@ import { Button } from "~/components/primitives/button/button"; import { Modal } from "~/components/primitives/modal/modal"; import { Text } from "~/components/primitives/text/text"; import { useClientContext } from "~/contexts/client-context"; -import { NearByChair, isClientApiError } from "~/types"; -import { sendClientReady, sendClientRunning } from "~/utils/post-message"; +import { NearByChair } from "~/types"; +import { sendClientReady, sendClientRideRequested } from "~/utils/post-message"; import { Arrived } from "./driving-state/arrived"; import { Carrying } from "./driving-state/carrying"; import { Enroute } from "./driving-state/enroute"; @@ -112,11 +112,9 @@ export default function Index() { destination_coordinate: destLocation, }, }); - sendClientRunning(window.parent, { rideId: ride_id }); + sendClientRideRequested(window.parent, { rideId: ride_id }); } catch (error) { - if (isClientApiError(error)) { - console.error(error); - } + console.error(error); } }, [currentLocation, destLocation]); @@ -223,7 +221,7 @@ export default function Index() { ref={locationSelectorModalRef} onClose={() => setLocationSelectorModalOpen(false)} > -
+
Date: Fri, 6 Dec 2024 00:14:13 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/utils/post-message.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/frontend/app/utils/post-message.ts b/frontend/app/utils/post-message.ts index 7eefc254..c6a72f91 100644 --- a/frontend/app/utils/post-message.ts +++ b/frontend/app/utils/post-message.ts @@ -1,6 +1,7 @@ export const MessageTypes = { - ClientReady: "isuride.client.ready", - SimulatorConfing: "isuride.simulator.config", + ClientReady: "isuride.client.ready", // クライアントの画面準備完了 + ClientRideRequested: "isuride.client.running", // クライアントでISURIDEが実行中 + SimulatorConfing: "isuride.simulator.config", // シミュレーターからの設定値変更 } as const; export type Message = { @@ -8,6 +9,10 @@ export type Message = { type: typeof MessageTypes.ClientReady; payload: { ready?: boolean }; }; + ClientRideRequested: { + type: typeof MessageTypes.ClientRideRequested; + payload: { rideId?: string }; + }; SimulatorConfing: { type: typeof MessageTypes.SimulatorConfing; payload: { @@ -23,6 +28,13 @@ export const sendClientReady = ( target.postMessage({ type: MessageTypes.ClientReady, payload }, "*"); }; +export const sendClientRideRequested = ( + target: Window, + payload: NonNullable, +) => { + target.postMessage({ type: MessageTypes.ClientRideRequested, payload }, "*"); +}; + export const sendSimulatorConfig = ( target: Window, payload: NonNullable, From 6cd72530fa51fde1723182066d6c23e98a4159d5 Mon Sep 17 00:00:00 2001 From: Masanari Hamada Date: Fri, 6 Dec 2024 14:16:08 +0900 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20=E5=88=A4=E5=AE=9A=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/contexts/simulator-context.tsx | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/app/contexts/simulator-context.tsx b/frontend/app/contexts/simulator-context.tsx index de278ce6..9a57546d 100644 --- a/frontend/app/contexts/simulator-context.tsx +++ b/frontend/app/contexts/simulator-context.tsx @@ -189,11 +189,7 @@ export const SimulatorProvider = ({ children }: { children: ReactNode }) => { }); const [clientRideId, setClientRideId] = useState(); - const isAnotherSimulatorBeingUsed = !!( - clientRideId && - data?.ride_id && - clientRideId !== data.ride_id - ); + const isAnotherSimulatorBeingUsed = !clientRideId && !!data?.ride_id; console.log(isAnotherSimulatorBeingUsed);