From c25509c62f4362d8b1b45cd16d7ca55b4ea42fef Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Wed, 27 Mar 2024 08:19:50 +0000 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=B7=9A=E5=8F=96=E5=BE=97=E3=82=92n8?= =?UTF-8?q?n=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stateBox/useCurrentTrain.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/stateBox/useCurrentTrain.js b/stateBox/useCurrentTrain.js index 9e181d8..1c79710 100644 --- a/stateBox/useCurrentTrain.js +++ b/stateBox/useCurrentTrain.js @@ -26,11 +26,8 @@ export const useCurrentTrain = () => { export const CurrentTrainProvider = ({ children }) => { const [currentTrain, setCurrentTrain] = useState([]); //現在在線中の全列車 { num: 列車番号, delay: 遅延時分(状態), Pos: 位置情報 } const [currentTrainLoading, setCurrentTrainLoading] = useState("loading"); // success, error, loading - const getCurrentTrain = () => - fetch( - "https://script.google.com/macros/s/AKfycby9Y2-Bm75J_WkbZimi7iS8v5r9wMa9wtzpdwES9sOGF4i6HIYEJOM60W6gM1gXzt1o/exec", - HeaderConfig - ) + const getCurrentTrain = () => { + fetch("https://n8n.haruk.in/webhook/c501550c-7d1b-4e50-927b-4429fe18931a") .then((response) => response.json()) .then((d) => d.map((x) => ({ num: x.TrainNum, delay: x.delay, Pos: x.Pos })) @@ -40,9 +37,24 @@ export const CurrentTrainProvider = ({ children }) => { setCurrentTrainLoading("success"); }) .catch(() => { - console.log("えらー"); - setCurrentTrainLoading("error"); + fetch( + "https://script.google.com/macros/s/AKfycby9Y2-Bm75J_WkbZimi7iS8v5r9wMa9wtzpdwES9sOGF4i6HIYEJOM60W6gM1gXzt1o/exec", + HeaderConfig + ) + .then((response) => response.json()) + .then((d) => + d.map((x) => ({ num: x.TrainNum, delay: x.delay, Pos: x.Pos })) + ) + .then((d) => { + setCurrentTrain(d); + setCurrentTrainLoading("success"); + }) + .catch(() => { + console.log("えらー"); + setCurrentTrainLoading("error"); + }); }); + }; useEffect(getCurrentTrain, []); //初回だけ現在の全在線列車取得