|
|
@@ -7,7 +7,8 @@ import {
|
|
|
StyleSheet,
|
|
|
Image,
|
|
|
ImageSourcePropType,
|
|
|
- Pressable
|
|
|
+ Pressable,
|
|
|
+ ActivityIndicator
|
|
|
} from 'react-native';
|
|
|
import { TabView, SceneMap, TabBar } from 'react-native-tab-view';
|
|
|
import { FlashList } from '@shopify/flash-list';
|
|
|
@@ -15,6 +16,8 @@ import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
|
|
import { router } from 'expo-router';
|
|
|
import { CheckMarkLogoSvg, CrossLogoSvg } from '../global/SVG';
|
|
|
+import { useEffect, useState } from 'react';
|
|
|
+import { chargeStationService } from '../../service/chargeStationService';
|
|
|
|
|
|
interface TabItem {
|
|
|
imgURL: ImageSourcePropType;
|
|
|
@@ -23,6 +26,7 @@ interface TabItem {
|
|
|
chargeStationName: string;
|
|
|
chargeStationAddress: string;
|
|
|
distance: string;
|
|
|
+ stationID: string;
|
|
|
}
|
|
|
|
|
|
interface TabViewComponentProps {
|
|
|
@@ -30,264 +34,287 @@ interface TabViewComponentProps {
|
|
|
tabItems: TabItem[];
|
|
|
}
|
|
|
|
|
|
-const dummyTabItems: TabItem[] = [
|
|
|
- {
|
|
|
- imgURL: require('../../assets/dummyStationPicture.png'),
|
|
|
- date: '今天',
|
|
|
- time: '16:30',
|
|
|
- chargeStationName: '上環街市充電站',
|
|
|
- chargeStationAddress: '香港上環皇后大道中345號',
|
|
|
- distance: '400米'
|
|
|
- },
|
|
|
- {
|
|
|
- imgURL: require('../../assets/dummyStationPicture2.png'),
|
|
|
- date: '3月15',
|
|
|
- time: '17:45',
|
|
|
- chargeStationName: '中環IFC充電站',
|
|
|
- chargeStationAddress: '香港中環皇后大道中999號',
|
|
|
- distance: '680米'
|
|
|
- },
|
|
|
- {
|
|
|
- imgURL: require('../../assets/dummyStationPicture2.png'),
|
|
|
- date: '4月20',
|
|
|
- time: '12:30',
|
|
|
- chargeStationName: '中環IFC充電站',
|
|
|
- chargeStationAddress: '香港中環皇后大道中999號',
|
|
|
- distance: '680米'
|
|
|
- },
|
|
|
- {
|
|
|
- imgURL: require('../../assets/dummyStationPicture.png'),
|
|
|
- date: '今天',
|
|
|
- time: '16:30',
|
|
|
- chargeStationName: '上環街市充電站',
|
|
|
- chargeStationAddress: '香港上環皇后大道中345號',
|
|
|
- distance: '400米'
|
|
|
- },
|
|
|
- {
|
|
|
- imgURL: require('../../assets/dummyStationPicture.png'),
|
|
|
- date: '今天',
|
|
|
- time: '16:30',
|
|
|
- chargeStationName: '上環街市充電站',
|
|
|
- chargeStationAddress: '香港上環皇后大道中345號',
|
|
|
- distance: '400米'
|
|
|
- }
|
|
|
-];
|
|
|
+const ReservationLocationPage = () => {
|
|
|
+ const [stations, setStations] = useState([]);
|
|
|
+ const [TabItems, setTabItems] = useState<TabItem[]>([]);
|
|
|
|
|
|
-const LocationTabComponent: React.FC<TabViewComponentProps> = ({
|
|
|
- titles,
|
|
|
- tabItems
|
|
|
-}) => {
|
|
|
- const layout = useWindowDimensions();
|
|
|
+ const LocationTabComponent: React.FC<TabViewComponentProps> = ({
|
|
|
+ titles,
|
|
|
+ tabItems
|
|
|
+ }) => {
|
|
|
+ const layout = useWindowDimensions();
|
|
|
|
|
|
- const FirstRoute = () => (
|
|
|
- <View style={{ flex: 1, backgroundColor: 'white' }}>
|
|
|
- <FlashList
|
|
|
- data={tabItems}
|
|
|
- renderItem={({ item }) => {
|
|
|
- return (
|
|
|
- <Pressable
|
|
|
- // onPress={() => console.log('clicked')}
|
|
|
- onPress={() => router.push('resultDetailPage')}
|
|
|
- style={({ pressed }) => [
|
|
|
- styles.container,
|
|
|
- {
|
|
|
- backgroundColor: pressed
|
|
|
- ? '#e7f2f8'
|
|
|
- : '#ffffff'
|
|
|
- }
|
|
|
- ]}
|
|
|
- >
|
|
|
- <View style={styles.container}>
|
|
|
- <Image
|
|
|
- style={styles.image}
|
|
|
- source={item.imgURL}
|
|
|
- />
|
|
|
- <View style={styles.textContainer}>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 18,
|
|
|
- color: '#222222'
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.chargeStationName}
|
|
|
- </Text>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 14,
|
|
|
- color: '#888888'
|
|
|
- }}
|
|
|
+ const FirstRoute = () => (
|
|
|
+ <View style={{ flex: 1, backgroundColor: 'white' }}>
|
|
|
+ {TabItems.length > 0 ? (
|
|
|
+ <FlashList
|
|
|
+ data={tabItems}
|
|
|
+ renderItem={({ item }) => {
|
|
|
+ return (
|
|
|
+ <Pressable
|
|
|
+ onPress={() =>
|
|
|
+ router.push({
|
|
|
+ pathname: '/resultDetailPage',
|
|
|
+ params: {
|
|
|
+ chargeStationAddress:
|
|
|
+ item.chargeStationAddress,
|
|
|
+ chargeStationName:
|
|
|
+ item.chargeStationName,
|
|
|
+ chargeStationID: item.stationID
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ style={({ pressed }) => [
|
|
|
+ styles.container,
|
|
|
+ {
|
|
|
+ backgroundColor: pressed
|
|
|
+ ? '#e7f2f8'
|
|
|
+ : '#ffffff'
|
|
|
+ }
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <View
|
|
|
+ style={styles.container}
|
|
|
+ className=" flex-1 flex-row "
|
|
|
>
|
|
|
- {item.chargeStationAddress}
|
|
|
- </Text>
|
|
|
- <View className=" flex-row space-x-2 items-center">
|
|
|
- <CheckMarkLogoSvg />
|
|
|
+ <Image
|
|
|
+ style={styles.image}
|
|
|
+ source={item.imgURL}
|
|
|
+ />
|
|
|
+ <View
|
|
|
+ style={styles.textContainer}
|
|
|
+ className="flex-1 justify-evenly"
|
|
|
+ >
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 20,
|
|
|
+ color: '#222222'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {item.chargeStationName}
|
|
|
+ </Text>
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 14,
|
|
|
+ color: '#888888'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {item.chargeStationAddress}
|
|
|
+ </Text>
|
|
|
+ <View className=" flex-row space-x-2 items-center">
|
|
|
+ <CheckMarkLogoSvg />
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 14,
|
|
|
+ color: '#222222'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Walk-in
|
|
|
+ </Text>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+
|
|
|
<Text
|
|
|
style={{
|
|
|
fontWeight: 400,
|
|
|
- fontSize: 14,
|
|
|
- color: '#222222'
|
|
|
+ fontSize: 16,
|
|
|
+ color: '#888888',
|
|
|
+ marginTop: 22,
|
|
|
+ marginLeft: 'auto',
|
|
|
+ marginRight: 10
|
|
|
}}
|
|
|
>
|
|
|
- Walk-in
|
|
|
+ {item.distance}
|
|
|
</Text>
|
|
|
</View>
|
|
|
- </View>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 16,
|
|
|
- color: '#888888',
|
|
|
- marginTop: 22
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.distance}
|
|
|
- </Text>
|
|
|
- </View>
|
|
|
- </Pressable>
|
|
|
- );
|
|
|
- }}
|
|
|
- estimatedItemSize={10}
|
|
|
- />
|
|
|
- </View>
|
|
|
- );
|
|
|
+ </Pressable>
|
|
|
+ );
|
|
|
+ }}
|
|
|
+ estimatedItemSize={10}
|
|
|
+ />
|
|
|
+ ) : (
|
|
|
+ <View className="flex-1 items-center justify-center">
|
|
|
+ <ActivityIndicator size="large" />
|
|
|
+ </View>
|
|
|
+ )}
|
|
|
+ </View>
|
|
|
+ );
|
|
|
|
|
|
- //tab 2
|
|
|
+ //tab 2
|
|
|
|
|
|
- const SecondRoute = () => (
|
|
|
- <View style={{ flex: 1, backgroundColor: 'white' }}>
|
|
|
- <FlashList
|
|
|
- data={tabItems}
|
|
|
- renderItem={({ item }) => {
|
|
|
- return (
|
|
|
- <Pressable
|
|
|
- // onPress={() => console.log('clicked')}
|
|
|
- onPress={() => router.push('resultDetailPage')}
|
|
|
- style={({ pressed }) => [
|
|
|
- styles.container,
|
|
|
- {
|
|
|
- backgroundColor: pressed
|
|
|
- ? '#e7f2f8'
|
|
|
- : '#ffffff'
|
|
|
+ const SecondRoute = () => (
|
|
|
+ <View style={{ flex: 1, backgroundColor: 'white' }}>
|
|
|
+ <FlashList
|
|
|
+ data={tabItems}
|
|
|
+ renderItem={({ item }) => {
|
|
|
+ return (
|
|
|
+ <Pressable
|
|
|
+ onPress={() =>
|
|
|
+ router.push({
|
|
|
+ pathname: '/resultDetailPage',
|
|
|
+ params: {
|
|
|
+ chargeStationAddress:
|
|
|
+ item.chargeStationAddress,
|
|
|
+ chargeStationName:
|
|
|
+ item.chargeStationName
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
- ]}
|
|
|
- >
|
|
|
- <View style={styles.container}>
|
|
|
- <Image
|
|
|
- style={styles.image}
|
|
|
- source={item.imgURL}
|
|
|
- />
|
|
|
- <View style={styles.textContainer}>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 18,
|
|
|
- color: '#222222'
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.chargeStationName}
|
|
|
- </Text>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 14,
|
|
|
- color: '#888888'
|
|
|
- }}
|
|
|
+ style={({ pressed }) => [
|
|
|
+ styles.container,
|
|
|
+ {
|
|
|
+ backgroundColor: pressed
|
|
|
+ ? '#e7f2f8'
|
|
|
+ : '#ffffff'
|
|
|
+ }
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <View
|
|
|
+ style={styles.container}
|
|
|
+ className=" flex-1 flex-row "
|
|
|
+ >
|
|
|
+ <Image
|
|
|
+ style={styles.image}
|
|
|
+ source={item.imgURL}
|
|
|
+ />
|
|
|
+ <View
|
|
|
+ style={styles.textContainer}
|
|
|
+ className="flex-1 justify-evenly"
|
|
|
>
|
|
|
- {item.chargeStationAddress}
|
|
|
- </Text>
|
|
|
- <View className=" flex-row space-x-2 items-center">
|
|
|
- <CheckMarkLogoSvg />
|
|
|
<Text
|
|
|
style={{
|
|
|
fontWeight: 400,
|
|
|
- fontSize: 14,
|
|
|
+ fontSize: 20,
|
|
|
color: '#222222'
|
|
|
}}
|
|
|
>
|
|
|
- Walk-in
|
|
|
+ {item.chargeStationName}
|
|
|
</Text>
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 14,
|
|
|
+ color: '#888888'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {item.chargeStationAddress}
|
|
|
+ </Text>
|
|
|
+ <View className=" flex-row space-x-2 items-center">
|
|
|
+ <CheckMarkLogoSvg />
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 14,
|
|
|
+ color: '#222222'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Walk-in
|
|
|
+ </Text>
|
|
|
+ </View>
|
|
|
</View>
|
|
|
+
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontWeight: 400,
|
|
|
+ fontSize: 16,
|
|
|
+ color: '#888888',
|
|
|
+ marginTop: 22,
|
|
|
+ marginLeft: 'auto',
|
|
|
+ marginRight: 10
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {item.distance}
|
|
|
+ </Text>
|
|
|
</View>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- fontWeight: 400,
|
|
|
- fontSize: 16,
|
|
|
- color: '#888888',
|
|
|
- marginTop: 22
|
|
|
- }}
|
|
|
- >
|
|
|
- {item.distance}
|
|
|
- </Text>
|
|
|
- </View>
|
|
|
- </Pressable>
|
|
|
- );
|
|
|
+ </Pressable>
|
|
|
+ );
|
|
|
+ }}
|
|
|
+ estimatedItemSize={10}
|
|
|
+ />
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+
|
|
|
+ const renderScene = SceneMap({
|
|
|
+ firstRoute: FirstRoute,
|
|
|
+ secondRoute: SecondRoute
|
|
|
+ });
|
|
|
+ const [routes] = React.useState([
|
|
|
+ { key: 'firstRoute', title: titles[0] },
|
|
|
+ { key: 'secondRoute', title: titles[1] }
|
|
|
+ ]);
|
|
|
+ const [index, setIndex] = React.useState(0);
|
|
|
+
|
|
|
+ const renderTabBar = (props: any) => (
|
|
|
+ <TabBar
|
|
|
+ {...props}
|
|
|
+ renderLabel={({ route, focused }) => (
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: focused ? '#025c72' : '#888888',
|
|
|
+ fontWeight: focused ? '900' : 'thin',
|
|
|
+ fontSize: 20
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {route.title}
|
|
|
+ </Text>
|
|
|
+ )}
|
|
|
+ indicatorStyle={{
|
|
|
+ backgroundColor: '#025c72'
|
|
|
+ }}
|
|
|
+ style={{
|
|
|
+ backgroundColor: 'white',
|
|
|
+ borderColor: '#DBE4E8',
|
|
|
+ elevation: 0,
|
|
|
+ borderBottomWidth: 0.5
|
|
|
}}
|
|
|
- estimatedItemSize={10}
|
|
|
/>
|
|
|
- </View>
|
|
|
- );
|
|
|
- const renderScene = SceneMap({
|
|
|
- firstRoute: FirstRoute,
|
|
|
- secondRoute: SecondRoute
|
|
|
- });
|
|
|
- const [routes] = React.useState([
|
|
|
- { key: 'firstRoute', title: titles[0] },
|
|
|
- { key: 'secondRoute', title: titles[1] }
|
|
|
- ]);
|
|
|
- const [index, setIndex] = React.useState(0);
|
|
|
+ );
|
|
|
+ return (
|
|
|
+ <TabView
|
|
|
+ navigationState={{ index, routes }}
|
|
|
+ renderScene={renderScene}
|
|
|
+ onIndexChange={setIndex}
|
|
|
+ // initialLayout={{ width: layout.width }}
|
|
|
+ renderTabBar={renderTabBar}
|
|
|
+ />
|
|
|
+ );
|
|
|
+ };
|
|
|
|
|
|
- const renderTabBar = (props: any) => (
|
|
|
- <TabBar
|
|
|
- {...props}
|
|
|
- renderLabel={({ route, focused }) => (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: focused ? '#025c72' : '#888888',
|
|
|
- fontWeight: focused ? '900' : 'thin',
|
|
|
- fontSize: 20
|
|
|
- }}
|
|
|
- >
|
|
|
- {route.title}
|
|
|
- </Text>
|
|
|
- )}
|
|
|
- indicatorStyle={{
|
|
|
- backgroundColor: '#025c72'
|
|
|
- }}
|
|
|
- style={{
|
|
|
- backgroundColor: 'white',
|
|
|
- borderColor: '#DBE4E8',
|
|
|
- elevation: 0,
|
|
|
- borderBottomWidth: 0.5
|
|
|
- }}
|
|
|
- />
|
|
|
- );
|
|
|
- return (
|
|
|
- <TabView
|
|
|
- navigationState={{ index, routes }}
|
|
|
- renderScene={renderScene}
|
|
|
- onIndexChange={setIndex}
|
|
|
- initialLayout={{ width: layout.width }}
|
|
|
- renderTabBar={renderTabBar}
|
|
|
- />
|
|
|
- );
|
|
|
-};
|
|
|
+ const styles = StyleSheet.create({
|
|
|
+ container: { flexDirection: 'row' },
|
|
|
+ image: {
|
|
|
+ width: 100,
|
|
|
+ height: 100,
|
|
|
+ marginTop: 15,
|
|
|
+ marginRight: 15,
|
|
|
+ borderRadius: 10
|
|
|
+ },
|
|
|
+ textContainer: { flexDirection: 'column', gap: 4, marginTop: 15 }
|
|
|
+ });
|
|
|
|
|
|
-const styles = StyleSheet.create({
|
|
|
- container: { flexDirection: 'row' },
|
|
|
- image: {
|
|
|
- width: 100,
|
|
|
- height: 100,
|
|
|
- marginTop: 15,
|
|
|
- marginRight: 15,
|
|
|
+ useEffect(() => {
|
|
|
+ const fetchStations = async () => {
|
|
|
+ const fetchedStations =
|
|
|
+ await chargeStationService.fetchChargeStations();
|
|
|
+
|
|
|
+ setStations(fetchedStations);
|
|
|
|
|
|
- borderRadius: 10
|
|
|
- },
|
|
|
- textContainer: { flexDirection: 'column', gap: 8, marginTop: 22 }
|
|
|
-});
|
|
|
+ const TabItems = fetchedStations.map((station) => ({
|
|
|
+ chargeStationAddress: station.Address,
|
|
|
+ chargeStationName: station.StationName,
|
|
|
+ date: '今天',
|
|
|
+ stationID: station.StationID,
|
|
|
+ imgURL: require('../../assets/dummyStationPicture.png'),
|
|
|
+ distance: '400米'
|
|
|
+ }));
|
|
|
+ setTabItems(TabItems);
|
|
|
+ };
|
|
|
+ fetchStations();
|
|
|
+ }, []);
|
|
|
|
|
|
-const ReservationLocationPage = () => {
|
|
|
return (
|
|
|
<SafeAreaView
|
|
|
className="flex-1 bg-white"
|
|
|
@@ -339,7 +366,7 @@ const ReservationLocationPage = () => {
|
|
|
<View className="flex-1 mt-2">
|
|
|
<LocationTabComponent
|
|
|
titles={['附近的充電站', '所有的充電站']}
|
|
|
- tabItems={dummyTabItems}
|
|
|
+ tabItems={TabItems}
|
|
|
/>
|
|
|
</View>
|
|
|
</View>
|
|
|
@@ -347,4 +374,4 @@ const ReservationLocationPage = () => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
-export default ReservationLocationPage;
|
|
|
+export default ReservationLocationPage;
|