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} + + ); +};