From 9785d8e947adc96d045293a30468e38470cfb278 Mon Sep 17 00:00:00 2001 From: Tsubasa SEKIGUCHI Date: Sat, 3 Aug 2024 10:55:38 +0900 Subject: [PATCH] =?UTF-8?q?=E8=B7=AF=E7=B7=9A=E6=83=85=E5=A0=B1=E3=81=8C?= =?UTF-8?q?=E6=AD=A3=E3=81=97=E3=81=8F=E5=87=A6=E7=90=86=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=81=A6=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useCurrentLine.ts | 10 +++++++--- src/hooks/useCurrentStation.ts | 11 +++++++++-- src/hooks/usePreviousStation.ts | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/hooks/useCurrentLine.ts b/src/hooks/useCurrentLine.ts index ce3466f2f..597f296f9 100644 --- a/src/hooks/useCurrentLine.ts +++ b/src/hooks/useCurrentLine.ts @@ -14,9 +14,13 @@ export const useCurrentLine = () => { (selectedDirection === 'INBOUND' ? stations.slice().reverse() : stations - ).find((rs) => rs.id === currentStation?.id), - [currentStation?.id, selectedDirection, stations] + ).find( + (rs) => + rs.groupId === currentStation?.groupId ?? + rs.line?.id === selectedLine?.id + ), + [currentStation?.groupId, selectedDirection, selectedLine?.id, stations] ) - return actualCurrentStation?.line || selectedLine + return actualCurrentStation?.line } diff --git a/src/hooks/useCurrentStation.ts b/src/hooks/useCurrentStation.ts index 63e87a072..1fb26d195 100644 --- a/src/hooks/useCurrentStation.ts +++ b/src/hooks/useCurrentStation.ts @@ -1,5 +1,6 @@ import { useMemo } from 'react' import { useRecoilValue } from 'recoil' +import lineState from '../store/atoms/line' import stationState from '../store/atoms/station' import getIsPass from '../utils/isPass' @@ -12,11 +13,17 @@ export const useCurrentStation = ( station: stationFromState, selectedDirection, } = useRecoilValue(stationState) + const { selectedLine } = useRecoilValue(lineState) // NOTE: 選択した路線と現在の駅の路線を一致させる const station = useMemo( - () => stations.find((s) => s.id === stationFromState?.id) ?? null, - [stationFromState?.id, stations] + () => + stations.find( + (s) => + s.groupId === stationFromState?.groupId ?? + s.line?.id === selectedLine?.id + ), + [selectedLine?.id, stationFromState?.groupId, stations] ) const withTrainTypeStation = useMemo(() => { diff --git a/src/hooks/usePreviousStation.ts b/src/hooks/usePreviousStation.ts index bc8fc0ea5..97ea6aa6e 100644 --- a/src/hooks/usePreviousStation.ts +++ b/src/hooks/usePreviousStation.ts @@ -9,6 +9,7 @@ import { useCurrentStation } from './useCurrentStation' const usePreviousStation = (skipPass = true): Station | undefined => { const { stations: stationsFromState, selectedDirection } = useRecoilValue(stationState) + const station = useCurrentStation(true) const stations = useMemo( () => @@ -18,7 +19,6 @@ const usePreviousStation = (skipPass = true): Station | undefined => { [selectedDirection, skipPass, stationsFromState] ) - const station = useCurrentStation(true) const reversedStations = useMemo( () => selectedDirection === 'INBOUND' ? stations : stations.slice().reverse(),