- Split the existing useCurrentTrain hook into two separate hooks: useCurrentTrainData for accessing train data and useCurrentTrainView for accessing view-related properties. - Updated all components and hooks to use the new hooks accordingly, ensuring that the functionality remains intact. - This change improves the separation of concerns and enhances the maintainability of the codebase.
93 lines
3.5 KiB
TypeScript
93 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 type { RootTabParamList } from "@/types/navigation";
|
|
import type { BottomTabNavigationProp } from "@react-navigation/bottom-tabs";
|
|
import { useCurrentTrainView } from "../stateBox/useCurrentTrain";
|
|
import { useNavigation } from "@react-navigation/native";
|
|
import { useTrainMenu } from "../stateBox/useTrainMenu";
|
|
import { FavoriteListItem } from "./atom/FavoriteListItem";
|
|
import { BigButton } from "./atom/BigButton";
|
|
import { useThemeColors } from "@/lib/theme";
|
|
import { useStationList } from "@/stateBox/useStationList";
|
|
export const FavoriteList: FC = () => {
|
|
const { colors, fixed } = useThemeColors();
|
|
const { favoriteStation } = useFavoriteStation();
|
|
const { webview } = useCurrentTrainView();
|
|
const { navigate, addListener, goBack, canGoBack } = useNavigation<BottomTabNavigationProp<RootTabParamList>>();
|
|
const { mapsStationData: stationData } = useTrainMenu();
|
|
const { getInjectJavascriptAddress } = useStationList();
|
|
|
|
useEffect(() => {
|
|
const unsubscribe = addListener("tabPress", goToTrainMenu);
|
|
return unsubscribe;
|
|
}, [{ navigate, addListener }]);
|
|
|
|
const goToTrainMenu = (e) => {
|
|
e.preventDefault();
|
|
goBack();
|
|
};
|
|
return (
|
|
<View style={{ height: "100%", backgroundColor: fixed.primary }}>
|
|
<Text
|
|
style={{
|
|
textAlign: "center",
|
|
fontSize: 20,
|
|
color: fixed.textOnPrimary,
|
|
fontWeight: "bold",
|
|
paddingVertical: 10,
|
|
}}
|
|
>
|
|
位置情報クイック移動メニュー
|
|
</Text>
|
|
<ScrollView style={{ height: "100%", backgroundColor: colors.background }}>
|
|
{favoriteStation.filter((currentStation) => currentStation.length > 0 && !!currentStation[0].StationNumber)
|
|
.map((currentStation) => {
|
|
return (
|
|
<FavoriteListItem
|
|
currentStation={currentStation}
|
|
onPress={() => {
|
|
const scriptString = getInjectJavascriptAddress(
|
|
currentStation[0].StationNumber
|
|
);
|
|
if (!scriptString) return;
|
|
webview.current?.injectJavaScript(scriptString);
|
|
goBack();
|
|
if (canGoBack()) goBack();
|
|
}}
|
|
key={currentStation[0].StationNumber + "FavoriteList"}
|
|
>
|
|
<View
|
|
style={{
|
|
flex: 2,
|
|
flexDirection: "row",
|
|
alignContent: "center",
|
|
alignItems: "center",
|
|
marginVertical: 4,
|
|
}}
|
|
>
|
|
<View style={{ flex: 1 }} />
|
|
<Text style={{ fontSize: 20, color: colors.text }}>移動する</Text>
|
|
<Icon name="chevron-right" size={20} />
|
|
</View>
|
|
</FavoriteListItem>
|
|
);
|
|
})}
|
|
</ScrollView>
|
|
<Text
|
|
style={{
|
|
backgroundColor: colors.background,
|
|
color: colors.text,
|
|
borderWidth: 1,
|
|
borderStyle: "solid",
|
|
}}
|
|
>
|
|
お気に入り登録した駅のうち、位置情報システムで移動可能な駅が表示されています。タップすることで位置情報システムの当該の駅に移動します。
|
|
</Text>
|
|
<BigButton onPress={() => goBack()} string="閉じる" />
|
|
</View>
|
|
);
|
|
};
|