diff --git a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx index 739ed3f..cacd548 100644 --- a/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx +++ b/components/ActionSheetComponents/EachTrainInfo/TrainDataView.tsx @@ -25,7 +25,7 @@ export const TrainDataView = ({ const { width, height } = useWindowDimensions(); const { isLandscape } = useDeviceOrientationChange(); - const { inject } = useCurrentTrain(); + const { setInjectData } = useCurrentTrain(); const { allCustomTrainData } = useAllTrainDiagram(); const [mapsStationData, setMapsStationData] = useState(undefined); @@ -150,27 +150,18 @@ export const TrainDataView = ({ { + if (!onLine) return; + setInjectData({ type:"train", value:currentTrainData?.num, fixed:true}); + navigate("positions", { screen: "Apps" }); + SheetManager.hide("EachTrainInfo"); + }} onPress={() => { if (!onLine) return; - const test = []; - Object.keys(mapsStationData).forEach((d) => { - mapsStationData[d].forEach((x) => { - if (x.StationNumber == currentPosition[0]) - test.push({ line: d, station: x }); - }); - if (currentPosition[0] == "M12") { - test.push({ - line: "seto", - station: { Station_JP: "児島", MyStation: "0" }, - }); - } - }); - if (!test.length) return; + setInjectData({ type: "station", value: currentPosition[0], fixed: false }); + navigate("positions", { screen: "Apps" }); - inject( - `MoveDisplayStation('${test[0].line}_${test[0].station.MyStation}_${test[0].station.Station_JP}');document.getElementById("disp").insertAdjacentHTML("afterbegin", "
");` - ); SheetManager.hide("EachTrainInfo"); }} > diff --git a/components/Apps.js b/components/Apps.js index fb5f985..769b17a 100644 --- a/components/Apps.js +++ b/components/Apps.js @@ -4,6 +4,7 @@ import { Platform, useWindowDimensions, LayoutAnimation, + Text, } from "react-native"; import Constants from "expo-constants"; import * as Updates from "expo-updates"; @@ -30,7 +31,7 @@ var Status = StatusbarDetect(); */ const top = Platform.OS == "ios" ? Constants.statusBarHeight : 0; export default function Apps() { - const { webview } = useCurrentTrain(); + const { webview, fixedPosition, setFixedPosition } = useCurrentTrain(); const { height, width } = useWindowDimensions(); const { navigate } = useNavigation(); const { isLandscape } = useDeviceOrientationChange(); @@ -125,6 +126,16 @@ export default function Apps() { }} /> )} + {fixedPosition.type && ( + { + setFixedPosition({ type: null, value: null }); + }} + > + {fixedPosition.type}: {fixedPosition.value} + + )} + {mapSwitch == "true" ? ( Updates.reloadAsync()} diff --git a/stateBox/useCurrentTrain.js b/stateBox/useCurrentTrain.js index 81c594a..3684382 100644 --- a/stateBox/useCurrentTrain.js +++ b/stateBox/useCurrentTrain.js @@ -47,15 +47,25 @@ export const CurrentTrainProvider = ({ children }) => { () => { if (!webview.current) return; if (fixedPosition.type == "station") { - alert("stationに移動"); const script = getInjectJavascriptAddress(fixedPosition.value); inject(script); - } - else if(fixedPosition.type == "train"){ + } else if (fixedPosition.type == "train") { + const currentTrain = getCurrentStationData(fixedPosition.value); + const values = getPosition(currentTrain); + if (!values) return; + if (values[0] == "M12" || values[1] == "M12") { + const script = getInjectJavascriptAddress("M12"); + inject(script); + return; + } + const script = getInjectJavascriptAddress( + values[values.length == 2 ? currentTrain.Direction : 0] + ); + inject(script); } }, - 60000, + 5000, //60000, false ); useEffect(() => { @@ -66,7 +76,6 @@ export const CurrentTrainProvider = ({ children }) => { } }, [fixedPosition]); const getPosition = (currentTrainData) => { - console.log(currentTrainData); //currentTrainData.Pos = "鴨川~端岡"; //test if (!currentTrainData) return; if (!currentTrainData?.Pos) return; @@ -127,22 +136,6 @@ export const CurrentTrainProvider = ({ children }) => { return [getStationID(currentTrainData?.Pos, stationList)]; } }; - const setInjectData = ({ type, value, fixed }) => { - if (type === "station") { - const script = getInjectJavascriptAddress(value); - console.log(value); - inject(script); - if (fixed) { - setFixedPosition({ type, value: value }); - } - } else if (type === "station") { - const script = getInjectJavascriptAddress(value); - inject(script); - if (fixed) { - setFixedPosition(script); - } - } - }; const getCurrentStationData = (e) => { //e:trainNumber if (!currentTrain.length) return; @@ -151,6 +144,28 @@ export const CurrentTrainProvider = ({ children }) => { stationList ); }; + const setInjectData = ({ type, value, fixed }) => { + if (type === "station") { + const script = getInjectJavascriptAddress(value); + console.log(value); + inject(script); + } else if (type === "train") { + const currentTrain = getCurrentStationData(value); + const values = getPosition(currentTrain); + if (!values) return; + let script; + if (values[0] == "M12" || values[1] == "M12") { + script = getInjectJavascriptAddress("M12"); + } else { + const valuesIndex = values.length == 2 ? currentTrain.Direction : 0; + script = getInjectJavascriptAddress(values[valuesIndex]); + } + inject(script); + } + if (fixed) { + setFixedPosition({ type, value }); + } + }; const getCurrentTrain = () => { fetch("https://n8n.haruk.in/webhook/c501550c-7d1b-4e50-927b-4429fe18931a") .then((response) => response.json()) @@ -215,6 +230,8 @@ export const CurrentTrainProvider = ({ children }) => { setInjectData, getCurrentStationData, getPosition, + fixedPosition, + setFixedPosition, }} > {children}