From b7c56f4b90b274864be2a1e8c5abe9207d7c3aa7 Mon Sep 17 00:00:00 2001 From: harukin-OneMix4 Date: Mon, 25 Dec 2023 04:40:38 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=88=97=E7=95=AA=E6=A4=9C=E7=B4=A2?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MenuPage.js | 26 ++++++ components/AllTrainDiagramView.js | 124 +++++++++++++++++++++++++++++ components/CurrentTrainListView.js | 51 ++++++++++++ stateBox/useAllTrainDiagram.js | 38 +++++++++ 4 files changed, 239 insertions(+) create mode 100644 components/AllTrainDiagramView.js create mode 100644 components/CurrentTrainListView.js create mode 100644 stateBox/useAllTrainDiagram.js diff --git a/MenuPage.js b/MenuPage.js index 129be1f..804f385 100644 --- a/MenuPage.js +++ b/MenuPage.js @@ -10,6 +10,8 @@ import Menu from "./menu"; import Setting from "./components/settings.js"; import { useFavoriteStation } from "./stateBox/useFavoriteStation"; import { optionData } from "./lib/stackOption.js"; +import CurrentTrainListView from "./components/CurrentTrainListView.js"; +import AllTrainDiagramView from "./components/AllTrainDiagramView.js"; const Stack = createStackNavigator(); export function MenuPage({ navigation, getCurrentTrain }) { @@ -56,6 +58,30 @@ export function MenuPage({ navigation, getCurrentTrain }) { > {(props) => } + + {(props) => } + + + {(props) => } + getStationList().then(setOriginalStationList), []); + + const openTrainInfo = (d) => { + const train = customTrainDataDetector(d); + let TrainNumber = ""; + if (train.trainNumDistance != undefined) { + const timeInfo = + parseInt(d.replace("M", "").replace("D", "")) - train.trainNumDistance; + TrainNumber = timeInfo + "号"; + } + const payload = { + data: { + trainNum: d, + limited: `${getTrainType(train.type).data}:${ + train.trainName + }${TrainNumber}`, + trainData: checkDuplicateTrainData( + currentTrain.filter((a) => a.num == d) + ), + }, + navigate, + originalStationList, + from: "LED", + }; + SheetManager.show("EachTrainInfo", { + payload, + }); + }; + return ( + + + {allTrainDiagram && + Object.keys(allTrainDiagram).map((key) => { + return ( + openTrainInfo(key)} + > + + + {key} + + + + ); + })} + + + navigate("menu")} + > + + + 閉じる + + + + + ); +} +const UsefulBox = (props) => { + const { icon, backgroundColor, flex, onPressButton, children } = props; + return ( + + + + {children} + + + ); +}; diff --git a/components/CurrentTrainListView.js b/components/CurrentTrainListView.js new file mode 100644 index 0000000..cc5f880 --- /dev/null +++ b/components/CurrentTrainListView.js @@ -0,0 +1,51 @@ +import React, { useRef } from "react"; +import { View, Text, TouchableOpacity, Linking } from "react-native"; +import MapView, { Marker } from "react-native-maps"; +import { MaterialCommunityIcons } from "@expo/vector-icons"; +import { useCurrentTrain } from "../stateBox/useCurrentTrain"; +export default function CurrentTrainListView({ navigation: { navigate } }) { + const { currentTrain } = useCurrentTrain(); + return ( + + {currentTrain && currentTrain.map((d) => {d.num})} + navigate("menu")} + > + + + 閉じる + + + + + ); +} +const UsefulBox = (props) => { + const { icon, backgroundColor, flex, onPressButton, children } = props; + return ( + + + + {children} + + + ); +}; diff --git a/stateBox/useAllTrainDiagram.js b/stateBox/useAllTrainDiagram.js new file mode 100644 index 0000000..63f3a92 --- /dev/null +++ b/stateBox/useAllTrainDiagram.js @@ -0,0 +1,38 @@ +import React, { createContext, useContext, useEffect, useState } from "react"; +const initialState = { + allTrainDiagram: undefined, + setAllTrainDiagram: () => {}, +}; + +const AllTrainDiagramContext = createContext(initialState); + +export const useAllTrainDiagram = () => { + return useContext(AllTrainDiagramContext); +}; + +export const AllTrainDiagramProvider = ({ children }) => { + const [allTrainDiagram, setAllTrainDiagram] = useState(); + useEffect(() => { + 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) => setAllTrainDiagram(res)); + }, []); + + return ( + + {children} + + ); +};