diff --git a/Apps.js b/Apps.js index 718d60f..6c215ba 100644 --- a/Apps.js +++ b/Apps.js @@ -13,6 +13,7 @@ import { news } from "./config/newsUpdate"; import { getStationList } from "./lib/getStationList"; import { StationDeteilView } from "./components/ActionSheetComponents/StationDeteilView"; import { injectJavascriptData } from "./lib/webViewInjectjavascript"; +import { getStationList2 } from "./lib/getStationList2"; /* import StatusbarDetect from './StatusbarDetect'; var Status = StatusbarDetect(); */ @@ -23,10 +24,19 @@ export default function Apps(props) { } = props; var urlcache = ""; const webview = useRef(); + //画面表示関連 const [iconSetting, setIconSetting] = useState(undefined); const [mapSwitch, setMapSwitch] = useState(undefined); - const [stationData, setStationData] = useState(undefined); + //地図用 + const [mapsStationData, setMapsStationData] = useState(undefined); + useEffect(() => { + getStationList2().then((data) => { + setMapsStationData(data); + }); + }, []); + + //駅情報画面用 const StationBoardAcSR = useRef(null); const [currentStation, setCurrentStation] = useState(undefined); const [originalStationList, setOriginalStationList] = useState(); @@ -37,20 +47,18 @@ export default function Apps(props) { }); }, []); + //地図表示テキスト const injectJavascript = injectJavascriptData(mapSwitch, iconSetting); useEffect(() => { + //ニュース表示 AsyncStorage.getItem("status") .then((d) => { - if (d != news) { - navigate("news"); - } + if (d != news) navigate("news"); }) - .catch((e) => { - navigate("news"); - }); - }, []); - useEffect(() => { + .catch((e) => navigate("news")); + + //列車アイコンスイッチ AsyncStorage.getItem("iconSwitch") .then((d) => { if (d) { @@ -67,6 +75,7 @@ export default function Apps(props) { ) ); + //地図スイッチ AsyncStorage.getItem("mapSwitch") .then((d) => { if (d) { @@ -133,7 +142,9 @@ export default function Apps(props) { injectedJavaScript={injectJavascript} /> navigate("trainMenu", { webview, stationData })} + onPress={() => + navigate("trainMenu", { webview, stationData: mapsStationData }) + } style={{ position: "absolute", top: Platform.OS == "ios" ? Constants.statusBarHeight : 0, diff --git a/lib/getStationList2.js b/lib/getStationList2.js new file mode 100644 index 0000000..8de3a41 --- /dev/null +++ b/lib/getStationList2.js @@ -0,0 +1,55 @@ +let status = undefined; +export const getStationList2 = async (props) => { + if (status) return status; + const HeaderConfig = { + headers: { referer: "https://train.jr-shikoku.co.jp/sp.html" }, + }; + + return await Promise.all([ + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=yosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=uwajima2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=dosan2", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=koutoku", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=tokushima", + HeaderConfig + ).then((response) => response.json()), + fetch( + "https://train.jr-shikoku.co.jp/g?arg1=station&arg2=naruto", + HeaderConfig + ).then((response) => response.json()), + ]).then((values) => { + let stationList = {}; + [ + stationList.yosan, + stationList.uwajima, + stationList.uwajima2, + stationList.dosan, + stationList.dosan2, + stationList.koutoku, + stationList.tokushima, + stationList.naruto, + ] = values; + return stationList; + }); +};