駅名入力でフィルタリングする機能を追加

This commit is contained in:
harukin-expo-dev-env
2025-09-03 13:52:56 +00:00
parent 2967837dd5
commit 92b5052f3b
2 changed files with 116 additions and 37 deletions

View File

@@ -1,12 +1,20 @@
import { FC, useEffect, useState } from "react"; import { FC, useEffect, useState } from "react";
import { View, Text, ScrollView } from "react-native"; import {
View,
Text,
ScrollView,
TextInput,
Keyboard,
KeyboardAvoidingView,
Platform,
} from "react-native";
import { useNavigation } from "@react-navigation/native"; import { useNavigation } from "@react-navigation/native";
import { BigButton } from "../atom/BigButton"; import { BigButton } from "../atom/BigButton";
import { useAllTrainDiagram } from "@/stateBox/useAllTrainDiagram"; import { useAllTrainDiagram } from "@/stateBox/useAllTrainDiagram";
import { ListView } from "@/components/StationDiagram/ListView"; import { ListView } from "@/components/StationDiagram/ListView";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { ExGridView } from "./ExGridView"; import { ExGridView } from "./ExGridView";
import { Switch } from "react-native-elements"; import { Switch, Input } from "react-native-elements";
type props = { type props = {
route: { route: {
@@ -40,6 +48,8 @@ export const StationDiagramView: FC<props> = ({ route }) => {
const { allTrainDiagram } = useAllTrainDiagram(); const { allTrainDiagram } = useAllTrainDiagram();
const { navigate, addListener, goBack, canGoBack } = useNavigation(); const { navigate, addListener, goBack, canGoBack } = useNavigation();
const [keyBoardVisible, setKeyBoardVisible] = useState(false);
const [input, setInput] = useState("");
type hoge = { type hoge = {
trainNumber: string; trainNumber: string;
array: string; array: string;
@@ -62,7 +72,23 @@ export const StationDiagramView: FC<props> = ({ route }) => {
type: any; type: any;
time: any; time: any;
}[] = []; }[] = [];
Object.keys(allTrainDiagram).forEach((d) => { Object.keys(allTrainDiagram)
.filter((s) => {
const boolData = allTrainDiagram[s];
let isStop = false;
let isInput = false;
boolData.split("#").forEach((d) => {
const [station, type, time] = d.split(",");
if (station === stationName) isStop = true;
if (station === input && type && !type.includes("通")) isInput = true;
});
if (input && input.length > 0) {
return isInput && isStop;
}
return isStop;
})
.forEach((d) => {
allTrainDiagram[d] allTrainDiagram[d]
.split("#") .split("#")
.filter((d) => { .filter((d) => {
@@ -104,7 +130,21 @@ export const StationDiagramView: FC<props> = ({ route }) => {
}) })
); );
} }
}, [currentStation, showLastStop, isSpecial, isOutOfService, threw]); }, [currentStation, showLastStop, isSpecial, isOutOfService, threw, input]);
useEffect(() => {
const showSubscription = Keyboard.addListener("keyboardDidShow", () => {
setKeyBoardVisible(true);
});
const hideSubscription = Keyboard.addListener("keyboardDidHide", () => {
setKeyBoardVisible(false);
});
return () => {
showSubscription.remove();
hideSubscription.remove();
};
}, []);
return ( return (
<View style={{ height: "100%", backgroundColor: "#0099CC" }}> <View style={{ height: "100%", backgroundColor: "#0099CC" }}>
<Text <Text
@@ -129,17 +169,55 @@ export const StationDiagramView: FC<props> = ({ route }) => {
> >
お気に入り登録した駅のうち、位置情報システムで移動可能な駅が表示されています。タップすることで位置情報システムの当該の駅に移動します。 お気に入り登録した駅のうち、位置情報システムで移動可能な駅が表示されています。タップすることで位置情報システムの当該の駅に移動します。
</Text> */} </Text> */}
<View style={{ height: 20, flexDirection: "row" }}> <KeyboardAvoidingView
<Switch value={showLastStop} onValueChange={setShowLastStop} /> behavior="padding"
<Text></Text> keyboardVerticalOffset={80}
<Switch value={isSpecial} onValueChange={setIsSpecial} /> enabled={Platform.OS === "ios"}
<Text></Text> >
<Switch value={isOutOfService} onValueChange={setIsOutOfService} /> <View style={{ height: 35, flexDirection: "row" }}>
<Text></Text> <Switch value={showLastStop} onValueChange={setShowLastStop}
<Switch value={threw} onValueChange={setIsThrew} /> color="red"
<Text></Text> style={{ marginVertical: 5 }} />
<Text style={{ color: "white", fontSize: 20, marginVertical: 5 }}></Text>
<Switch value={isSpecial} onValueChange={setIsSpecial}
color="red"
style={{ marginVertical: 5 }} />
<Text style={{ color: "white", fontSize: 20, marginVertical: 5 }}></Text>
<Switch value={isOutOfService} onValueChange={setIsOutOfService}
color="red"
style={{ marginVertical: 5 }} />
<Text style={{ color: "white", fontSize: 20, marginVertical: 5 }}></Text>
<Switch value={threw} onValueChange={setIsThrew}
color="red"
style={{ marginVertical: 5 }} />
<Text style={{ color: "white", fontSize: 20, marginVertical: 5 }}></Text>
</View> </View>
<View
style={{
height: 35,
margin: 5,
alignItems: "center",
backgroundColor: "#F4F4F4",
flexDirection: "row",
paddingLeft: 10,
paddingRight: 10,
borderRadius: 25,
borderColor: "#F4F4F4",
}}
>
<TextInput
placeholder="列番・列車名を入力してフィルタリングします。"
onFocus={() => setKeyBoardVisible(true)}
onEndEditing={() => {}}
onChange={(ret) => setInput(ret.nativeEvent.text)}
value={input}
style={{ flex: 1 }}
/>
</View>
</KeyboardAvoidingView>
{keyBoardVisible || (
<BigButton onPress={() => goBack()} string="閉じる" /> <BigButton onPress={() => goBack()} string="閉じる" />
)}
</View> </View>
); );
}; };

View File

@@ -6,6 +6,7 @@ const initialState = {
allTrainDiagram: undefined, allTrainDiagram: undefined,
setAllTrainDiagram: () => {}, setAllTrainDiagram: () => {},
allCustomTrainData: [], allCustomTrainData: [],
keyList: [],
}; };
const AllTrainDiagramContext = createContext(initialState); const AllTrainDiagramContext = createContext(initialState);