@@ -29,7 +29,6 @@ type TBlog = {
2929 link ?: string
3030}
3131
32- const defaultDesc = ""
3332
3433interface Props extends BlogsBlockFragment { }
3534const PAGE_SIZE = 3
@@ -38,13 +37,6 @@ const BlogsBlock = (props: Props) => {
3837 const [ blockListing , setBlockListing ] =
3938 useState < GetPostsThumbQuery [ "posts" ] > ( )
4039 const { locale } = useLocaleContext ( )
41- const [ page , setPage ] = useState ( 0 )
42-
43- const sizes = blockListing ? blockListing . nodes . length : 0
44- const max_page = blockListing
45- ? Math . floor ( blockListing ?. nodes ?. length / PAGE_SIZE )
46- : 0
47-
4840 useEffect ( ( ) => {
4941 ; ( async ( ) => {
5042 const { data } = await getPostThumb (
@@ -54,6 +46,16 @@ const BlogsBlock = (props: Props) => {
5446 } ) ( )
5547 } , [ ] )
5648
49+ const [ page , setPage ] = useState ( 0 )
50+ const sizes = blockListing ? blockListing . nodes . length : 0
51+ const max_page = blockListing
52+ ? Math . floor ( blockListing ?. nodes ?. length / PAGE_SIZE )
53+ : 0
54+
55+ const totalPosts = blockListing ?. nodes ?. length || 0
56+ const currentlyShowing = Math . min ( ( page + 1 ) * PAGE_SIZE , totalPosts )
57+ const hasMorePosts = currentlyShowing < totalPosts
58+
5759 if ( ! blockListing && sizes < 1 )
5860 return (
5961 < div className = "container-fluid min-h-[500px] pt-10" >
@@ -125,7 +127,7 @@ const BlogsBlock = (props: Props) => {
125127 )
126128 } ) }
127129 < div className = "mt-10 flex w-full justify-center" >
128- { sizes > PAGE_SIZE && ( page + 1 ) * PAGE_SIZE < sizes && (
130+ { hasMorePosts && (
129131 < Button
130132 onClick = { ( ) =>
131133 setPage ( ( prev ) => {
0 commit comments