一部ロジックの短縮化
This commit is contained in:
parent
5115656050
commit
b2ee75205b
@ -403,12 +403,12 @@ const EachData = ({
|
|||||||
|
|
||||||
const TrainName = ({ train, trainIDSwitch, d, getTrainType }) => {
|
const TrainName = ({ train, trainIDSwitch, d, getTrainType }) => {
|
||||||
const { trainName, trainNumDistance } = train;
|
const { trainName, trainNumDistance } = train;
|
||||||
let TrainNumber = "";
|
let TrainNumber =
|
||||||
if (trainNumDistance != undefined) {
|
trainNumDistance != undefined
|
||||||
const timeInfo =
|
? `${
|
||||||
parseInt(d.train.replace("M", "").replace("D", "")) - trainNumDistance;
|
parseInt(d.train.replace("M", "").replace("D", "")) - trainNumDistance
|
||||||
TrainNumber = timeInfo + "号";
|
}号`
|
||||||
}
|
: "";
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 9 }}>
|
<View style={{ flex: 9 }}>
|
||||||
<Text
|
<Text
|
||||||
@ -426,23 +426,22 @@ const TrainName = ({ train, trainIDSwitch, d, getTrainType }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const LastStation = ({ d }) => {
|
const LastStation = ({ d: { lastStation } }) => {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 4, flexDirection: "row" }}>
|
<View style={{ flex: 4, flexDirection: "row" }}>
|
||||||
<Text
|
<Text
|
||||||
style={{
|
style={{
|
||||||
fontSize:
|
fontSize: lastStation.length > 4 ? parseInt("13%") : parseInt("18%"),
|
||||||
d.lastStation.length > 4 ? parseInt("13%") : parseInt("18%"),
|
|
||||||
color: "white",
|
color: "white",
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{d.lastStation}
|
{lastStation}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const DependTime = ({ d }) => {
|
const DependTime = ({ d: { time } }) => {
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 3 }}>
|
<View style={{ flex: 3 }}>
|
||||||
<Text
|
<Text
|
||||||
@ -452,7 +451,7 @@ const DependTime = ({ d }) => {
|
|||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{d.time}
|
{time}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@ -464,34 +463,28 @@ const checkDuplicateTrainData = (currentTrainArray) => {
|
|||||||
if (notNyujoData.length == 0) return currentTrainArray[0];
|
if (notNyujoData.length == 0) return currentTrainArray[0];
|
||||||
else return notNyujoData[0];
|
else return notNyujoData[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
|
const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
|
||||||
const [status, setStatus] = useState("");
|
// 土讃線複数存在対策
|
||||||
useEffect(() => {
|
const getTrainDelayStatus = (current) => {
|
||||||
const array = currentTrain.filter((a) => a.num == d.train);
|
|
||||||
const current = checkDuplicateTrainData(array);
|
|
||||||
// 土讃線複数存在対策
|
|
||||||
if (!current) return () => {};
|
if (!current) return () => {};
|
||||||
const delay = current.delay;
|
const delay = current.delay;
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case delay === "入線":
|
case delay === "入線":
|
||||||
if (current.Pos === station.Station_JP) {
|
if (current.Pos === station.Station_JP) {
|
||||||
setStatus("当駅始発");
|
return "当駅始発";
|
||||||
break;
|
|
||||||
} else {
|
} else {
|
||||||
setStatus("発車前");
|
return "発車前";
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case isNaN(delay):
|
case isNaN(delay):
|
||||||
setStatus(delay);
|
return delay;
|
||||||
break;
|
|
||||||
case delay === 0:
|
case delay === 0:
|
||||||
setStatus("定刻通り");
|
return "定刻通り";
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
setStatus(delay + "分遅れ");
|
return delay + "分遅れ";
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}, [currentTrain, d.train, trainDescriptionSwitch]);
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{ flex: 4 }}>
|
<View style={{ flex: 4 }}>
|
||||||
<Text
|
<Text
|
||||||
@ -502,11 +495,14 @@ const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
|
|||||||
paddingLeft: 1,
|
paddingLeft: 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{status}
|
{getTrainDelayStatus(
|
||||||
|
checkDuplicateTrainData(currentTrain.filter((a) => a.num == d.train))
|
||||||
|
)}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Description = ({ train }) => {
|
const Description = ({ train }) => {
|
||||||
return (
|
return (
|
||||||
<View
|
<View
|
||||||
|
Loading…
Reference in New Issue
Block a user