項目の最適化
This commit is contained in:
		| @@ -38,7 +38,14 @@ export const TrainDataView = ({ | |||||||
|       .then((res) => res.json()) |       .then((res) => res.json()) | ||||||
|       .then((data) => { |       .then((data) => { | ||||||
|         if (!data) return; |         if (!data) return; | ||||||
|         const {type, stationName, lineNumber, platformNumber, position, description} = data; |         const { | ||||||
|  |           type, | ||||||
|  |           stationName, | ||||||
|  |           lineNumber, | ||||||
|  |           platformNumber, | ||||||
|  |           position, | ||||||
|  |           description, | ||||||
|  |         } = data; | ||||||
|         if (type == "Station") { |         if (type == "Station") { | ||||||
|           setLineNumber(lineNumber); |           setLineNumber(lineNumber); | ||||||
|           setPlatformNumber(platformNumber); |           setPlatformNumber(platformNumber); | ||||||
| @@ -55,10 +62,8 @@ export const TrainDataView = ({ | |||||||
|   }, []); |   }, []); | ||||||
|   const onLine = !!currentPosition?.toString().length; |   const onLine = !!currentPosition?.toString().length; | ||||||
|   const [dialog, setDialog] = useState(false); |   const [dialog, setDialog] = useState(false); | ||||||
|   const [deleteDialog, setDeleteDialog] = useState(false); |  | ||||||
|   const [posInput, setPosInput] = useState(""); |   const [posInput, setPosInput] = useState(""); | ||||||
|   const [descInput, setDescInput] = useState(""); |   const [descInput, setDescInput] = useState(""); | ||||||
|   const [stationInput, setStationInput] = useState(""); |  | ||||||
|   const [stationNumberInput, setStationNumberInput] = useState(""); |   const [stationNumberInput, setStationNumberInput] = useState(""); | ||||||
|   const [lineInput, setLineInput] = useState(""); |   const [lineInput, setLineInput] = useState(""); | ||||||
|   return ( |   return ( | ||||||
| @@ -67,18 +72,13 @@ export const TrainDataView = ({ | |||||||
|         dialog={dialog} |         dialog={dialog} | ||||||
|         setDialog={setDialog} |         setDialog={setDialog} | ||||||
|         currentTrainData={currentTrainData} |         currentTrainData={currentTrainData} | ||||||
|         stationInput={stationInput} |  | ||||||
|         stationNumberInput={stationNumberInput} |         stationNumberInput={stationNumberInput} | ||||||
|         posInput={posInput} |  | ||||||
|         descInput={descInput} |  | ||||||
|         setPosInput={setPosInput} |  | ||||||
|         setDescInput={setDescInput} |  | ||||||
|         lineInput={lineInput} |         lineInput={lineInput} | ||||||
|         setLineInput={setLineInput} |         setLineInput={setLineInput} | ||||||
|         station={{ |         posInput={posInput} | ||||||
|           Station_JP: currentTrainData?.Pos, |         setPosInput={setPosInput} | ||||||
|           StationNumber: currentPosition[0], |         descInput={descInput} | ||||||
|         }} |         setDescInput={setDescInput} | ||||||
|       /> |       /> | ||||||
|       <View |       <View | ||||||
|         style={{ |         style={{ | ||||||
| @@ -100,15 +100,12 @@ export const TrainDataView = ({ | |||||||
|                 platformDescription == undefined |                 platformDescription == undefined | ||||||
|               ) |               ) | ||||||
|                 return; |                 return; | ||||||
|               setStationInput(`${Pos.from}→${Pos.to}間`); |  | ||||||
|               setStationNumberInput( |               setStationNumberInput( | ||||||
|                 getStationID(currentTrainData?.Pos, stationList) |                 getStationID(currentTrainData?.Pos, stationList) | ||||||
|               ); |               ); | ||||||
|               setPosInput(platformNumber?.toString() || ""); |               setPosInput(platformNumber?.toString() || ""); | ||||||
|               setLineInput(lineNumber?.toString() || ""); |               setLineInput(lineNumber?.toString() || ""); | ||||||
|               setDeleteDialog(true); |  | ||||||
|             } else { |             } else { | ||||||
|               setStationInput(Pos.Pos); |  | ||||||
|               setStationNumberInput( |               setStationNumberInput( | ||||||
|                 getStationID(currentTrainData?.Pos, stationList) |                 getStationID(currentTrainData?.Pos, stationList) | ||||||
|               ); |               ); | ||||||
| @@ -147,7 +144,7 @@ export const TrainDataView = ({ | |||||||
|             currentTrainData={currentTrainData} |             currentTrainData={currentTrainData} | ||||||
|             platformNumber={platformNumber} |             platformNumber={platformNumber} | ||||||
|             lineNumber={lineNumber} |             lineNumber={lineNumber} | ||||||
|             platformDescription={platformDescription ? `${platformDescription}` : ""} |             platformDescription={platformDescription || ""} | ||||||
|             style={ |             style={ | ||||||
|               onLine |               onLine | ||||||
|                 ? { borderWidth: 1, borderColor: "red", borderStyle: "solid" } |                 ? { borderWidth: 1, borderColor: "red", borderStyle: "solid" } | ||||||
|   | |||||||
| @@ -1,6 +1,5 @@ | |||||||
| import React, { FC, useEffect, useState } from "react"; | import React, { FC, useEffect, useState } from "react"; | ||||||
| import { Linking, TouchableOpacity, Text } from "react-native"; | import { TouchableOpacity } from "react-native"; | ||||||
| import { Dialog, Button, Input } from "react-native-elements"; |  | ||||||
| import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData"; | import { checkDuplicateTrainData } from "../../lib/checkDuplicateTrainData"; | ||||||
| import { getTrainDelayStatus } from "../../lib/getTrainDelayStatus"; | import { getTrainDelayStatus } from "../../lib/getTrainDelayStatus"; | ||||||
| import { getTrainType } from "../../lib/getTrainType"; | import { getTrainType } from "../../lib/getTrainType"; | ||||||
| @@ -158,15 +157,13 @@ export const EachData: FC<Props> = (props) => { | |||||||
|         setDialog={setDialog} |         setDialog={setDialog} | ||||||
|         {...{ |         {...{ | ||||||
|           currentTrainData, |           currentTrainData, | ||||||
|           stationInput, |  | ||||||
|           stationNumberInput, |           stationNumberInput, | ||||||
|           posInput, |  | ||||||
|           descInput, |  | ||||||
|           setPosInput, |  | ||||||
|           setDescInput, |  | ||||||
|           station, |  | ||||||
|           lineInput, |           lineInput, | ||||||
|           setLineInput, |           setLineInput, | ||||||
|  |           posInput, | ||||||
|  |           setPosInput, | ||||||
|  |           descInput, | ||||||
|  |           setDescInput | ||||||
|         }} |         }} | ||||||
|       /> |       /> | ||||||
|       <TouchableOpacity |       <TouchableOpacity | ||||||
| @@ -218,6 +215,8 @@ export const EachData: FC<Props> = (props) => { | |||||||
|           setPlatformNumber={setPlatformNumber} |           setPlatformNumber={setPlatformNumber} | ||||||
|           platformDescription={platformDescription} |           platformDescription={platformDescription} | ||||||
|           platformNumber={platformNumber} |           platformNumber={platformNumber} | ||||||
|  |           lineInput={lineInput} | ||||||
|  |           setLineInput={setLineInput} | ||||||
|           key={d.train + "-trainPosition"} |           key={d.train + "-trainPosition"} | ||||||
|         /> |         /> | ||||||
|       )} |       )} | ||||||
|   | |||||||
| @@ -1,4 +1,4 @@ | |||||||
| import React, { FC, useEffect } from "react"; | import React, { FC, useEffect, useState } from "react"; | ||||||
| import { Text, TextStyle, View, TouchableOpacity } from "react-native"; | import { Text, TextStyle, View, TouchableOpacity } from "react-native"; | ||||||
| import { useStationList } from "../../../stateBox/useStationList"; | import { useStationList } from "../../../stateBox/useStationList"; | ||||||
| import { | import { | ||||||
| @@ -24,9 +24,11 @@ type Props = { | |||||||
|   setDialog: (dialog: boolean) => void; |   setDialog: (dialog: boolean) => void; | ||||||
|   setDeleteDialog: (dialog: boolean) => void; |   setDeleteDialog: (dialog: boolean) => void; | ||||||
|   platformDescription: string; |   platformDescription: string; | ||||||
|   platformNumber: number; |   platformNumber: string; | ||||||
|   setPlatformDescription: (desc: string) => void; |   setPlatformDescription: (desc: string) => void; | ||||||
|   setPlatformNumber: (num: number) => void; |   setPlatformNumber: (num: string) => void; | ||||||
|  |   lineInput: string; | ||||||
|  |   setLineInput: (line: string) => void; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| export const TrainPosition: FC<Props> = ({ | export const TrainPosition: FC<Props> = ({ | ||||||
| @@ -43,27 +45,55 @@ export const TrainPosition: FC<Props> = ({ | |||||||
|   setPlatformNumber, |   setPlatformNumber, | ||||||
|   platformDescription, |   platformDescription, | ||||||
|   platformNumber, |   platformNumber, | ||||||
|  |   setLineInput, | ||||||
| }) => { | }) => { | ||||||
|   const { currentTrain } = useCurrentTrain(); |  | ||||||
|   const { stationList } = useStationList(); |   const { stationList } = useStationList(); | ||||||
|  |   type data = { | ||||||
|  |     type: string; | ||||||
|  |     lineNumber: string; | ||||||
|  |     platformNumber: string; | ||||||
|  |     position: string; | ||||||
|  |     stationName: string; | ||||||
|  |     description: string; | ||||||
|  |   }; | ||||||
|  |   const [database, setDatabase] = useState<data>(null); | ||||||
|  |   const [text, setText] = useState(""); | ||||||
|  |   const [masterText, setMasterText] = useState(""); | ||||||
|  |   useEffect(() => { | ||||||
|  |     const text = `${currentTrainData?.PosNum} ${currentTrainData?.Line} ${currentTrainData?.Pos}`; | ||||||
|  |     setText(trainIDSwitch ? text : masterText); | ||||||
|  |     return () => { | ||||||
|  |       setText(""); | ||||||
|  |     }; | ||||||
|  |   }, [masterText, trainIDSwitch]); | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|     fetch( |     fetch( | ||||||
|       `https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3?PosId=${currentTrainData?.PosNum}&lineName=${currentTrainData?.Line}&StationName=${currentTrainData?.Pos}` |       `https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3?PosId=${currentTrainData?.PosNum}&lineName=${currentTrainData?.Line}&StationName=${currentTrainData?.Pos}` | ||||||
|     ) |     ) | ||||||
|       .then((res) => res.json()) |       .then((res) => res.json()) | ||||||
|       .then((data: { type: string; platform: number; description: string }) => { |       .then((data: data) => { | ||||||
|         const { type, platform, description } = data; |         const { type, platformNumber, description, lineNumber } = data; | ||||||
|         setPlatformNumber(type == "Station" ? platform : undefined); |         setDatabase(data); | ||||||
|         setPlatformDescription(type == "Station" ? description : undefined); |         const { isBetween, Pos } = trainPosition(currentTrainData); | ||||||
|  |         if (isBetween === true) { | ||||||
|  |           // 移動中 | ||||||
|  |           setMasterText(`現在地:${Pos.from}→${Pos.to}間を走行中`); | ||||||
|  |         } else { | ||||||
|  |           if (Pos.Pos) { | ||||||
|  |             let platform = platformNumber ? `${platformNumber}番乗り場` : ""; | ||||||
|  |             let line = lineNumber ? `${lineNumber}番線` : ""; | ||||||
|  |             setMasterText( | ||||||
|  |               `現在地:${Pos.Pos}  ${platform || line} ${description || ""}` | ||||||
|  |             ); | ||||||
|  |           } else { | ||||||
|  |             setMasterText(""); | ||||||
|  |           } | ||||||
|  |         } | ||||||
|       }); |       }); | ||||||
|   }, [currentTrainData, currentTrain]); |     return () => { | ||||||
|  |       setMasterText(""); | ||||||
|   const trainPositionText = (trainData: trainDataType) => { |  | ||||||
|     const { isBetween, Pos } = trainPosition(trainData); |  | ||||||
|     if (isBetween === true) return `現在地:${Pos.from}→${Pos.to}間を走行中`; |  | ||||||
|     else return Pos.Pos == "" ? "" : `現在地:${Pos.Pos}`; |  | ||||||
|     }; |     }; | ||||||
|  |   }, [currentTrainData?.PosNum, currentTrainData?.Line, currentTrainData?.Pos]); | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <TouchableOpacity |     <TouchableOpacity | ||||||
| @@ -79,22 +109,18 @@ export const TrainPosition: FC<Props> = ({ | |||||||
|       }} |       }} | ||||||
|       onLongPress={() => { |       onLongPress={() => { | ||||||
|         const { isBetween, Pos } = trainPosition(currentTrainData); |         const { isBetween, Pos } = trainPosition(currentTrainData); | ||||||
|  |         setStationNumberInput(getStationID(currentTrainData?.Pos, stationList)); | ||||||
|  |         setPosInput(database?.platformNumber?.toString() || ""); | ||||||
|         if (isBetween === true) { |         if (isBetween === true) { | ||||||
|           if (platformNumber == undefined && platformDescription == undefined) |           if (database?.platformNumber == undefined && database?.description == undefined) | ||||||
|             return; |             return; | ||||||
|           setStationInput(`${Pos.from}→${Pos.to}間`); |           setStationInput(`${Pos.from}→${Pos.to}間`); | ||||||
|           setStationNumberInput( |  | ||||||
|             getStationID(currentTrainData?.Pos, stationList) |  | ||||||
|           ); |  | ||||||
|           setPosInput(platformNumber?.toString() || ""); |  | ||||||
|           setDeleteDialog(true); |           setDeleteDialog(true); | ||||||
|         } else { |         } else { | ||||||
|           setStationInput(Pos.Pos); |           setStationInput(currentTrainData?.Pos); | ||||||
|           setStationNumberInput( |           setDescInput(database?.description || ""); | ||||||
|             getStationID(currentTrainData?.Pos, stationList) |           setLineInput(database?.lineNumber?.toString() || ""); | ||||||
|           ); |           setPlatformNumber(database?.platformNumber?.toString() || ""); | ||||||
|           setDescInput(platformDescription || ""); |  | ||||||
|           setPosInput(platformNumber?.toString() || ""); |  | ||||||
|           setDialog(true); |           setDialog(true); | ||||||
|         } |         } | ||||||
|       }} |       }} | ||||||
| @@ -104,13 +130,7 @@ export const TrainPosition: FC<Props> = ({ | |||||||
|           style={{ ...descriptionStyle, color: "green" }} |           style={{ ...descriptionStyle, color: "green" }} | ||||||
|           numberOfLines={numberOfLines} |           numberOfLines={numberOfLines} | ||||||
|         > |         > | ||||||
|           {`${ |           {text} | ||||||
|             trainIDSwitch |  | ||||||
|               ? currentTrainData?.PosNum + currentTrainData?.Line |  | ||||||
|               : trainPositionText(currentTrainData) |  | ||||||
|           } ${platformNumber ? platformNumber + "番線" : ""} ${ |  | ||||||
|             platformDescription ? "(" + platformDescription + ")" : "" |  | ||||||
|           }`} |  | ||||||
|         </Text> |         </Text> | ||||||
|       </View> |       </View> | ||||||
|     </TouchableOpacity> |     </TouchableOpacity> | ||||||
|   | |||||||
| @@ -1,13 +1,13 @@ | |||||||
| import React, { FC, useState } from "react"; | import React, { FC } from "react"; | ||||||
| import { Text } from "react-native"; | import { Text } from "react-native"; | ||||||
| import { Dialog, Input, Button } from "react-native-elements"; | import { Dialog, Input, Button } from "react-native-elements"; | ||||||
| import { trainDataType } from "../../../lib/trainPositionTextArray"; | import { trainDataType } from "../../../lib/trainPositionTextArray"; | ||||||
| import { useCurrentTrain } from "../../../stateBox/useCurrentTrain"; | import { getStationID } from "@/lib/eachTrainInfoCoreLib/getStationData"; | ||||||
|  | import { useStationList } from "@/stateBox/useStationList"; | ||||||
| type Props = { | type Props = { | ||||||
|   dialog: boolean; |   dialog: boolean; | ||||||
|   setDialog: (dialog: boolean) => void; |   setDialog: (dialog: boolean) => void; | ||||||
|   currentTrainData: trainDataType; |   currentTrainData: trainDataType; | ||||||
|   stationInput: string; |  | ||||||
|   stationNumberInput: string; |   stationNumberInput: string; | ||||||
|   posInput: string; |   posInput: string; | ||||||
|   descInput: string; |   descInput: string; | ||||||
| @@ -15,37 +15,33 @@ type Props = { | |||||||
|   setPosInput: (pos: string) => void; |   setPosInput: (pos: string) => void; | ||||||
|   setDescInput: (desc: string) => void; |   setDescInput: (desc: string) => void; | ||||||
|   setLineInput: (line: string) => void; |   setLineInput: (line: string) => void; | ||||||
|   station: { |  | ||||||
|     Station_JP: string; |  | ||||||
|     StationNumber: string; |  | ||||||
|   }; |  | ||||||
| }; | }; | ||||||
| export const TrainPositionDataPush: FC<Props> = ({ | export const TrainPositionDataPush: FC<Props> = ({ | ||||||
|   dialog, |   dialog, | ||||||
|   setDialog, |   setDialog, | ||||||
|   currentTrainData, |   currentTrainData, | ||||||
|   stationInput, |  | ||||||
|   stationNumberInput, |   stationNumberInput, | ||||||
|   lineInput, |   lineInput, | ||||||
|   setLineInput, |   setLineInput, | ||||||
|   posInput, |   posInput, | ||||||
|   descInput, |  | ||||||
|   setPosInput, |   setPosInput, | ||||||
|  |   descInput, | ||||||
|   setDescInput, |   setDescInput, | ||||||
|   station, |  | ||||||
| }) => { | }) => { | ||||||
|  |   const { stationList } = useStationList(); | ||||||
|   const sendPlatformData = () => { |   const sendPlatformData = () => { | ||||||
|     fetch(`https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3`, { |     fetch(`https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3`, { | ||||||
|       method: "POST", |       method: "POST", | ||||||
|       headers: { "Content-Type": "application/json" }, |       headers: { "Content-Type": "application/json" }, | ||||||
|       body: JSON.stringify({ |       body: JSON.stringify({ | ||||||
|         PosId: currentTrainData?.PosNum,//自動:位置情報ID |         PosId: currentTrainData?.PosNum, //自動:位置情報ID | ||||||
|         StationId: station.StationNumber,//自動:駅ID |         StationId: getStationID(currentTrainData?.Pos, stationList), //自動:駅ID | ||||||
|         StationName: station.Station_JP,//自動:駅名、漢字 |         StationName: currentTrainData?.Pos, //自動:駅名、漢字 | ||||||
|         lineName: currentTrainData?.Line,//自動:位置情報路線ID(koutoku/yosan) |         lineName: currentTrainData?.Line, //自動:位置情報路線ID(koutoku/yosan) | ||||||
|         Description: descInput,//手動入力、参考情報 |         Description: descInput, //手動入力、参考情報 | ||||||
|         platformNumber: parseInt(posInput),//手動入力、乗り場表記 |         platformNumber: parseInt(posInput), //手動入力、乗り場表記 | ||||||
|         lineNumber: parseInt(lineInput),//手動入力、番線表記 |         lineNumber: parseInt(lineInput), //手動入力、番線表記 | ||||||
|       }), |       }), | ||||||
|     }) |     }) | ||||||
|       .then(() => { |       .then(() => { | ||||||
| @@ -60,9 +56,10 @@ export const TrainPositionDataPush: FC<Props> = ({ | |||||||
|   }; |   }; | ||||||
|   return ( |   return ( | ||||||
|     <Dialog isVisible={dialog} onBackdropPress={() => setDialog(false)}> |     <Dialog isVisible={dialog} onBackdropPress={() => setDialog(false)}> | ||||||
|  |       <Text style={{ fontSize: 20, fontWeight: "bold" }}>駅番線情報投稿機能</Text> | ||||||
|       <Text>路線: {currentTrainData?.Line}</Text> |       <Text>路線: {currentTrainData?.Line}</Text> | ||||||
|       <Text>地点ID: {currentTrainData?.PosNum}</Text> |       <Text>地点ID: {currentTrainData?.PosNum}</Text> | ||||||
|       <Text>駅名: {stationInput}</Text> |       <Text>駅名: {currentTrainData?.Pos}</Text> | ||||||
|       <Text>駅ナンバー: {stationNumberInput}</Text> |       <Text>駅ナンバー: {stationNumberInput}</Text> | ||||||
|       <Input |       <Input | ||||||
|         label="乗り場" |         label="乗り場" | ||||||
| @@ -82,6 +79,7 @@ export const TrainPositionDataPush: FC<Props> = ({ | |||||||
|         value={descInput} |         value={descInput} | ||||||
|         onChangeText={setDescInput} |         onChangeText={setDescInput} | ||||||
|       /> |       /> | ||||||
|  |       <Text style={{ fontSize: 12, fontWeight: "bold" }}>この機能は駅の停車位置に関する情報を投稿する機能です。列車の遅れ、運行情報を投稿するフォームではありませんのでご注意ください。</Text> | ||||||
|       <Button title="送信" onPress={sendPlatformData} /> |       <Button title="送信" onPress={sendPlatformData} /> | ||||||
|     </Dialog> |     </Dialog> | ||||||
|   ); |   ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user