From e9fd753a8fdfccf02573da1e00fc2aa28f903cfe Mon Sep 17 00:00:00 2001 From: harukin-DeskMini Date: Sun, 26 Mar 2023 19:29:57 +0900 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/FavoriteList.js | 1 - components/発車時刻表/LED_vidion.js | 1 - components/駅名表/Sign.js | 1 - menu.js | 185 +++++++++++------------ trainbaseview.js | 1 - 5 files changed, 88 insertions(+), 101 deletions(-) diff --git a/components/FavoriteList.js b/components/FavoriteList.js index 3b946a2..422ca4c 100644 --- a/components/FavoriteList.js +++ b/components/FavoriteList.js @@ -34,7 +34,6 @@ export default function FavoriteList({ {favoriteStation .filter((d) => d[0].StationMap) .map((currentStation) => { - console.log(currentStation); return ( { diff --git a/components/発車時刻表/LED_vidion.js b/components/発車時刻表/LED_vidion.js index d25229b..af069ef 100644 --- a/components/発車時刻表/LED_vidion.js +++ b/components/発車時刻表/LED_vidion.js @@ -138,7 +138,6 @@ export default function LED_vision(props) { }); return { train: d, time: a.time, lastStation: a.lastStation }; }); - console.log(returnData); return returnData.sort((a, b) => { switch (true) { case parseInt(a.time.split(":")[0]) < parseInt(b.time.split(":")[0]): diff --git a/components/駅名表/Sign.js b/components/駅名表/Sign.js index 79e7b33..7316205 100644 --- a/components/駅名表/Sign.js +++ b/components/駅名表/Sign.js @@ -111,7 +111,6 @@ export default function Sign(props) { setFavoriteStation(otherData); } else { let ret = favoriteStation; - console.log(currentStation); ret.push(currentStation); AS.setItem("favoriteStation", JSON.stringify(ret)); setFavoriteStation(ret); diff --git a/menu.js b/menu.js index 4563941..6744042 100644 --- a/menu.js +++ b/menu.js @@ -48,59 +48,20 @@ export default function Menu(props) { const navigation = useNavigation(); //位置情報 - const [location, setLocation] = useState(null); const [locationStatus, setLocationStatus] = useState(null); useEffect(() => { Location.requestForegroundPermissionsAsync().then((data) => { setLocationStatus(data.status); }); }, []); - useEffect(() => { - if (locationStatus !== "granted") return () => {}; - getCurrentPosition(); - }, [locationStatus]); const getCurrentPosition = () => { + if (locationStatus !== "granted") return () => {}; Location.getCurrentPositionAsync({}).then((location) => - setLocation(location) + makeCurrentStation(location) ); }; - - useInterval(() => { - if (locationStatus !== "granted") return () => {}; - getCurrentPosition(); - }, 5000); - - const [originalStationList, setOriginalStationList] = useState(); - useEffect(() => { - getStationList().then(setOriginalStationList); - }, []); - - const [locationAndFavorite, setLocationAndFavorite] = useState([]); - useEffect(() => { - if (!favoriteStation) return () => {}; - const data = favoriteStation.filter((d) => - JSON.stringify(d) === JSON.stringify(currentStation) ? false : true - ); - setLocationAndFavorite(data); - }, [currentStation, favoriteStation]); - - useEffect(() => { - if (!(selectedCurrentStation < favoriteStation.length)) { - if (favoriteStation.length == 0) { - setSelectedCurrentStation(0); - carouselRef.current.snapToItem(0); - } else { - setSelectedCurrentStation(favoriteStation.length - 1); - carouselRef.current.snapToItem(favoriteStation.length - 1); - } - } - }, [favoriteStation]); - - const [stationName, setStationName] = useState(undefined); - const [currentStation, setCurrentStation] = useState(undefined); - useEffect(() => { - if (!location) return () => {}; + const makeCurrentStation = (location) => { if (!originalStationList) return () => {}; const findStationEachLine = (selectLine) => { const searchArea = 0.0015; @@ -134,7 +95,15 @@ export default function Menu(props) { } else { setCurrentStation(undefined); } - }, [location, originalStationList]); + }; + + useEffect(getCurrentPosition, [locationStatus]); + useInterval(getCurrentPosition, 5000); + + const [currentStation, setCurrentStation] = useState(undefined); //第三要素 + + const [originalStationList, setOriginalStationList] = useState(); // 第一要素 + useEffect(() => getStationList().then(setOriginalStationList), []); const [count, setCount] = useState(0); const [delayData, setDelayData] = useState(undefined); @@ -152,7 +121,29 @@ export default function Menu(props) { .then(() => setGetTime(new Date())) .finally(() => setLoadingDelayData(false)); }, [loadingDelayData]); - + const allStationData = [currentStation, ...favoriteStation].filter( + (d) => d != undefined + ); + console.log(allStationData); + useEffect(() => { + if (allStationData.length == 0) { + setSelectedCurrentStation(0); + return; + } + console.log(allStationData[selectedCurrentStation]); + if (allStationData[selectedCurrentStation] == undefined) { + const count = selectedCurrentStation - 1; + setSelectedCurrentStation(count); + } + }, [selectedCurrentStation, currentStation, favoriteStation]); + useEffect(() => { + if (!carouselRef.current) return; + console.log(carouselRef.current); + if (carouselRef.current?._itemToSnapTo != selectedCurrentStation) { + carouselRef.current.snapToItem(0); + carouselRef.current.snapToItem(selectedCurrentStation); + } + }, [selectedCurrentStation]); return ( - { - setSelectedCurrentStation(d); - }} - renderItem={({ item, index }) => { - return ( - - - - ); - }} - /> - {locationAndFavorite.length != 0 && originalStationList && ( - { + setSelectedCurrentStation(d); + }} + renderItem={({ item, index }) => { + return ( + + + + ); + }} /> )} + {allStationData.length != 0 && + originalStationList && + allStationData[selectedCurrentStation] && ( + + )} - + {allStationData.length != 0 && + originalStationList && + allStationData[selectedCurrentStation] && ( + + )}