Merge commit 'a87b29e961756d48345093ba5290ea69cec64547' into patch/5.0.x

This commit is contained in:
harukin-expo-dev-env 2024-03-27 15:52:01 +00:00
commit 4d64980212
2 changed files with 39 additions and 10 deletions

View File

@ -12,11 +12,10 @@ export const useAllTrainDiagram = () => {
export const AllTrainDiagramProvider = ({ children }) => {
const [allTrainDiagram, setAllTrainDiagram] = useState();
const customData = {
};
const customData = {};
useEffect(() => {
fetch(
"https://script.google.com/macros/s/AKfycbx_s7RB-xTy-iAslFJg7LfplLV09-hjDXEjdi9kCP_JT45wq17Af_IPOKIOqIfaNDg/exec"
"http://n8n.haruk.in/webhook/CrowdTh%E2%82%AC71m3Ra7!ngLead%E2%82%ACr$"
)
.then((res) => res.json())
.then((res) => {
@ -30,6 +29,24 @@ export const AllTrainDiagramProvider = ({ children }) => {
.then((res) => {
Object.assign(res, customData);
setAllTrainDiagram(res);
})
.catch((d) => {
fetch(
"https://script.google.com/macros/s/AKfycbx_s7RB-xTy-iAslFJg7LfplLV09-hjDXEjdi9kCP_JT45wq17Af_IPOKIOqIfaNDg/exec"
)
.then((res) => res.json())
.then((res) => {
const data = {};
res.forEach((d) => {
const keys = Object.keys(d);
data[keys] = d[keys];
});
return data;
})
.then((res) => {
Object.assign(res, customData);
setAllTrainDiagram(res);
});
});
}, []);

View File

@ -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, []); //初回だけ現在の全在線列車取得