Skip to content

Commit

Permalink
Merge pull request #3641 from TrainLCD/fix/la
Browse files Browse the repository at this point in the history
路線情報が正しく処理できてなかった
  • Loading branch information
TinyKitten authored Aug 3, 2024
2 parents efcebb0 + 9785d8e commit 8f7ab49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/hooks/useCurrentLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 9 additions & 2 deletions src/hooks/useCurrentStation.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePreviousStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() =>
Expand All @@ -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(),
Expand Down

0 comments on commit 8f7ab49

Please sign in to comment.