Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commitc4a4aad

Browse files
committed
refactor(ContentPage): extact ContentSourceCard component
1 parent207e4a7 commitc4a4aad

File tree

9 files changed

+139
-88
lines changed

9 files changed

+139
-88
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
importReactfrom'react'
2+
importRfrom'ramda'
3+
4+
import{Wrapper,TagDot,TagTitle,NomoreDesc}from'./styles/tag_list'
5+
6+
import{uid}from'../../utils'
7+
8+
constTagList=({ items})=>{
9+
if(R.isEmpty(items))return<NomoreDesc>无标签</NomoreDesc>
10+
11+
return(
12+
<React.Fragment>
13+
{items.map(t=>(
14+
<Wrapperkey={uid.gen()}>
15+
<TagDotcolor={t.color}/>
16+
<TagTitle>{t.title}</TagTitle>
17+
</Wrapper>
18+
))}
19+
</React.Fragment>
20+
)
21+
}
22+
23+
exportdefaultTagList
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
*
3+
* ContentSourceCard
4+
*
5+
*/
6+
7+
importReactfrom'react'
8+
importPropTypesfrom'prop-types'
9+
10+
importCommunityListfrom'../CommunityList'
11+
12+
import{Wrapper,Title,Desc,NomoreDesc}from'./styles'
13+
14+
importTagListfrom'./TagList'
15+
16+
import{makeDebugger}from'../../utils'
17+
18+
/* eslint-disable no-unused-vars */
19+
constdebug=makeDebugger('c:ContentSourceCard:index')
20+
/* eslint-enable no-unused-vars */
21+
22+
constContentSourceCard=({ data})=>(
23+
<Wrapper>
24+
<Title>所属社区</Title>
25+
<Desc>
26+
<CommunityList
27+
items={data.communities}
28+
emptyHint={<NomoreDesc>不属于任何社区</NomoreDesc>}
29+
/>
30+
</Desc>
31+
<Title>标签</Title>
32+
33+
<DesccolumnnoBottom>
34+
<TagListitems={data.tags}/>
35+
</Desc>
36+
</Wrapper>
37+
)
38+
39+
ContentSourceCard.propTypes={
40+
data:PropTypes.shape({
41+
communities:PropTypes.arrayOf(
42+
PropTypes.shape({
43+
id:PropTypes.string,
44+
title:PropTypes.string,
45+
logo:PropTypes.string,
46+
raw:PropTypes.string,
47+
})
48+
),
49+
tags:PropTypes.arrayOf(
50+
PropTypes.shape({
51+
id:PropTypes.string,
52+
title:PropTypes.string,
53+
color:PropTypes.string,
54+
raw:PropTypes.string,
55+
})
56+
),
57+
}),
58+
}
59+
60+
ContentSourceCard.defaultProps={
61+
data:{
62+
communities:[],
63+
tags:[],
64+
},
65+
}
66+
67+
exportdefaultContentSourceCard

‎containers/PostContent/styles/source_card.js‎renamed to ‎components/ContentSourceCard/styles/index.js‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,3 @@ export const NomoreDesc = styled.div`
3131
color:${theme('banner.desc')};
3232
font-style: italic;
3333
`
34-
35-
exportconstTagWrapper=styled.div`
36-
display: flex;
37-
margin-bottom: 12px;
38-
margin-left: 2px;
39-
`
40-
exportconstTagDot=styled.div`
41-
width: 10px;
42-
height: 10px;
43-
background: tomato;
44-
border-radius: 50%;
45-
margin-right: 5px;
46-
`
47-
exportconstTagTitle=styled.div`
48-
margin-top: -5px;
49-
`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
importstyledfrom'styled-components'
2+
3+
import{theme}from'../../../utils'
4+
5+
exportconstWrapper=styled.div`
6+
display: flex;
7+
margin-bottom: 12px;
8+
margin-left: 2px;
9+
`
10+
exportconstTagDot=styled.div`
11+
width: 10px;
12+
height: 10px;
13+
background: tomato;
14+
border-radius: 50%;
15+
margin-right: 5px;
16+
`
17+
exportconstTagTitle=styled.div`
18+
margin-top: -5px;
19+
`
20+
21+
exportconstNomoreDesc=styled.div`
22+
color:${theme('banner.desc')};
23+
font-style: italic;
24+
`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import ContentSourceCard from '../index'
5+
6+
describe('TODO <ContentSourceCard />',()=>{
7+
it('Expect to have unit tests specified',()=>{
8+
expect(true).toEqual(true)
9+
})
10+
})

‎components/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export { default as FollowButton } from './FollowButton'
5555
export{defaultasThreadSelector}from'./ThreadSelector'
5656
export{defaultasCommunityList}from'./CommunityList'
5757
export{defaultasAuthorCard}from'./AuthorCard'
58+
export{defaultasContentSourceCard}from'./ContentSourceCard'
5859

5960
// loading component
6061
export{

‎containers/JobContent/SideCards.js‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
importReactfrom'react'
22

3-
import{AuthorCard}from'../../components'
3+
import{AuthorCard,ContentSourceCard}from'../../components'
44
import{Wrapper}from'./styles/side_cards'
5-
// import SourceCard from './SourceCard'
65

7-
constSideCards=({ data})=>{
8-
// console.log('data author: ', data.author)
9-
return(
10-
<Wrapper>
11-
<AuthorCarduser={data.author}/>
12-
{/* <SourceCard data={data} /> */}
13-
</Wrapper>
14-
)
15-
}
6+
constSideCards=({ data})=>(
7+
<Wrapper>
8+
<AuthorCarduser={data.author}/>
9+
<ContentSourceCarddata={data}/>
10+
</Wrapper>
11+
)
1612

1713
exportdefaultSideCards
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
importReactfrom'react'
22

3-
import{AuthorCard}from'../../components'
3+
import{AuthorCard,ContentSourceCard}from'../../components'
44
import{Wrapper}from'./styles/side_cards'
5-
importSourceCardfrom'./SourceCard'
65

7-
constSideCards=({ data})=>{
8-
// console.log('data author: ', data.author)
9-
return(
10-
<Wrapper>
11-
<AuthorCarduser={data.author}/>
12-
<SourceCarddata={data}/>
13-
</Wrapper>
14-
)
15-
}
6+
constSideCards=({ data})=>(
7+
<Wrapper>
8+
<AuthorCarduser={data.author}/>
9+
<ContentSourceCarddata={data}/>
10+
</Wrapper>
11+
)
1612

1713
exportdefaultSideCards

‎containers/PostContent/SourceCard.js‎

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp