From 7232c40af1aa2a5e60f185f0fb48f98b62fe699d Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sun, 13 Apr 2025 16:56:47 +0000 Subject: [PATCH] =?UTF-8?q?menu=E3=81=AE=E5=A4=89=E6=95=B0=E5=90=8D?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- menu.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/menu.js b/menu.js index 35460e5..1392e8c 100644 --- a/menu.js +++ b/menu.js @@ -103,40 +103,40 @@ export default function Menu({ getCurrentTrain, scrollRef }) { const [nearPositionStation, setNearPositionStation] = useState(undefined); //第三要素 const carouselRef = useRef(); - const [selectedCurrentStation, setSelectedCurrentStation] = useState(0); + const [listIndex, setListIndex] = useState(0); - const [allStationData, setAllStationData] = useState([]); + const [listUpStation, setListUpStation] = useState([]); useEffect(() => { if (stationListMode == "position") { console.log(nearPositionStation); - setAllStationData([nearPositionStation].filter((d) => d != undefined)); + setListUpStation([nearPositionStation].filter((d) => d != undefined)); } else { - setAllStationData(favoriteStation.filter((d) => d != undefined)); + setListUpStation(favoriteStation.filter((d) => d != undefined)); } }, [nearPositionStation, favoriteStation, stationListMode]); useEffect(() => { - if (allStationData.length == 0) { - setSelectedCurrentStation(0); + if (listUpStation.length == 0) { + setListIndex(0); return; } - if (allStationData[selectedCurrentStation] == undefined) { - const count = selectedCurrentStation - 1; - setSelectedCurrentStation(count); + if (listUpStation[listIndex] == undefined) { + const count = listIndex - 1; + setListIndex(count); } - }, [selectedCurrentStation, nearPositionStation, allStationData]); + }, [listIndex, nearPositionStation, listUpStation]); useEffect(() => { if (!carouselRef.current) return; carouselRef?.current.scrollTo({ - count: selectedCurrentStation - carouselRef.current.getCurrentIndex(), + count: listIndex - carouselRef.current.getCurrentIndex(), animated: true, }); - }, [selectedCurrentStation]); + }, [listIndex]); useEffect(() => { if (originalStationList == undefined) return; - if (allStationData.length == 0) return; - if (allStationData[selectedCurrentStation] == undefined) return; - const { lat, lng } = allStationData[selectedCurrentStation][0]; + if (listUpStation.length == 0) return; + if (listUpStation[listIndex] == undefined) return; + const { lat, lng } = listUpStation[listIndex][0]; const mapRegion = { latitude: lat, longitude: lng, @@ -144,7 +144,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) { longitudeDelta: 0.05, }; mapsRef.current.animateToRegion(mapRegion, 1000); - }, [selectedCurrentStation, nearPositionStation, allStationData, mapsRef]); + }, [listIndex, nearPositionStation, listUpStation, mapsRef]); return ( - {allStationData.length != 0 && originalStationList.length != 0 && ( + {listUpStation.length != 0 && originalStationList.length != 0 && ( <> - {allStationData[selectedCurrentStation] && ( + {listUpStation[listIndex] && ( {}}