menuの変数名を変更

This commit is contained in:
harukin-expo-dev-env 2025-04-13 16:56:47 +00:00
parent 35bb460b54
commit 7232c40af1

46
menu.js
View File

@ -103,40 +103,40 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
const [nearPositionStation, setNearPositionStation] = useState(undefined); //第三要素 const [nearPositionStation, setNearPositionStation] = useState(undefined); //第三要素
const carouselRef = useRef(); const carouselRef = useRef();
const [selectedCurrentStation, setSelectedCurrentStation] = useState(0); const [listIndex, setListIndex] = useState(0);
const [allStationData, setAllStationData] = useState([]); const [listUpStation, setListUpStation] = useState([]);
useEffect(() => { useEffect(() => {
if (stationListMode == "position") { if (stationListMode == "position") {
console.log(nearPositionStation); console.log(nearPositionStation);
setAllStationData([nearPositionStation].filter((d) => d != undefined)); setListUpStation([nearPositionStation].filter((d) => d != undefined));
} else { } else {
setAllStationData(favoriteStation.filter((d) => d != undefined)); setListUpStation(favoriteStation.filter((d) => d != undefined));
} }
}, [nearPositionStation, favoriteStation, stationListMode]); }, [nearPositionStation, favoriteStation, stationListMode]);
useEffect(() => { useEffect(() => {
if (allStationData.length == 0) { if (listUpStation.length == 0) {
setSelectedCurrentStation(0); setListIndex(0);
return; return;
} }
if (allStationData[selectedCurrentStation] == undefined) { if (listUpStation[listIndex] == undefined) {
const count = selectedCurrentStation - 1; const count = listIndex - 1;
setSelectedCurrentStation(count); setListIndex(count);
} }
}, [selectedCurrentStation, nearPositionStation, allStationData]); }, [listIndex, nearPositionStation, listUpStation]);
useEffect(() => { useEffect(() => {
if (!carouselRef.current) return; if (!carouselRef.current) return;
carouselRef?.current.scrollTo({ carouselRef?.current.scrollTo({
count: selectedCurrentStation - carouselRef.current.getCurrentIndex(), count: listIndex - carouselRef.current.getCurrentIndex(),
animated: true, animated: true,
}); });
}, [selectedCurrentStation]); }, [listIndex]);
useEffect(() => { useEffect(() => {
if (originalStationList == undefined) return; if (originalStationList == undefined) return;
if (allStationData.length == 0) return; if (listUpStation.length == 0) return;
if (allStationData[selectedCurrentStation] == undefined) return; if (listUpStation[listIndex] == undefined) return;
const { lat, lng } = allStationData[selectedCurrentStation][0]; const { lat, lng } = listUpStation[listIndex][0];
const mapRegion = { const mapRegion = {
latitude: lat, latitude: lat,
longitude: lng, longitude: lng,
@ -144,7 +144,7 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
longitudeDelta: 0.05, longitudeDelta: 0.05,
}; };
mapsRef.current.animateToRegion(mapRegion, 1000); mapsRef.current.animateToRegion(mapRegion, 1000);
}, [selectedCurrentStation, nearPositionStation, allStationData, mapsRef]); }, [listIndex, nearPositionStation, listUpStation, mapsRef]);
return ( return (
<View <View
style={{ style={{
@ -190,25 +190,25 @@ export default function Menu({ getCurrentTrain, scrollRef }) {
mapsRef, mapsRef,
stationListMode, stationListMode,
setStationListMode, setStationListMode,
setSelectedCurrentStation, setSelectedCurrentStation: setListIndex,
}} }}
/> />
{allStationData.length != 0 && originalStationList.length != 0 && ( {listUpStation.length != 0 && originalStationList.length != 0 && (
<> <>
<CarouselBox <CarouselBox
{...{ {...{
originalStationList, originalStationList,
allStationData, allStationData: listUpStation,
currentStation: nearPositionStation, currentStation: nearPositionStation,
setSelectedCurrentStation, setSelectedCurrentStation: setListIndex,
carouselRef, carouselRef,
selectedCurrentStation, selectedCurrentStation: listIndex,
navigate, navigate,
}} }}
/> />
{allStationData[selectedCurrentStation] && ( {listUpStation[listIndex] && (
<LED_vision <LED_vision
station={allStationData[selectedCurrentStation]} station={listUpStation[listIndex]}
getCurrentTrain={getCurrentTrain} getCurrentTrain={getCurrentTrain}
navigate={navigate} navigate={navigate}
openStationACFromEachTrainInfo={() => {}} openStationACFromEachTrainInfo={() => {}}