menu側にも列車表示を追加
This commit is contained in:
parent
ed76462436
commit
7f67fc6cc8
42
menu.js
42
menu.js
@ -34,6 +34,7 @@ import { TicketBox } from "./components/atom/TicketBox";
|
||||
import { TextBox } from "./components/atom/TextBox";
|
||||
import { getStationList, lineList } from "./lib/getStationList";
|
||||
import { JRSTraInfo } from "./components/ActionSheetComponents/JRSTraInfo";
|
||||
import { EachTrainInfo } from "./components/ActionSheetComponents/EachTrainInfo";
|
||||
import useInterval from "./lib/useInterval";
|
||||
|
||||
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 = () => {
|
||||
if (locationStatus !== "granted") return () => {};
|
||||
Location.getCurrentPositionAsync({}).then((location) =>
|
||||
@ -124,13 +132,11 @@ export default function Menu(props) {
|
||||
const allStationData = [currentStation, ...favoriteStation].filter(
|
||||
(d) => d != undefined
|
||||
);
|
||||
console.log(allStationData);
|
||||
useEffect(() => {
|
||||
if (allStationData.length == 0) {
|
||||
setSelectedCurrentStation(0);
|
||||
return;
|
||||
}
|
||||
console.log(allStationData[selectedCurrentStation]);
|
||||
if (allStationData[selectedCurrentStation] == undefined) {
|
||||
const count = selectedCurrentStation - 1;
|
||||
setSelectedCurrentStation(count);
|
||||
@ -138,12 +144,35 @@ export default function Menu(props) {
|
||||
}, [selectedCurrentStation, currentStation, favoriteStation]);
|
||||
useEffect(() => {
|
||||
if (!carouselRef.current) return;
|
||||
console.log(carouselRef.current);
|
||||
if (carouselRef.current?._itemToSnapTo != selectedCurrentStation) {
|
||||
carouselRef.current.snapToItem(0);
|
||||
carouselRef.current.snapToItem(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 (
|
||||
<View
|
||||
style={{
|
||||
@ -231,6 +260,13 @@ export default function Menu(props) {
|
||||
setLoadingDelayData={setLoadingDelayData}
|
||||
delayData={delayData}
|
||||
/>
|
||||
<EachTrainInfo
|
||||
setRef={EachTrainInfoAsSR}
|
||||
data={trainInfo}
|
||||
navigate={navigate}
|
||||
originalStationList={originalStationList}
|
||||
openStationACFromEachTrainInfo={openStationACFromEachTrainInfo}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user