import { Text, View, ActivityIndicator } from 'react-native'; import { useEffect, useState } from 'react'; import { useLocalSearchParams, useGlobalSearchParams, Link } from 'expo-router'; import { useAuth } from '../context/AuthContext'; import { SafeAreaProvider, SafeAreaView } from 'react-native-safe-area-context'; import { ScrollView } from 'react-native'; interface Container { Id: string; Names: string[]; Image: string; ImageID: string; Command: string; Created: number; State: string; Status: string; // Add other fields as needed } export default function Route() { const glob = useGlobalSearchParams(); const local = useLocalSearchParams(); const { domain, username, authData } = useAuth(); const [containers, setContainers] = useState([]); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { fetchData(); }, []); // Empty dependency array means this runs once on mount const fetchData = async () => { setIsLoading(true); try { const response = await fetch(`${domain}/api/endpoints/${local.env}/docker/containers/json?all=true`, { headers: { 'Authorization': `Bearer ${authData.jwt}` } }); const data = await response.json(); setContainers(data); } catch (error) { console.error('Error fetching data:', error); setError('Failed to fetch containers'); } finally { setIsLoading(false); } }; if (isLoading) { return ( ); } if (error) { return ( Error: {error} ); } return ( {containers.map((container) => ( {container.Names[0].replace('/', '')} Status: {container.Status} State: {container.State} Image: {container.Image} ))} ); }