import { useState, useEffect } from 'react'; interface SkeletonLoaderProps { count?: number; component?: | 'default' | 'analysis' | 'logs' | 'table' | 'chatbot' | 'dropdown' | 'chunkCards' | 'sourceCards'; } const SkeletonLoader: React.FC = ({ count = 1, component = 'default', }) => { const [skeletonCount, setSkeletonCount] = useState(count); useEffect(() => { const handleResize = () => { const windowWidth = window.innerWidth; if (windowWidth > 1024) { setSkeletonCount(1); } else if (windowWidth > 768) { setSkeletonCount(count); } else { setSkeletonCount(Math.min(count, 2)); } }; handleResize(); window.addEventListener('resize', handleResize); return () => { window.removeEventListener('resize', handleResize); }; }, [count]); const renderTable = () => ( <> {[...Array(4)].map((_, idx) => (
))} ); const renderChatbot = () => ( <> {[...Array(4)].map((_, idx) => (
))} ); const renderDropdown = () => (
); const renderLogs = () => (
{[...Array(8)].map((_, idx) => (
))}
); const renderDefault = () => ( <> {[...Array(skeletonCount)].map((_, idx) => (
))} ); const renderAnalysis = () => ( <> {[...Array(skeletonCount)].map((_, idx) => (
))} ); const renderChunkCards = () => ( <> {Array.from({ length: count }).map((_, index) => (
))} ); const renderSourceCards = () => ( <> {Array.from({ length: count }).map((_, idx) => (
))} ); const componentMap = { table: renderTable, chatbot: renderChatbot, dropdown: renderDropdown, logs: renderLogs, default: renderDefault, analysis: renderAnalysis, chunkCards: renderChunkCards, sourceCards: renderSourceCards, }; const render = componentMap[component] || componentMap.default; return <>{render()}; }; export default SkeletonLoader;