引数の調整とgetTrainTypeの分離

This commit is contained in:
harukin-OneMix4 2023-07-06 02:16:48 +09:00
parent b2ee75205b
commit 52b15288b9
2 changed files with 28 additions and 27 deletions

View File

@ -9,6 +9,7 @@ import { useInterval } from "../../lib/useInterval";
import trainList from "../../assets/originData/trainList";
import { objectIsEmpty } from "../../lib/objectIsEmpty";
import { parseAllTrainDiagram } from "../../lib/parseAllTrainDiagram";
import { getTrainType } from "../../lib/getTrainType";
let diagramData = undefined;
@ -332,18 +333,6 @@ const EachData = ({
setTrainInfo,
EachTrainInfoAsSR,
}) => {
const getTrainType = (data) => {
switch (data) {
case "Rapid":
return { color: "aqua", name: "快速", data: "rapid" };
case "LTDEXP":
return { color: "red", name: "特急", data: "express" };
case "NightLTDEXP":
return { color: "red", name: "寝台特急", data: "express" };
case "Normal":
return { color: "white", name: "普通列車", data: "normal" };
}
};
const openTrainInfo = (d) => {
console.log(train);
console.log(d);
@ -387,16 +376,13 @@ const EachData = ({
d={d}
getTrainType={getTrainType(train.type)}
/>
<LastStation d={d} />
<DependTime d={d} />
<StatusAndDelay
currentTrain={currentTrain}
d={d}
props={props}
trainDescriptionSwitch={trainDescriptionSwitch}
/>
<LastStation lastStation={d.lastStation} />
<DependTime time={d.time} />
<StatusAndDelay currentTrain={currentTrain} train={d.train} />
</TouchableOpacity>
{trainDescriptionSwitch && !!train.info && <Description train={train} />}
{trainDescriptionSwitch && !!train.info && (
<Description info={train.info} />
)}
</>
);
};
@ -426,7 +412,7 @@ const TrainName = ({ train, trainIDSwitch, d, getTrainType }) => {
);
};
const LastStation = ({ d: { lastStation } }) => {
const LastStation = ({ lastStation }) => {
return (
<View style={{ flex: 4, flexDirection: "row" }}>
<Text
@ -441,7 +427,8 @@ const LastStation = ({ d: { lastStation } }) => {
</View>
);
};
const DependTime = ({ d: { time } }) => {
const DependTime = ({ time }) => {
return (
<View style={{ flex: 3 }}>
<Text
@ -464,7 +451,7 @@ const checkDuplicateTrainData = (currentTrainArray) => {
else return notNyujoData[0];
};
const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
const StatusAndDelay = ({ currentTrain, train }) => {
// 土讃線複数存在対策
const getTrainDelayStatus = (current) => {
if (!current) return () => {};
@ -496,14 +483,14 @@ const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
}}
>
{getTrainDelayStatus(
checkDuplicateTrainData(currentTrain.filter((a) => a.num == d.train))
checkDuplicateTrainData(currentTrain.filter((a) => a.num == train))
)}
</Text>
</View>
);
};
const Description = ({ train }) => {
const Description = ({ info }) => {
return (
<View
style={{
@ -525,7 +512,7 @@ const Description = ({ train }) => {
}}
>
{" "}
&gt; {train.info}
&gt; {info}
</Text>
</View>
</View>

14
lib/getTrainType.js Normal file
View File

@ -0,0 +1,14 @@
export const getTrainType = (data) => {
switch (data) {
case "Rapid":
return { color: "aqua", name: "快速", data: "rapid" };
case "LTDEXP":
return { color: "red", name: "特急", data: "express" };
case "NightLTDEXP":
return { color: "red", name: "寝台特急", data: "express" };
case "Normal":
return { color: "white", name: "普通列車", data: "normal" };
default:
return { color: "white", name: "その他", data: "normal" };
}
};