1
- import React , { useEffect , useCallback , useRef , useState } from 'react' ;
1
+ import React , {
2
+ useEffect ,
3
+ useCallback ,
4
+ useRef ,
5
+ useState ,
6
+ useMemo ,
7
+ } from 'react' ;
2
8
import { useDispatch } from 'react-redux' ;
3
9
import {
4
10
READ_POST ,
@@ -37,6 +43,7 @@ import RelatedPost from './RelatedPost';
37
43
import optimizeImage from '../../lib/optimizeImage' ;
38
44
import { useSetShowFooter } from '../../components/velog/VelogPageTemplate' ;
39
45
import HorizontalBanner from './HorizontalBanner' ;
46
+ import gtag from '../../lib/gtag' ;
40
47
41
48
const UserProfileWrapper = styled ( VelogResponsive ) `
42
49
margin-top: 16rem;
@@ -189,6 +196,27 @@ const PostViewer: React.FC<PostViewerProps> = ({
189
196
} ;
190
197
} , [ onScroll ] ) ;
191
198
199
+ const shouldShowBanner = useMemo ( ( ) => {
200
+ if ( ! data ?. post ) return ;
201
+
202
+ const post = data . post ;
203
+ const isOwnPost = post . user . id === userId ;
204
+ const isVeryOld =
205
+ Date . now ( ) - new Date ( post . released_at ) . getTime ( ) >
206
+ 1000 * 60 * 60 * 24 * 30 ;
207
+
208
+ if ( isOwnPost ) return false ;
209
+ if ( ! isVeryOld ) return false ;
210
+ return true ;
211
+ } , [ data ?. post ] ) ;
212
+
213
+ useEffect ( ( ) => {
214
+ if ( ! data ?. post ?. id ) return ;
215
+ if ( ! shouldShowBanner ) return ;
216
+ gtag ( 'event' , 'banner_view' ) ;
217
+ console . log ( 'banner_view' ) ;
218
+ } , [ data ?. post ?. id , shouldShowBanner ] ) ;
219
+
192
220
const onRemove = async ( ) => {
193
221
if ( ! data || ! data . post ) return ;
194
222
try {
@@ -320,9 +348,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
320
348
321
349
const { post } = data ;
322
350
323
- const isVeryOld =
324
- Date . now ( ) - new Date ( post . released_at ) . getTime ( ) >
325
- 1000 * 60 * 60 * 24 * 180 ;
351
+ const isContentLongEnough = post . body . length > 500 ;
326
352
327
353
const url = `https://velog.io/@${ username } /${ post . url_slug } ` ;
328
354
@@ -388,7 +414,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
388
414
/>
389
415
}
390
416
/>
391
- { userId === null && isVeryOld ? < HorizontalBanner /> : null }
417
+ { shouldShowBanner ? < HorizontalBanner /> : null }
392
418
< PostContent isMarkdown = { post . is_markdown } body = { post . body } />
393
419
< UserProfileWrapper >
394
420
< UserProfile
@@ -411,9 +437,7 @@ const PostViewer: React.FC<PostViewerProps> = ({
411
437
}
412
438
/>
413
439
)} */ }
414
- { userId === null && isVeryOld && post . body . length > 300 ? (
415
- < HorizontalBanner />
416
- ) : null }
440
+ { shouldShowBanner && isContentLongEnough ? < HorizontalBanner /> : null }
417
441
418
442
< PostComments
419
443
count = { post . comments_count }
0 commit comments