jrshikoku/components/発車時刻表/LED_inside_Component/TrainPositionDataPush.tsx
harukin-expo-dev-env fe5baba037 項目の最適化
2025-08-13 11:33:07 +00:00

87 lines
3.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { FC } from "react";
import { Text } from "react-native";
import { Dialog, Input, Button } from "react-native-elements";
import { trainDataType } from "../../../lib/trainPositionTextArray";
import { getStationID } from "@/lib/eachTrainInfoCoreLib/getStationData";
import { useStationList } from "@/stateBox/useStationList";
type Props = {
dialog: boolean;
setDialog: (dialog: boolean) => void;
currentTrainData: trainDataType;
stationNumberInput: string;
posInput: string;
descInput: string;
lineInput: string;
setPosInput: (pos: string) => void;
setDescInput: (desc: string) => void;
setLineInput: (line: string) => void;
};
export const TrainPositionDataPush: FC<Props> = ({
dialog,
setDialog,
currentTrainData,
stationNumberInput,
lineInput,
setLineInput,
posInput,
setPosInput,
descInput,
setDescInput,
}) => {
const { stationList } = useStationList();
const sendPlatformData = () => {
fetch(`https://n8n.haruk.in/webhook/JR-shikoku-PosID-v3`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
PosId: currentTrainData?.PosNum, //自動位置情報ID
StationId: getStationID(currentTrainData?.Pos, stationList), //自動駅ID
StationName: currentTrainData?.Pos, //自動:駅名、漢字
lineName: currentTrainData?.Line, //自動位置情報路線ID(koutoku/yosan)
Description: descInput, //手動入力、参考情報
platformNumber: parseInt(posInput), //手動入力、乗り場表記
lineNumber: parseInt(lineInput), //手動入力、番線表記
}),
})
.then(() => {
alert("位置情報データを送信しました。");
setDialog(false);
setPosInput("");
setDescInput("");
})
.catch(() => {
alert("位置情報データの送信に失敗しました。");
});
};
return (
<Dialog isVisible={dialog} onBackdropPress={() => setDialog(false)}>
<Text style={{ fontSize: 20, fontWeight: "bold" }}>稿</Text>
<Text>: {currentTrainData?.Line}</Text>
<Text>ID: {currentTrainData?.PosNum}</Text>
<Text>: {currentTrainData?.Pos}</Text>
<Text>: {stationNumberInput}</Text>
<Input
label="乗り場"
inputMode="numeric"
value={posInput}
onChangeText={setPosInput}
/>
<Input
label="番線"
inputMode="numeric"
value={lineInput}
onChangeText={setLineInput}
/>
<Input
label="参考情報"
inputMode="text"
value={descInput}
onChangeText={setDescInput}
/>
<Text style={{ fontSize: 12, fontWeight: "bold" }}>稿稿</Text>
<Button title="送信" onPress={sendPlatformData} />
</Dialog>
);
};