mirror of
https://github.com/johndoe6345789/docker-swarm-termina.git
synced 2026-05-04 18:44:59 +00:00
70d32f13b2
ContainerCard: 354 -> 91 LOC - Extract useContainerActions custom hook (88 LOC) - Split into sub-components: - ContainerHeader (77 LOC) - ContainerInfo (54 LOC) - ContainerActions (125 LOC) - DeleteConfirmDialog (41 LOC) Dashboard: 249 -> 89 LOC - Extract useContainerList hook (39 LOC) - Extract useTerminalModal hook (24 LOC) - Split into sub-components: - DashboardHeader (118 LOC) - EmptyState (44 LOC) All React components now under 150 LOC for better maintainability https://claude.ai/code/session_01U3wVqokhrL3dTeq2dTq73n
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { useState, useEffect } from 'react';
|
|
import { apiClient, Container } from '@/lib/api';
|
|
|
|
export function useContainerList(isAuthenticated: boolean) {
|
|
const [containers, setContainers] = useState<Container[]>([]);
|
|
const [isRefreshing, setIsRefreshing] = useState(false);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [error, setError] = useState('');
|
|
|
|
const fetchContainers = async () => {
|
|
setIsRefreshing(true);
|
|
setError('');
|
|
try {
|
|
const data = await apiClient.getContainers();
|
|
setContainers(data);
|
|
} catch (err) {
|
|
setError(err instanceof Error ? err.message : 'Failed to fetch containers');
|
|
} finally {
|
|
setIsRefreshing(false);
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
if (isAuthenticated) {
|
|
fetchContainers();
|
|
const interval = setInterval(fetchContainers, 10000);
|
|
return () => clearInterval(interval);
|
|
}
|
|
}, [isAuthenticated]);
|
|
|
|
return {
|
|
containers,
|
|
isRefreshing,
|
|
isLoading,
|
|
error,
|
|
refreshContainers: fetchContainers,
|
|
};
|
|
}
|