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