import { ScrollView, Text, View, StyleSheet, Pressable, ImageSourcePropType } from 'react-native'; import NormalInput from '../global/normal_input'; import NormalButton from '../global/normal_button'; import { FlashList } from '@shopify/flash-list'; import { ArrowIconSvg } from '../global/SVG'; import { SafeAreaView } from 'react-native-safe-area-context'; import { useEffect, useRef, useState } from 'react'; import { router } from 'expo-router'; interface BookingHistory { charingStationName: string; chargingStationAddress: string; } interface SearchPageComponentProps {} interface TabItem { imgURL: ImageSourcePropType; date: string; time: string; chargeStationName: string; chargeStationAddress: string; distance: string; latitude: number; longitude: number; } const dummyTabItems: TabItem[] = [ { imgURL: require('../../assets/dummyStationPicture.png'), date: '今天', time: '16:30', chargeStationName: '觀塘偉業街充電站', chargeStationAddress: '九龍觀塘偉業街143號地下', distance: '400米', latitude: 22.310958, longitude: 114.226065 }, { imgURL: require('../../assets/dummyStationPicture2.png'), date: '3月15', time: '17:45', chargeStationName: '中環IFC充電站', chargeStationAddress: '香港中環皇后大道中999號', distance: '680米', latitude: 22.28552, longitude: 114.15769 } ]; const bookingHistoryData: BookingHistory[] = [ { charingStationName: '充電站#1', chargingStationAddress: '充電站地址#1' }, { charingStationName: '充電站#2', chargingStationAddress: '充電站地址#2' }, { charingStationName: '充電站#3', chargingStationAddress: '充電站地址#3' }, { charingStationName: '充電站#4', chargingStationAddress: '充電站地址#4' } ]; const SearchPageComponent: React.FC = () => { const inputRef = useRef(null); const [searchInput, setSearchInput] = useState(''); const [filteredItems, setFilteredItems] = useState([]); useEffect(() => { if (inputRef.current) { inputRef.current.focus(); } }, []); useEffect(() => { if (searchInput === '') { setFilteredItems([]); } else { const filteredData = dummyTabItems.filter((item) => item.chargeStationName.includes(searchInput.toLocaleUpperCase()) ); setFilteredItems(filteredData); } }, [searchInput]); return ( { if (router.canGoBack()) { router.back(); } else { router.replace('/(auth)/(tabs)/(home)'); } }} > { setSearchInput(text); console.log(text); }} extendedStyle={styles.textInput} ref={inputRef} /> {filteredItems.length > 0 && ( {filteredItems.map((item, index) => ( { setSearchInput( item.chargeStationName ); setFilteredItems([]); router.push({ pathname: '/searchResultPage', params: { latitude: item.latitude, longitude: item.longitude, chargeStationName: item.chargeStationName } }); }} style={({ pressed }) => [ styles.dropdownItem, pressed && styles.dropdownItemPress ]} > {item.chargeStationName} ))} )} 附近的充電站 } // onPress={() => console.log('附近的充電站')} onPress={() => router.push('/searchResultPage')} buttonPressedStyle={{ backgroundColor: '#CFDEE4' }} extendedStyle={{ backgroundColor: '#E3F2F8', borderRadius: 8, paddingVertical: 12 }} /> 可Walk-in的充電站 } onPress={() => console.log('可Walk-in的充電站')} buttonPressedStyle={{ backgroundColor: '#CFDEE4' }} extendedStyle={{ backgroundColor: '#E3F2F8', borderRadius: 8, paddingVertical: 12 }} /> Test Tab #1 } onPress={() => console.log('Test Tab #1')} buttonPressedStyle={{ backgroundColor: '#CFDEE4' }} extendedStyle={{ backgroundColor: '#E3F2F8', borderRadius: 8, paddingVertical: 12 }} /> Test Tab #2 } onPress={() => console.log('Test Tab #2')} buttonPressedStyle={{ backgroundColor: '#CFDEE4' }} extendedStyle={{ backgroundColor: '#E3F2F8', borderRadius: 8, paddingVertical: 12 }} /> 預約記錄 ( {item.charingStationName} {item.chargingStationAddress} )} /> ); }; export default SearchPageComponent; const styles = StyleSheet.create({ leftArrowBackButton: { width: '15%', maxWidth: '100%', fontSize: 16, padding: 20, paddingLeft: 30, borderBottomLeftRadius: 12, borderTopLeftRadius: 12, borderColor: '#bbbbbb', borderTopWidth: 1, borderBottomWidth: 1, borderLeftWidth: 1, alignItems: 'center', justifyContent: 'center' }, textInput: { width: '85%', maxWidth: '100%', fontSize: 16, padding: 20, paddingLeft: 0, borderLeftWidth: 0, borderTopWidth: 1, borderBottomWidth: 1, borderRightWidth: 1, borderBottomRightRadius: 12, borderTopRightRadius: 12, borderRadius: 0, borderColor: '#bbbbbb' }, dropdown: { backgroundColor: 'white', borderBottomLeftRadius: 12, borderBottomRightRadius: 12, borderLeftWidth: 1, borderRightWidth: 1, borderBottomWidth: 1, marginTop: 10, maxHeight: 200, width: '100%', position: 'absolute', top: 50, zIndex: 2, borderColor: '#bbbbbb' }, dropdownItem: { padding: 10, borderBottomWidth: 1, borderBottomColor: '#ddd' }, dropdownItemPress: { backgroundColor: '#e8f8fc' } });