diff --git a/components/ActionSheetComponents/EachTrainInfoCore.js b/components/ActionSheetComponents/EachTrainInfoCore.js index b791f49..9633c8c 100644 --- a/components/ActionSheetComponents/EachTrainInfoCore.js +++ b/components/ActionSheetComponents/EachTrainInfoCore.js @@ -83,23 +83,29 @@ export const EachTrainInfoCore = ({ const [haveThrough, setHaveThrough] = useState(false); // 使用例 - const stopStationIDList = trainDataWidhThrough.map((i) => { - const [station, se, time] = i.split(","); - const Stations = stationList.map((a) => - a.filter((d) => d.StationName == station) - ); - const StationNumbers = - Stations && - Stations.reduce((newArray, e) => { - return newArray.concat(e); - }, []).map((d) => d.StationNumber); - return StationNumbers; - }); + const [stopStationIDList, setStopStationList] = useState([]); + useEffect(() => { + const x = trainDataWidhThrough.map((i) => { + const [station, se, time] = i.split(","); + const Stations = stationList.map((a) => + a.filter((d) => d.StationName == station) + ); + const StationNumbers = + Stations && + Stations.reduce((newArray, e) => { + return newArray.concat(e); + }, []).map((d) => d.StationNumber); + return StationNumbers; + }); + setStopStationList(x); + }, [trainDataWidhThrough]); + useEffect(() => { const isCancel = []; - const stopStationList = trainData.map((i,index,array) => { + const stopStationList = trainData.map((i, index, array) => { const [station, se, time] = i.split(","); - const [nextStation, nextSe, nextTime] = array[index+1]?.split(",") || []; + const [nextStation, nextSe, nextTime] = + array[index + 1]?.split(",") || []; isCancel.push(se.includes("休") && nextSe.includes("休")); if (se == "通編") setHaveThrough(true); return stationList.map((a) => a.filter((d) => d.StationName == station)); @@ -131,8 +137,9 @@ export const EachTrainInfoCore = ({ d.StationNumber > baseStationNumberFirst && d.StationNumber < baseStationNumberSecond ) { - - allThroughStation.push(`${d.Station_JP},${isCancel[index] ? "通休編" : "通過"},`); + allThroughStation.push( + `${d.Station_JP},${isCancel[index] ? "通休編" : "通過"},` + ); setHaveThrough(true); reverse = false; } else { @@ -140,7 +147,9 @@ export const EachTrainInfoCore = ({ d.StationNumber < baseStationNumberFirst && d.StationNumber > baseStationNumberSecond ) { - allThroughStation.push(`${d.Station_JP},${isCancel[index] ? "通休編" : "通過"},`); + allThroughStation.push( + `${d.Station_JP},${isCancel[index] ? "通休編" : "通過"},` + ); setHaveThrough(true); reverse = true; } @@ -252,6 +261,7 @@ export const EachTrainInfoCore = ({ useEffect(() => { const position = getPosition(currentTrainData); + if (stopStationIDList.length == 0) return; if (position) { if (position.length > 1) { if (position[0] == "-Iyo") { @@ -259,8 +269,7 @@ export const EachTrainInfoCore = ({ stopStationIDList[ stopStationIDList.findIndex((d) => d.includes("U14")) - 1 ][0]; - } - else if (position[0] == "+Iyo") { + } else if (position[0] == "+Iyo") { position[0] = stopStationIDList[ stopStationIDList.findIndex((d) => d.includes("U14")) + 1 @@ -271,7 +280,7 @@ export const EachTrainInfoCore = ({ stopStationIDList[ stopStationIDList.findIndex((d) => d.includes("U14")) + 1 ][0]; - }else if (position[1] == "-Iyo") { + } else if (position[1] == "-Iyo") { position[1] = stopStationIDList[ stopStationIDList.findIndex((d) => d.includes("U14")) - 1 @@ -281,7 +290,7 @@ export const EachTrainInfoCore = ({ setCurrentPosition(position); } - }, [currentTrainData]); + }, [currentTrainData,stopStationIDList]); useEffect(() => { //列車現在地アイコン表示スイッチ @@ -294,7 +303,7 @@ export const EachTrainInfoCore = ({ const customTrainType = getTrainType({ type: customTrainDataDetector(data.trainNum, allCustomTrainData).type, }); - + const openTrainInfo = (d) => { const train = customTrainDataDetector(d, allCustomTrainData); let TrainNumber = ""; @@ -365,9 +374,7 @@ export const EachTrainInfoCore = ({ style: { maxHeight: isLandscape ? height - 94 : (height / 100) * 70, backgroundColor: - customTrainType.data === "notService" - ? "#777777ff" - : "white", + customTrainType.data === "notService" ? "#777777ff" : "white", }, }} shortHeader={ diff --git a/components/Apps/FixedPositionBox/FixedTrainBox.tsx b/components/Apps/FixedPositionBox/FixedTrainBox.tsx index 4a2fb29..4fdd11b 100644 --- a/components/Apps/FixedPositionBox/FixedTrainBox.tsx +++ b/components/Apps/FixedPositionBox/FixedTrainBox.tsx @@ -34,8 +34,13 @@ export const FixedTrain: FC = ({ displaySize, setDisplaySize, }) => { - const {fixedPosition, setFixedPosition, currentTrain, getCurrentStationData, getPosition } = - useCurrentTrain(); + const { + fixedPosition, + setFixedPosition, + currentTrain, + getCurrentStationData, + getPosition, + } = useCurrentTrain(); const { mapSwitch } = useTrainMenu(); const { allCustomTrainData, allTrainDiagram } = useAllTrainDiagram(); @@ -53,8 +58,7 @@ export const FixedTrain: FC = ({ const stationData = getCurrentStationData(trainID); if (stationData) { setTrain(stationData); - } - else{ + } else { alert("追跡していた列車が消えました。追跡を終了します。"); setFixedPosition({ type: null, value: null }); } @@ -133,22 +137,27 @@ export const FixedTrain: FC = ({ }); setTrainDataWithThrough(mainArray); }, [allTrainDiagram, stationList, trainID]); - const stopStationIDList = trainDataWidhThrough.map((i) => { - const [station, se, time] = i.split(","); - const Stations = stationList.map((a) => - a.filter((d) => d.StationName == station) - ); - const StationNumbers = - Stations && - Stations.reduce((newArray, e) => { - return newArray.concat(e); - }, []).map((d) => d.StationNumber); - return StationNumbers; - }); + const [stopStationIDList, setStopStationList] = useState([]); + useEffect(() => { + const x = trainDataWidhThrough.map((i) => { + const [station, se, time] = i.split(","); + const Stations = stationList.map((a) => + a.filter((d) => d.StationName == station) + ); + const StationNumbers = + Stations && + Stations.reduce((newArray, e) => { + return newArray.concat(e); + }, []).map((d) => d.StationNumber); + return StationNumbers; + }); + setStopStationList(x); + }, [trainDataWidhThrough]); const [currentPosition, setCurrentPosition] = useState([]); useEffect(() => { let position = getPosition(train); + if (stopStationIDList.length == 0) return; if (position) { if (position.length > 1) { if (position[0] == "-Iyo") { @@ -177,7 +186,7 @@ export const FixedTrain: FC = ({ setCurrentPosition(position); } - }, [train]); + }, [train,stopStationIDList]); const [nextStationData, setNextStationData] = useState([]); const [untilStationData, setUntilStationData] = useState([]); diff --git a/lib/eachTrainInfoCoreLib/findReversalPoints.js b/lib/eachTrainInfoCoreLib/findReversalPoints.js index 0f37283..f1f62f2 100644 --- a/lib/eachTrainInfoCoreLib/findReversalPoints.js +++ b/lib/eachTrainInfoCoreLib/findReversalPoints.js @@ -31,10 +31,17 @@ export const findReversalPoints = (array, stopStationIDList) => { } } return false; + } else if (array[0] == "U15" && array[1] == "U14") { + + return d[0] == "U13" ? true : false; + } else if (array[0] == "S17" && array[1] == "U14") { + + return d[0] == "U14" ? true : false; } let returndata = false; d.forEach((x) => { + console.log(array, x, d); if (array[0] < x && x < array[1]) { returndata = true; } else if (array[0] < x && x == array[1]) { diff --git a/stateBox/useCurrentTrain.tsx b/stateBox/useCurrentTrain.tsx index 53c530c..ffbcc56 100644 --- a/stateBox/useCurrentTrain.tsx +++ b/stateBox/useCurrentTrain.tsx @@ -112,7 +112,7 @@ export const CurrentTrainProvider: FC = ({ children }) => { currentTrainData: trainDataType ) => string[] | undefined; const getPosition: getPositionFuncType = (currentTrainData) => { - //currentTrainData.Pos = "鴨川~端岡"; //test + //currentTrainData = {Pos:"伊予若宮~伊予大洲"}; //test if (!currentTrainData) return; if (!currentTrainData?.Pos) return; if (currentTrainData?.Pos.match("~")) { diff --git a/stateBox/useStationList.tsx b/stateBox/useStationList.tsx index 9b3e737..e760e6e 100644 --- a/stateBox/useStationList.tsx +++ b/stateBox/useStationList.tsx @@ -127,7 +127,8 @@ export const StationListProvider: FC = ({ children }) => { }); } }); - if (bootStationList[0].line === undefined) return ""; + console.log(bootStationList[0]); + if (bootStationList[0] === undefined) return ""; return `MoveDisplayStation('${bootStationList[0].line}_${bootStationList[0].station.MyStation}_${bootStationList[0].station.Station_JP}');document.getElementById("disp").insertAdjacentHTML("afterbegin", "
");setReload();`; };