検索モードの追加

This commit is contained in:
harukin-expo-dev-env 2025-07-15 02:56:29 +00:00
parent 3dc5f52333
commit e6adf775bb
5 changed files with 91 additions and 40 deletions

View File

@ -104,7 +104,7 @@ export const CarouselBox = ({
}} }}
> >
<Text style={{ color: "#0099CC", fontSize: 20 }}> <Text style={{ color: "#0099CC", fontSize: 20 }}>
{!!isSearchMode ? "路線検索モードです。上に並んでいる路線を選んでみましょう!" :stationListMode == "position" {!!isSearchMode ? "路線検索モードです。入力欄に駅名やナンバリングを入力したり、上に並んでいる路線を選んでみましょう!" :stationListMode == "position"
? "現在地の近くに駅がありません。" ? "現在地の近くに駅がありません。"
: "お気に入りリストがありません。お気に入りの駅を追加しよう!"} : "お気に入りリストがありません。お気に入りの駅を追加しよう!"}
</Text> </Text>

View File

@ -25,6 +25,10 @@ export const CarouselTypeChanger = ({
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput
}) => { }) => {
const tabBarHeight = useBottomTabBarHeight(); const tabBarHeight = useBottomTabBarHeight();
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
@ -62,6 +66,8 @@ export const CarouselTypeChanger = ({
<SearchUnitBox <SearchUnitBox
isSearchMode={isSearchMode} isSearchMode={isSearchMode}
setisSearchMode={setisSearchMode} setisSearchMode={setisSearchMode}
input={input}
setInput={setInput}
/> />
<TouchableOpacity <TouchableOpacity
style={{ style={{

View File

@ -12,9 +12,13 @@ import Ionicons from "react-native-vector-icons/Ionicons";
import { useWindowDimensions } from "react-native"; import { useWindowDimensions } from "react-native";
import lineColorList from "@/assets/originData/lineColorList"; import lineColorList from "@/assets/originData/lineColorList";
import { lineList_LineWebID, stationIDPair } from "@/lib/getStationList"; import { lineList_LineWebID, stationIDPair } from "@/lib/getStationList";
export const SearchUnitBox = ({ isSearchMode, setisSearchMode, }) => { export const SearchUnitBox = ({
isSearchMode,
setisSearchMode,
input,
setInput,
}) => {
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
const [input, setInput] = React.useState("");
return ( return (
<> <>
<TouchableOpacity <TouchableOpacity
@ -40,7 +44,14 @@ export const SearchUnitBox = ({ isSearchMode, setisSearchMode, }) => {
> >
{!isSearchMode && <Ionicons name="search" size={30} color="white" />} {!isSearchMode && <Ionicons name="search" size={30} color="white" />}
{!!isSearchMode && ( {!!isSearchMode && (
<View style={{ backgroundColor: "#0099CC",flexDirection:"column",display:"flex",flex:1 }}> <View
style={{
backgroundColor: "#0099CC",
flexDirection: "column",
display: "flex",
flex: 1,
}}
>
<View <View
style={{ style={{
backgroundColor: "white", backgroundColor: "white",
@ -52,7 +63,7 @@ export const SearchUnitBox = ({ isSearchMode, setisSearchMode, }) => {
}} }}
> >
<TextInput <TextInput
placeholder="駅名を入力してフィルタリングします。" placeholder="駅名や駅ナンバリングを入力してフィルタリングします。"
onEndEditing={() => {}} onEndEditing={() => {}}
onChange={(ret) => setInput(ret.nativeEvent.text)} onChange={(ret) => setInput(ret.nativeEvent.text)}
value={input} value={input}

20
menu.js
View File

@ -42,7 +42,7 @@ export default function Menu(props) {
const { scrollRef, mapHeight, MapFullHeight, mapMode, setMapMode } = props; const { scrollRef, mapHeight, MapFullHeight, mapMode, setMapMode } = props;
const { navigate, addListener, isFocused } = useNavigation(); const { navigate, addListener, isFocused } = useNavigation();
const { favoriteStation } = useFavoriteStation(); const { favoriteStation } = useFavoriteStation();
const { originalStationList } = useStationList(); const { originalStationList,getStationDataFromNameBase } = useStationList();
const { height, width } = useWindowDimensions(); const { height, width } = useWindowDimensions();
const { bottom, left, right, top } = useSafeAreaInsets(); const { bottom, left, right, top } = useSafeAreaInsets();
const tabBarHeight = useBottomTabBarHeight(); const tabBarHeight = useBottomTabBarHeight();
@ -172,9 +172,11 @@ export default function Menu(props) {
const [listUpStation, setListUpStation] = useState([]); const [listUpStation, setListUpStation] = useState([]);
const [isSearchMode, setisSearchMode] = useState(false); const [isSearchMode, setisSearchMode] = useState(false);
const [input, setInput] = React.useState("");
useLayoutEffect(() => { useLayoutEffect(() => {
if (!!isSearchMode) { if (!!isSearchMode) {
const returnData = []; const returnData = [];
if (!input || input == "") {
Object.keys(lineList_LineWebID).forEach((d, indexBase) => { Object.keys(lineList_LineWebID).forEach((d, indexBase) => {
originalStationList[d].forEach((D, index) => { originalStationList[d].forEach((D, index) => {
if ( if (
@ -191,6 +193,10 @@ export default function Menu(props) {
}); });
}); });
if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return; if (JSON.stringify(returnData) == JSON.stringify(listUpStation)) return;
}else{
const hoge = getStationDataFromNameBase(input);
hoge.forEach(d=>returnData.push([d]));
}
setListUpStation(returnData); setListUpStation(returnData);
} else if (stationListMode == "position") { } else if (stationListMode == "position") {
const returnData = nearPositionStation.filter((d) => d != undefined); const returnData = nearPositionStation.filter((d) => d != undefined);
@ -290,7 +296,7 @@ export default function Menu(props) {
> >
<MapView <MapView
ref={mapsRef} ref={mapsRef}
style={{ width: "100%", height:( mapMode ? MapFullHeight : mapHeight) }} style={{ width: "100%", height: mapMode ? MapFullHeight : mapHeight }}
showsUserLocation={true} showsUserLocation={true}
loadingEnabled={true} loadingEnabled={true}
showsMyLocationButton={false} showsMyLocationButton={false}
@ -371,6 +377,10 @@ export default function Menu(props) {
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput,
}} }}
/> />
)} )}
@ -386,7 +396,7 @@ export default function Menu(props) {
listIndex, listIndex,
navigate, navigate,
stationListMode, stationListMode,
isSearchMode isSearchMode,
}} }}
/> />
{listUpStation[listIndex] && ( {listUpStation[listIndex] && (
@ -416,6 +426,10 @@ export default function Menu(props) {
setMapMode, setMapMode,
isSearchMode, isSearchMode,
setisSearchMode, setisSearchMode,
listUpStation,
setListUpStation,
input,
setInput,
}} }}
/> />
)} )}

View File

@ -16,6 +16,7 @@ type initialStateType = {
setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>; setOriginalStationList: React.Dispatch<React.SetStateAction<any[]>>;
getStationDataFromName: (id: string) => any[]; getStationDataFromName: (id: string) => any[];
getStationDataFromId: (id: string) => any[]; getStationDataFromId: (id: string) => any[];
getStationDataFromNameBase: (name: string) => any[];
stationList: any[]; stationList: any[];
getInjectJavascriptAddress: (StationNumber: string) => string; getInjectJavascriptAddress: (StationNumber: string) => string;
}; };
@ -24,6 +25,7 @@ const initialState = {
setOriginalStationList: () => {}, setOriginalStationList: () => {},
getStationDataFromName: () => [], getStationDataFromName: () => [],
getStationDataFromId: () => [], getStationDataFromId: () => [],
getStationDataFromNameBase: () => [],
stationList: [], stationList: [],
getInjectJavascriptAddress: (StationNumber: string) => "", getInjectJavascriptAddress: (StationNumber: string) => "",
}; };
@ -66,6 +68,23 @@ export const StationListProvider: FC<Props> = ({ children }) => {
}); });
return returnArray; return returnArray;
}; };
const getStationDataFromNameBase: (name: string) => any[] = (name) => {
const returnArray = [];
Object.keys(originalStationList).forEach((key) => {
originalStationList[key].forEach((station) => {
if (!station.StationNumber) return;
if (typeof station.StationNumber === "string" && station.StationNumber.includes(name)) {
if (!!station.jslodApi) returnArray.push(station);
}
else if (typeof station.Station_JP === "string" && station.Station_JP.includes(name)) {
if (!!station.jslodApi) returnArray.push(station);
}
});
});
return returnArray;
};
const [stationList, setStationList] = useState<any[][]>([[]]); const [stationList, setStationList] = useState<any[][]>([[]]);
useEffect(() => { useEffect(() => {
if (originalStationList.length === 0) return; if (originalStationList.length === 0) return;
@ -113,6 +132,7 @@ export const StationListProvider: FC<Props> = ({ children }) => {
setOriginalStationList, setOriginalStationList,
getStationDataFromName, getStationDataFromName,
getStationDataFromId, getStationDataFromId,
getStationDataFromNameBase,
stationList, stationList,
getInjectJavascriptAddress, getInjectJavascriptAddress,
}} }}