1
- import React , { useState , useEffect , useMemo } from 'react' ;
1
+ import React , { useMemo } from 'react' ;
2
2
import styled from 'styled-components' ;
3
3
import PostCard , { PostCardSkeleton } from './PostCard' ;
4
4
import { PartialPost } from '../../lib/graphql/post' ;
@@ -21,20 +21,30 @@ function PostCardGrid({ posts, loading, forHome }: PostCardGridProps) {
21
21
22
22
const postsWithAds = useMemo ( ( ) => {
23
23
if ( ! forHome ) return posts ;
24
+ if ( posts . length === 0 ) return posts ;
24
25
const cloned : ( PartialPost | undefined ) [ ] = [ ...posts ] ;
25
26
cloned . splice ( 4 , 0 , undefined ) ;
26
- if ( cloned . length > 30 ) {
27
+ if ( cloned . length > 21 ) {
27
28
cloned . splice ( 20 , 0 , undefined ) ;
28
29
}
30
+ if ( cloned . length > 33 ) {
31
+ cloned . splice ( 32 , 0 , undefined ) ;
32
+ }
33
+ if ( cloned . length > 49 ) {
34
+ cloned . splice ( 48 , 0 , undefined ) ;
35
+ }
36
+ if ( cloned . length > 63 ) {
37
+ cloned . splice ( 62 , 0 , undefined ) ;
38
+ }
29
39
return cloned ;
30
40
} , [ posts , forHome ] ) ;
31
41
32
42
return (
33
43
< Block >
34
- { postsWithAds . map ( ( post ) => {
44
+ { postsWithAds . map ( ( post , i ) => {
35
45
if ( post )
36
46
return < PostCard post = { post } key = { post . id } forHome = { forHome } /> ;
37
- return < AdFeed /> ;
47
+ return < AdFeed key = { i } /> ;
38
48
} ) }
39
49
{ loading &&
40
50
Array . from ( { length : 8 } ) . map ( ( _ , i ) => (
0 commit comments