5
5
*/
6
6
7
7
import React from 'react'
8
- import T from 'prop-types'
9
8
10
9
import { ICON , ICON_CMD } from '@/config'
11
- import { buildLog , cutRest , nilOrEmpty } from '@/utils'
10
+ import { buildLog , cutRest } from '@/utils'
12
11
13
12
import DigestSentence from '@/components/DigestSentence'
14
13
import { SpaceGrow } from '@/components/Common'
@@ -28,36 +27,47 @@ import {
28
27
TechIcon ,
29
28
Divider ,
30
29
GithubIcon ,
31
- } from './styles'
30
+ } from './styles/works_card '
32
31
33
32
/* eslint-disable-next-line */
34
33
const log = buildLog ( 'c:WorksCard:index' )
35
34
36
- const getSafeValue = ( mode , value , defaultValue ) => {
37
- return mode === 'preview' && nilOrEmpty ( value ) ? defaultValue : value
35
+ type TProps = {
36
+ testid ?: string
37
+ withBg ?: boolean
38
+ mode ?: 'default' | 'preview'
39
+ item : {
40
+ cover : string
41
+ title : string
42
+ desc : string
43
+ tag : {
44
+ title : string
45
+ }
46
+ platform : {
47
+ title : string
48
+ }
49
+ techStack : {
50
+ icon : string
51
+ raw : string
52
+ } [ ]
53
+ insertedAt : string
54
+ upvote : number
55
+ commentsCount : number
56
+ isOSS : boolean
57
+ ossAddr ?: boolean
58
+ }
38
59
}
39
60
40
- const WorksCard = ( {
41
- withBg,
42
- testid,
43
- mode,
61
+ const WorksCard : React . FC < TProps > = ( {
62
+ testid = 'works-card' ,
44
63
item,
45
- defaultTitle,
46
- defaultDesc,
47
- defaultUpvote,
48
- defaultCommentsCount,
64
+ withBg = false ,
65
+ mode = 'default' ,
66
+ // item,
49
67
} ) => {
50
68
const descLimit = mode === 'default' ? 30 : 20
51
69
52
- const title = getSafeValue ( mode , item . title , defaultTitle )
53
- const desc = getSafeValue ( mode , item . desc , defaultDesc )
54
-
55
- const upvote = getSafeValue ( mode , item . upvote , defaultUpvote )
56
- const commentsCount = getSafeValue (
57
- mode ,
58
- item . commentsCount ,
59
- defaultCommentsCount ,
60
- )
70
+ const { title, desc, upvote, commentsCount } = item
61
71
62
72
return (
63
73
< Wrapper testid = { testid } withBg = { withBg } >
@@ -71,7 +81,7 @@ const WorksCard = ({
71
81
< Header >
72
82
< div >
73
83
< Title > { title } </ Title >
74
- < DigestSentence top = { 5 } bottom = { 15 } >
84
+ < DigestSentence top = { 5 } bottom = { 15 } onPreview = { ( ) => log } >
75
85
{ cutRest ( desc , descLimit ) }
76
86
</ DigestSentence >
77
87
</ div >
@@ -127,47 +137,4 @@ const WorksCard = ({
127
137
)
128
138
}
129
139
130
- WorksCard . propTypes = {
131
- testid : T . string ,
132
- withBg : T . bool ,
133
- mode : T . oneOf ( [ 'default' , 'preview' ] ) ,
134
- item : T . shape ( {
135
- cover : T . string ,
136
- title : T . string ,
137
- desc : T . string ,
138
- tag : T . shape ( {
139
- title : T . string ,
140
- } ) ,
141
- platform : T . shape ( {
142
- title : T . string ,
143
- } ) ,
144
- techStack : T . arrayOf (
145
- T . shape ( {
146
- icon : T . string ,
147
- } ) ,
148
- ) ,
149
- insertedAt : T . string ,
150
- upvote : T . number ,
151
- commentsCount : T . number ,
152
- isOSS : T . bool ,
153
- ossAddr : T . bool ,
154
- } ) . isRequired ,
155
-
156
- defaultTitle : T . string ,
157
- defaultDesc : T . string ,
158
- defaultUpvote : T . number ,
159
- defaultCommentsCount : T . number ,
160
- }
161
-
162
- WorksCard . defaultProps = {
163
- testid : 'works-card' ,
164
- withBg : false ,
165
- mode : 'default' ,
166
- defaultTitle : '作品名称' ,
167
- defaultDesc : '作品简介' ,
168
- defaultUpvote : 99 ,
169
- defaultCommentsCount : 66 ,
170
- // item,
171
- }
172
-
173
140
export default React . memo ( WorksCard )
0 commit comments