@@ -2,13 +2,12 @@ import { TrackingAction, TrackingEventParameter } from '@/const/trackingKeys';
2
2
import { JUMPER_LEARN_PATH } from '@/const/urls' ;
3
3
import { useUserTracking } from '@/hooks/userTracking/useUserTracking' ;
4
4
import { useMenuStore } from '@/stores/menu/MenuStore' ;
5
- import type { StrapiImageData , TagData } from '@/types/strapi' ;
5
+ import type { BlogArticleData } from '@/types/strapi' ;
6
6
import { formatDate } from '@/utils/formatDate' ;
7
7
import { readingTime } from '@/utils/readingTime' ;
8
8
import type { CSSObject } from '@mui/material' ;
9
9
import { Skeleton } from '@mui/material' ;
10
10
import Link from 'next/link' ;
11
- import type { RootNode } from 'node_modules/@strapi/blocks-react-renderer/dist/BlocksRenderer' ;
12
11
import { useTranslation } from 'react-i18next' ;
13
12
import {
14
13
BlogArticleCardContainer ,
@@ -23,63 +22,51 @@ import {
23
22
} from '.' ;
24
23
25
24
interface BlogArticleCardProps {
25
+ article : BlogArticleData ;
26
26
baseUrl : string ;
27
- id : number ;
28
- image : StrapiImageData ;
29
- content : RootNode [ ] ;
30
- publishedAt : string | null | undefined ;
31
- createdAt : string ;
32
- title : string ;
33
- tags : TagData | undefined ;
34
27
trackingCategory : string ;
35
- slug : string ;
36
28
styles ?: CSSObject ;
37
29
}
38
30
39
31
export const BlogArticleCard = ( {
32
+ article,
40
33
baseUrl,
41
34
trackingCategory,
42
- image,
43
- tags,
44
- content,
45
- publishedAt,
46
- createdAt,
47
- id,
48
- title,
49
35
styles,
50
- slug,
51
36
} : BlogArticleCardProps ) => {
52
37
const { trackEvent } = useUserTracking ( ) ;
53
- const minRead = readingTime ( content ) ;
38
+ const minRead = readingTime ( article . attributes . Content ) ;
54
39
const { t } = useTranslation ( ) ;
55
40
const { closeAllMenus } = useMenuStore ( ( state ) => state ) ;
56
-
57
41
const handleClick = ( ) => {
58
42
trackEvent ( {
59
43
category : trackingCategory ,
60
44
action : TrackingAction . ClickArticleCard ,
61
45
label : 'click-blog-article-card' ,
62
46
data : {
63
- [ TrackingEventParameter . ArticleTitle ] : title ,
64
- [ TrackingEventParameter . ArticleCardId ] : id ,
47
+ [ TrackingEventParameter . ArticleTitle ] : article . attributes . Title ,
48
+ [ TrackingEventParameter . ArticleCardId ] : article . id ,
65
49
} ,
66
50
} ) ;
67
51
closeAllMenus ( ) ;
68
52
} ;
69
53
return (
70
54
< Link
71
- href = { `${ JUMPER_LEARN_PATH } /${ slug } ` }
72
- style = { { textDecoration : 'none' } }
55
+ href = { `${ JUMPER_LEARN_PATH } /${ article . attributes . Slug } ` }
56
+ style = { { textDecoration : 'none' , width : '100%' } }
73
57
>
74
58
< BlogArticleCardContainer
75
59
variant = "outlined"
76
60
onClick = { handleClick }
77
61
sx = { styles }
78
62
>
79
- { image . data ? (
63
+ { article . attributes . Image . data ? (
80
64
< BlogArticleCardImage
81
- src = { `${ baseUrl } ${ image . data ?. attributes ?. formats . small . url } ` }
82
- alt = { image . data ?. attributes ?. alternativeText ?? title }
65
+ src = { `${ baseUrl } ${ article . attributes . Image . data ?. attributes ?. formats . small . url } ` }
66
+ alt = {
67
+ article . attributes . Image . data ?. attributes ?. alternativeText ??
68
+ article . attributes . Title
69
+ }
83
70
// read the following to udnerstand why width and height are set to 0, https://github.com/vercel/next.js/discussions/18474#discussioncomment-5501724
84
71
width = { 0 }
85
72
height = { 0 }
@@ -100,17 +87,22 @@ export const BlogArticleCard = ({
100
87
101
88
< BlogArticleCardContent >
102
89
< BlogArticleCardTitle variant = "bodyLarge" >
103
- { title }
90
+ { article . attributes . Title }
104
91
</ BlogArticleCardTitle >
105
92
< BlogArticleCardDetails >
106
- { tags ?. data . slice ( 0 , 1 ) . map ( ( tag , index ) => (
93
+ { article . attributes . tags ?. data . slice ( 0 , 1 ) . map ( ( tag , index ) => (
107
94
< BlogArticleCardTag key = { index } variant = "bodyXSmall" as = "h3" >
108
95
{ tag . attributes . Title }
109
96
</ BlogArticleCardTag >
110
97
) ) }
111
- < BlogArticleCardMetaContainer >
98
+ < BlogArticleCardMetaContainer
99
+ hasTags = { article . attributes . tags ?. data . length > 0 }
100
+ >
112
101
< BlogArticleMetaDate variant = "bodyXSmall" as = "span" >
113
- { formatDate ( publishedAt || createdAt ) }
102
+ { formatDate (
103
+ article . attributes . publishedAt ||
104
+ article . attributes . createdAt ,
105
+ ) }
114
106
</ BlogArticleMetaDate >
115
107
< BlogArticleMetaReadingTime variant = "bodyXSmall" as = "span" >
116
108
{ t ( 'blog.minRead' , { minRead : minRead } ) }
0 commit comments