From 65123424a34d6511a09a818b583f12292c8e3bb2 Mon Sep 17 00:00:00 2001 From: harukin-expo-dev-env Date: Sat, 5 Jul 2025 07:57:55 +0000 Subject: [PATCH] =?UTF-8?q?=E9=A7=85=E3=81=B8=E3=81=AE=E7=A7=BB=E5=8B=95?= =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88=E3=82=92hooks?= =?UTF-8?q?=E3=81=AB=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Apps/WebView.jsx | 33 ++--------------- stateBox/useStationList.tsx | 74 +++++++++++++++++++++++++++++-------- 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/components/Apps/WebView.jsx b/components/Apps/WebView.jsx index 257d189..13d0e13 100644 --- a/components/Apps/WebView.jsx +++ b/components/Apps/WebView.jsx @@ -23,7 +23,7 @@ export const AppsWebView = ({ openStationACFromEachTrainInfo }) => { const { navigate } = useNavigation(); const { favoriteStation } = useFavoriteStation(); const { isLandscape } = useDeviceOrientationChange(); - const { originalStationList, stationList } = useStationList(); + const { originalStationList, stationList, getInjectJavascriptAddress } = useStationList(); const { setSelectedLine, mapsStationData: stationData, @@ -137,34 +137,9 @@ export const AppsWebView = ({ openStationACFromEachTrainInfo }) => { if (!stationData) return () => {}; if (!originalStationList) return () => {}; if (favoriteStation.length < 1) return () => {}; - const bootStationList = []; - Object.keys(originalStationList).forEach((d) => { - let findNearStations = false; - originalStationList[d].forEach((x) => { - let lineName = lineList_LineWebID[d]; - if (findNearStations) { - if (x.MyStation){ - bootStationList.push({ line: lineName, station: x }); - findNearStations = false; - } - return; - } - if (x.StationNumber == favoriteStation[0][0].StationNumber) { - console.log(originalStationList[d]); - if (!x.MyStation) findNearStations = true; - else bootStationList.push({ line: lineName, station: x }); - } - }); - if (favoriteStation[0].StationNumber == "M12") { - bootStationList.push({ - line: "seto", - station: { Station_JP: "児島", MyStation: "0" }, - }); - } - }); - webview.current?.injectJavaScript( - `MoveDisplayStation('${bootStationList[0].line}_${bootStationList[0].station.MyStation}_${bootStationList[0].station.Station_JP}')` - ); + const string = getInjectJavascriptAddress(favoriteStation[0][0].StationNumber); + if (!string) return () => {}; + webview.current?.injectJavaScript(string); once = true; }; diff --git a/stateBox/useStationList.tsx b/stateBox/useStationList.tsx index 97eac6a..aae75b8 100644 --- a/stateBox/useStationList.tsx +++ b/stateBox/useStationList.tsx @@ -5,7 +5,11 @@ import React, { useEffect, FC, } from "react"; -import { lineList, getStationList } from "../lib/getStationList"; +import { + lineList, + getStationList, + lineList_LineWebID, +} from "../lib/getStationList"; type initialStateType = { originalStationList: any[][]; @@ -13,6 +17,7 @@ type initialStateType = { getStationDataFromName: (id: string) => any[]; getStationDataFromId: (id: string) => any[]; stationList: any[]; + getInjectJavascriptAddress: (StationNumber: string) => string; }; const initialState = { originalStationList: [[]], @@ -20,6 +25,7 @@ const initialState = { getStationDataFromName: () => [], getStationDataFromId: () => [], stationList: [], + getInjectJavascriptAddress: (StationNumber: string) => "", }; const StationListContext = createContext(initialState); @@ -40,7 +46,10 @@ export const StationListProvider: FC = ({ children }) => { Object.keys(originalStationList).forEach((key) => { originalStationList[key].forEach((station) => { if (station.StationNumber === id) { - returnArray = [...returnArray, ...getStationDataFromName(station.Station_JP)]; + returnArray = [ + ...returnArray, + ...getStationDataFromName(station.Station_JP), + ]; } }); }); @@ -58,21 +67,56 @@ export const StationListProvider: FC = ({ children }) => { return returnArray; }; const [stationList, setStationList] = useState([[]]); - useEffect(()=>{ - if(originalStationList.length === 0) return; - const stationList = - lineList.map((d) => - originalStationList[d].map((a) => ({ - StationNumber: a.StationNumber, - StationName: a.Station_JP, - })) - ); - setStationList(stationList); - },[originalStationList]) - + useEffect(() => { + if (originalStationList.length === 0) return; + const stationList = lineList.map((d) => + originalStationList[d].map((a) => ({ + StationNumber: a.StationNumber, + StationName: a.Station_JP, + })) + ); + setStationList(stationList); + }, [originalStationList]); + + const getInjectJavascriptAddress = (StationNumber: string) => { + const bootStationList = []; + Object.keys(originalStationList).forEach((d) => { + let findNearStations = false; + originalStationList[d].forEach((x) => { + let lineName = lineList_LineWebID[d]; + if (findNearStations) { + if (x.MyStation) { + bootStationList.push({ line: lineName, station: x }); + findNearStations = false; + } + return; + } + if (x.StationNumber == StationNumber) { + console.log(originalStationList[d]); + if (!x.MyStation) findNearStations = true; + else bootStationList.push({ line: lineName, station: x }); + } + }); + if (StationNumber == "M12") { + bootStationList.push({ + line: "seto", + station: { Station_JP: "児島", MyStation: "0" }, + }); + } + }); + return `MoveDisplayStation('${bootStationList[0].line}_${bootStationList[0].station.MyStation}_${bootStationList[0].station.Station_JP}')`; + }; + return ( {children}