import { View, Text, ScrollView, StyleSheet, ActivityIndicator, Pressable, Image } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import NormalButton from '../global/normal_button'; import { router, useFocusEffect } from 'expo-router'; import { useCallback, useEffect, useState } from 'react'; import { chargeStationService } from '../../service/chargeStationService'; // const RETRY_DELAY = 2000; // 2 seconds // const MAX_RETRIES = 3; // Maximum number of retry attempts const NoChargingOngoingPageComponent = () => { const [newAvailableConnectors, setNewAvailableConnectors] = useState([]); useFocusEffect( useCallback(() => { let isMounted = true; // Simple cleanup flag const fetchAllConnectors = async () => { try { const newAvailableConnectors = await chargeStationService.NewfetchAvailableConnectors(); // Only update state if component is still mounted if (isMounted) { // Sort the connectors based on stationID const sortedConnectors = [...newAvailableConnectors].sort((a, b) => { // Custom sorting order const order: Record = { '2405311022116801000': 1, // 觀塘偉業街 '2411291610329331000': 2, // 黃竹坑 '2501161430118231000': 3 // 沙頭角 }; return (order[a.stationID] || 999) - (order[b.stationID] || 999); }); setNewAvailableConnectors(sortedConnectors); } } catch (error) { console.error('Fetch error:', error); } }; fetchAllConnectors(); // Simple cleanup - prevents state updates if component unmounts return () => { isMounted = false; }; }, []) // Add any missing dependencies here if needed ); const StationRow = ({ item }: { item: any }) => { let imgObj = null; if (item.image) { imgObj = { uri: item.image }; } else { imgObj = require('../../assets/dummyStationPicture.png'); } return ( { router.push({ pathname: '/resultDetailPage', params: { chargeStationAddress: item.address, chargeStationID: item.stationID, chargeStationName: item.stationName, availableConnectors: item.availableConnectors, imageSource: item.image, stationLng: item.stationLng, stationLat: item.stationLat, pricemodel_id: item.pricemodel_id } }); }} > {item.stationName} {item.address} 現時可用充電槍數目: {item.availableConnectors} ); }; return ( 暫無正在進行的充電 立刻前往Crazy Charge 充電站充電吧! {newAvailableConnectors?.map((item: any, index: number) => ( ))} ); }; const styles = StyleSheet.create({ grayColor: { color: '#888888' }, greenColor: { color: '#02677D' }, image: { width: 100, height: 100, margin: 15, borderRadius: 10 } }); export default NoChargingOngoingPageComponent;