引数の調整と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 trainList from "../../assets/originData/trainList";
import { objectIsEmpty } from "../../lib/objectIsEmpty"; import { objectIsEmpty } from "../../lib/objectIsEmpty";
import { parseAllTrainDiagram } from "../../lib/parseAllTrainDiagram"; import { parseAllTrainDiagram } from "../../lib/parseAllTrainDiagram";
import { getTrainType } from "../../lib/getTrainType";
let diagramData = undefined; let diagramData = undefined;
@ -332,18 +333,6 @@ const EachData = ({
setTrainInfo, setTrainInfo,
EachTrainInfoAsSR, 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) => { const openTrainInfo = (d) => {
console.log(train); console.log(train);
console.log(d); console.log(d);
@ -387,16 +376,13 @@ const EachData = ({
d={d} d={d}
getTrainType={getTrainType(train.type)} getTrainType={getTrainType(train.type)}
/> />
<LastStation d={d} /> <LastStation lastStation={d.lastStation} />
<DependTime d={d} /> <DependTime time={d.time} />
<StatusAndDelay <StatusAndDelay currentTrain={currentTrain} train={d.train} />
currentTrain={currentTrain}
d={d}
props={props}
trainDescriptionSwitch={trainDescriptionSwitch}
/>
</TouchableOpacity> </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 ( return (
<View style={{ flex: 4, flexDirection: "row" }}> <View style={{ flex: 4, flexDirection: "row" }}>
<Text <Text
@ -441,7 +427,8 @@ const LastStation = ({ d: { lastStation } }) => {
</View> </View>
); );
}; };
const DependTime = ({ d: { time } }) => {
const DependTime = ({ time }) => {
return ( return (
<View style={{ flex: 3 }}> <View style={{ flex: 3 }}>
<Text <Text
@ -464,7 +451,7 @@ const checkDuplicateTrainData = (currentTrainArray) => {
else return notNyujoData[0]; else return notNyujoData[0];
}; };
const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => { const StatusAndDelay = ({ currentTrain, train }) => {
// 土讃線複数存在対策 // 土讃線複数存在対策
const getTrainDelayStatus = (current) => { const getTrainDelayStatus = (current) => {
if (!current) return () => {}; if (!current) return () => {};
@ -496,14 +483,14 @@ const StatusAndDelay = ({ currentTrain, d, props, trainDescriptionSwitch }) => {
}} }}
> >
{getTrainDelayStatus( {getTrainDelayStatus(
checkDuplicateTrainData(currentTrain.filter((a) => a.num == d.train)) checkDuplicateTrainData(currentTrain.filter((a) => a.num == train))
)} )}
</Text> </Text>
</View> </View>
); );
}; };
const Description = ({ train }) => { const Description = ({ info }) => {
return ( return (
<View <View
style={{ style={{
@ -525,7 +512,7 @@ const Description = ({ train }) => {
}} }}
> >
{" "} {" "}
&gt; {train.info} &gt; {info}
</Text> </Text>
</View> </View>
</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" };
}
};