menu側にも列車表示を追加

This commit is contained in:
harukin-OneMix4 2023-06-27 21:34:20 +09:00
parent ed76462436
commit 7f67fc6cc8

42
menu.js
View File

@ -34,6 +34,7 @@ import { TicketBox } from "./components/atom/TicketBox";
import { TextBox } from "./components/atom/TextBox"; import { TextBox } from "./components/atom/TextBox";
import { getStationList, lineList } from "./lib/getStationList"; import { getStationList, lineList } from "./lib/getStationList";
import { JRSTraInfo } from "./components/ActionSheetComponents/JRSTraInfo"; import { JRSTraInfo } from "./components/ActionSheetComponents/JRSTraInfo";
import { EachTrainInfo } from "./components/ActionSheetComponents/EachTrainInfo";
import useInterval from "./lib/useInterval"; import useInterval from "./lib/useInterval";
export default function Menu(props) { export default function Menu(props) {
@ -55,6 +56,13 @@ export default function Menu(props) {
}); });
}, []); }, []);
//列車情報表示関連
const EachTrainInfoAsSR = useRef(null);
const [trainInfo, setTrainInfo] = useState({
trainNum: undefined,
limited: undefined,
});
const getCurrentPosition = () => { const getCurrentPosition = () => {
if (locationStatus !== "granted") return () => {}; if (locationStatus !== "granted") return () => {};
Location.getCurrentPositionAsync({}).then((location) => Location.getCurrentPositionAsync({}).then((location) =>
@ -124,13 +132,11 @@ export default function Menu(props) {
const allStationData = [currentStation, ...favoriteStation].filter( const allStationData = [currentStation, ...favoriteStation].filter(
(d) => d != undefined (d) => d != undefined
); );
console.log(allStationData);
useEffect(() => { useEffect(() => {
if (allStationData.length == 0) { if (allStationData.length == 0) {
setSelectedCurrentStation(0); setSelectedCurrentStation(0);
return; return;
} }
console.log(allStationData[selectedCurrentStation]);
if (allStationData[selectedCurrentStation] == undefined) { if (allStationData[selectedCurrentStation] == undefined) {
const count = selectedCurrentStation - 1; const count = selectedCurrentStation - 1;
setSelectedCurrentStation(count); setSelectedCurrentStation(count);
@ -138,12 +144,35 @@ export default function Menu(props) {
}, [selectedCurrentStation, currentStation, favoriteStation]); }, [selectedCurrentStation, currentStation, favoriteStation]);
useEffect(() => { useEffect(() => {
if (!carouselRef.current) return; if (!carouselRef.current) return;
console.log(carouselRef.current);
if (carouselRef.current?._itemToSnapTo != selectedCurrentStation) { if (carouselRef.current?._itemToSnapTo != selectedCurrentStation) {
carouselRef.current.snapToItem(0); carouselRef.current.snapToItem(0);
carouselRef.current.snapToItem(selectedCurrentStation); carouselRef.current.snapToItem(selectedCurrentStation);
} }
}, [selectedCurrentStation]); }, [selectedCurrentStation]);
const openStationACFromEachTrainInfo = (stationName) => {
EachTrainInfoAsSR.current?.hide();
const findStationEachLine = (selectLine) => {
let NearStation = selectLine.filter((d) => d.Station_JP == stationName);
return NearStation;
};
let returnDataBase = lineList
.map((d) => findStationEachLine(originalStationList[d]))
.filter((d) => d.length > 0)
.reduce((pre, current) => {
pre.push(...current);
return pre;
}, []);
if (returnDataBase.length) {
setStationBoardData(returnDataBase);
sleep(30, function () {
StationBoardAcSR.current?.show();
});
} else {
setStationBoardData(undefined);
StationBoardAcSR.current?.hide();
}
};
return ( return (
<View <View
style={{ style={{
@ -231,6 +260,13 @@ export default function Menu(props) {
setLoadingDelayData={setLoadingDelayData} setLoadingDelayData={setLoadingDelayData}
delayData={delayData} delayData={delayData}
/> />
<EachTrainInfo
setRef={EachTrainInfoAsSR}
data={trainInfo}
navigate={navigate}
originalStationList={originalStationList}
openStationACFromEachTrainInfo={openStationACFromEachTrainInfo}
/>
</View> </View>
); );
} }