jrshikoku/components/FavoriteList.tsx
harukin-expo-dev-env 5d89747c03 暫定型移行
2025-03-11 05:16:35 +00:00

96 lines
3.5 KiB
TypeScript

import React, { FC, useEffect } from "react";
import { View, Text, ScrollView } from "react-native";
import Icon from "react-native-vector-icons/Entypo";
import { useFavoriteStation } from "../stateBox/useFavoriteStation";
import { useCurrentTrain } from "../stateBox/useCurrentTrain";
import { useNavigation } from "@react-navigation/native";
import { useTrainMenu } from "../stateBox/useTrainMenu";
import { FavoriteListItem } from "./atom/FavoriteListItem";
import { BigButton } from "./atom/BigButton";
export const FavoriteList: FC = () => {
const { favoriteStation } = useFavoriteStation();
const { webview } = useCurrentTrain();
const { navigate, addListener, goBack, canGoBack } = useNavigation();
const { mapsStationData: stationData } = useTrainMenu();
useEffect(() => {
const unsubscribe = addListener("tabPress", goToTrainMenu);
return unsubscribe;
}, [{ navigate, addListener }]);
const goToTrainMenu = (e) => {
e.preventDefault();
goBack();
};
return (
<View style={{ height: "100%", backgroundColor: "#0099CC" }}>
<Text
style={{
textAlign: "center",
fontSize: 20,
color: "white",
fontWeight: "bold",
paddingVertical: 10,
}}
>
</Text>
<ScrollView style={{ height: "100%", backgroundColor: "white" }}>
{favoriteStation
.filter((d) => d[0].StationMap)
.map((currentStation) => {
return (
<FavoriteListItem
currentStation={currentStation}
onPress={() => {
const getStationLine = (now) => {
const returnData = Object.keys(stationData).filter((d) => {
const cache = stationData[d].findIndex(
(data) => data.Station_JP == now.Station_JP
);
return cache != -1;
});
return returnData[0];
};
const lineName = getStationLine(currentStation[0]);
webview.current?.injectJavaScript(
`MoveDisplayStation('${lineName}_${currentStation[0].MyStation}_${currentStation[0].Station_JP}');
document.getElementById("disp").insertAdjacentHTML("afterbegin", "<div />");`
);
goBack();
if (canGoBack()) goBack();
}}
>
<View
style={{
flex: 2,
flexDirection: "row",
alignContent: "center",
alignItems: "center",
marginVertical: 4,
}}
>
<View style={{ flex: 1 }} />
<Text style={{ fontSize: 20 }}></Text>
<Icon name="chevron-right" size={20} />
</View>
</FavoriteListItem>
);
})}
</ScrollView>
<Text
style={{
backgroundColor: "white",
borderWidth: 1,
borderStyle: "solid",
}}
>
</Text>
<BigButton onPress={() => goBack()} string="閉じる" />
</View>
);
};