LEDVisionのエラーfallback対策&始発駅表記の対応
This commit is contained in:
parent
1ef8870153
commit
cb94b545dc
@ -4,6 +4,7 @@ import { Switch } from "react-native-elements";
|
||||
import { widthPercentageToDP as wp } from "react-native-responsive-screen";
|
||||
import { customTrainDataDetector } from "../custom-train-data";
|
||||
import { useInterval } from "../../lib/useInterval";
|
||||
import trainList from "../../assets/originData/trainList";
|
||||
|
||||
let diagramData = undefined;
|
||||
|
||||
@ -56,6 +57,7 @@ export default function LED_vision(props) {
|
||||
)
|
||||
.then((response) => response.text())
|
||||
.then((d) => {
|
||||
if (d.indexOf("<title>404 Not Found</title>") != -1) throw Error;
|
||||
const val = d.replace("[\r\n", "").split(",\r\n");
|
||||
let trainDiagram = {};
|
||||
val.forEach((element) => {
|
||||
@ -79,6 +81,21 @@ export default function LED_vision(props) {
|
||||
}
|
||||
});
|
||||
setStationDiagram(returnData);
|
||||
})
|
||||
.catch((d) => {
|
||||
console.log("fallback");
|
||||
setTrainDiagram(trainList);
|
||||
let returnData = {};
|
||||
if (!trainList) {
|
||||
setStationDiagram(returnData);
|
||||
return;
|
||||
}
|
||||
Object.keys(trainList).forEach((key) => {
|
||||
if (trainList[key].match(props.station.Station_JP)) {
|
||||
returnData[key] = trainList[key];
|
||||
}
|
||||
});
|
||||
setStationDiagram(returnData);
|
||||
});
|
||||
}, []);
|
||||
|
||||
@ -122,10 +139,14 @@ export default function LED_vision(props) {
|
||||
HeaderConfig
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then((d) => d.map((x) => ({ num: x.TrainNum, delay: x.delay })))
|
||||
.then((d) =>
|
||||
d.map((x) => ({ num: x.TrainNum, delay: x.delay, Pos: x.Pos }))
|
||||
)
|
||||
.then(setCurrentTrain);
|
||||
|
||||
useEffect(getCurrentTrain, []);
|
||||
useEffect(() => {
|
||||
getCurrentTrain();
|
||||
}, []);
|
||||
|
||||
useInterval(getCurrentTrain, 15000);
|
||||
|
||||
@ -145,6 +166,18 @@ export default function LED_vision(props) {
|
||||
|
||||
return false;
|
||||
};
|
||||
const getTrainType = (data) => {
|
||||
switch (data) {
|
||||
case "Rapid":
|
||||
return { color: "aqua", name: "快速" };
|
||||
case "LTDEXP":
|
||||
return { color: "red", name: "特急" };
|
||||
case "NightLTDEXP":
|
||||
return { color: "red", name: "寝台特急" };
|
||||
case "Normal":
|
||||
return { color: "white", name: "普通列車" };
|
||||
}
|
||||
};
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
@ -192,40 +225,19 @@ export default function LED_vision(props) {
|
||||
backgroundColor: "#000",
|
||||
flexDirection: "row",
|
||||
}}
|
||||
key={d.train}
|
||||
>
|
||||
<View style={{ flex: 9 }}>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: train.trainName.length > 6 ? 15 : 20,
|
||||
color: (() => {
|
||||
switch (train.type) {
|
||||
case "Rapid":
|
||||
return "aqua";
|
||||
case "LTDEXP":
|
||||
return "red";
|
||||
case "NightLTDEXP":
|
||||
return "red";
|
||||
case "Normal":
|
||||
return "white";
|
||||
}
|
||||
})(),
|
||||
color: getTrainType(train.type).color,
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
>
|
||||
{trainIDSwitch
|
||||
? d.train
|
||||
: (() => {
|
||||
switch (train.type) {
|
||||
case "Rapid":
|
||||
return "快速";
|
||||
case "LTDEXP":
|
||||
return "特急";
|
||||
case "NightLTDEXP":
|
||||
return "寝台特急";
|
||||
case "Normal":
|
||||
return "普通列車";
|
||||
}
|
||||
})() +
|
||||
: getTrainType(train.type).name +
|
||||
" " +
|
||||
train.trainName +
|
||||
(train.trainNumDistance == undefined
|
||||
@ -268,10 +280,18 @@ export default function LED_vision(props) {
|
||||
}}
|
||||
>
|
||||
{(() => {
|
||||
const delay = currentTrain.filter(
|
||||
const current = currentTrain.filter(
|
||||
(a) => a.num == d.train
|
||||
)[0].delay;
|
||||
)[0];
|
||||
const delay = current.delay;
|
||||
switch (true) {
|
||||
case delay == "入線":
|
||||
if (current.Pos == props.station.Station_JP) {
|
||||
return "当駅始発";
|
||||
} else {
|
||||
return "発車前";
|
||||
}
|
||||
|
||||
case isNaN(delay):
|
||||
return delay;
|
||||
case delay == 0:
|
||||
|
@ -18,6 +18,18 @@ import train_lang from "../assets/originData/train_lang";
|
||||
|
||||
let status = undefined;
|
||||
|
||||
export const lineList = [
|
||||
"予讃線",
|
||||
"松宇線",
|
||||
"伊予灘線",
|
||||
"土讃線",
|
||||
"窪川線",
|
||||
"高徳線",
|
||||
"徳島線",
|
||||
"鳴門線",
|
||||
"瀬戸大橋線",
|
||||
];
|
||||
|
||||
export const getStationList = async (props) => {
|
||||
if (status) return status;
|
||||
//駅リストイニシャライズ
|
||||
|
Loading…
Reference in New Issue
Block a user