diff --git a/src/blog/components/Latest.tsx b/src/blog/components/Latest.tsx index c4f808e..6ed7682 100644 --- a/src/blog/components/Latest.tsx +++ b/src/blog/components/Latest.tsx @@ -8,6 +8,7 @@ import { styled } from '@mui/material/styles'; import NavigateNextRoundedIcon from '@mui/icons-material/NavigateNextRounded'; import CircularProgress from '@mui/material/CircularProgress'; import type { Article } from '../providers/Article'; // ✅ import type for correctness +import Fade from '@mui/material/Fade'; // ✅ for smooth appearance const StyledTypography = styled(Typography)({ @@ -98,12 +99,11 @@ interface LatestProps { export default function Latest({ articles, onSelectArticle, onLoadMore }: LatestProps) { const [visibleCount, setVisibleCount] = React.useState(2); const [loadingMore, setLoadingMore] = React.useState(false); + const [animating, setAnimating] = React.useState(false); + const loaderRef = React.useRef(null); const displayedArticles = articles.slice(0, visibleCount); - // Intersection Observer ref - const loaderRef = React.useRef(null); - React.useEffect(() => { if (!loaderRef.current) return; @@ -114,17 +114,22 @@ export default function Latest({ articles, onSelectArticle, onLoadMore }: Latest console.log('🟡 Intersection triggered — loading more blogs...'); setLoadingMore(true); + // simulate API load delay + await new Promise((resolve) => setTimeout(resolve, 1000)); + if (onLoadMore) { console.log(`📡 Calling onLoadMore(offset=${visibleCount}, limit=2)`); await onLoadMore(visibleCount, 2); } + setAnimating(true); setVisibleCount((prev) => { const newCount = prev + 2; console.log(`✅ Increasing visibleCount from ${prev} → ${newCount}`); return newCount; }); + setTimeout(() => setAnimating(false), 600); setLoadingMore(false); } }, @@ -150,42 +155,58 @@ export default function Latest({ articles, onSelectArticle, onLoadMore }: Latest {displayedArticles.map((article, index) => ( - - - {article.tag} - - - onSelectArticle?.(index)} + + - {article.title} - - + + {article.tag} + - - {article.description} - + onSelectArticle?.(index)} + > + {article.title} + + - - + + {article.description} + + + + + ))} - {/* Infinite scroll loader */} - - {loadingMore && } + + {loadingMore ? ( + + ) : ( + Scroll to load more... + )} );