Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit f7f1c4a

Browse files
committed
refactor(cheatsheet): UI / UX refactor
1 parent 2813a98 commit f7f1c4a

File tree

34 files changed

+1381
-49
lines changed

34 files changed

+1381
-49
lines changed

components/CommunityContent/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import ReposThread from '../../containers/ReposThread'
1313
import WikiThread from '../../containers/WikiThread'
1414
import JobsThread from '../../containers/JobsThread'
1515
import UsersThread from '../../containers/UsersThread'
16-
import CheatSheetPaper from '../../containers/CheatSheetPaper'
16+
import CheatsheetThread from '../../containers/CheatsheetThread'
17+
// import CheatSheetPaper from '../../containers/CheatSheetPaper'
1718

1819
import { Wrapper } from './styles'
1920
import { makeDebugger, ROUTE } from '../../utils'
@@ -42,8 +43,9 @@ const ComunityContent = ({ curRoute }) => {
4243
case ROUTE.WIKI: {
4344
return <WikiThread />
4445
}
45-
case 'cheatsheet': {
46-
return <CheatSheetPaper />
46+
case ROUTE.CHEATSHEET: {
47+
// return <CheatSheetPaper />
48+
return <CheatsheetThread />
4749
}
4850
default: {
4951
return <div>default</div>

components/ContributorList/index.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
*
3+
* ContributorList
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import PropTypes from 'prop-types'
9+
10+
import Maybe from '../Maybe'
11+
import Popover from '../Popover'
12+
import GithubUserCard from '../GithubUserCard'
13+
import AvatarAdder from '../../containers/AvatarAdder'
14+
15+
import { Wrapper, AvatarLink, Avatar, CardWrapper } from './styles'
16+
17+
import { makeDebugger, uid } from '../../utils'
18+
/* eslint-disable no-unused-vars */
19+
const debug = makeDebugger('c:ContributorList:index')
20+
/* eslint-enable no-unused-vars */
21+
22+
const ContributorList = ({ users, showAdder, addContributor }) => (
23+
<Wrapper>
24+
{users.map(user => (
25+
<Popover
26+
content={
27+
<CardWrapper>
28+
<GithubUserCard user={user} />
29+
</CardWrapper>
30+
}
31+
placement="bottom"
32+
trigger="hover"
33+
key={uid.gen()}
34+
>
35+
<AvatarLink>
36+
<Avatar src={user.avatar} />
37+
</AvatarLink>
38+
</Popover>
39+
))}
40+
41+
<Maybe test={showAdder}>
42+
<AvatarAdder onConfirm={addContributor} />
43+
</Maybe>
44+
</Wrapper>
45+
)
46+
47+
ContributorList.propTypes = {
48+
users: PropTypes.arrayOf(
49+
PropTypes.shape({
50+
avatar: PropTypes.string,
51+
nickname: PropTypes.string,
52+
bio: PropTypes.string,
53+
company: PropTypes.string,
54+
location: PropTypes.string,
55+
htmlUrl: PropTypes.string,
56+
})
57+
).isRequired,
58+
addContributor: PropTypes.func,
59+
showAdder: PropTypes.bool,
60+
}
61+
62+
ContributorList.defaultProps = {
63+
addContributor: debug,
64+
showAdder: false,
65+
}
66+
67+
export default ContributorList

containers/WikiThread/styles/avatar_list.js renamed to components/ContributorList/styles/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from 'styled-components'
22

3-
import Img from '../../../components/Img'
4-
/* import { theme } from '../../../utils' */
3+
import Img from '../../Img'
4+
// import { theme } from '../../../utils'
55

66
export const Wrapper = styled.div`
77
display: flex;
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 ContributorList from '../index'
5+
6+
describe('TODO <ContributorList />', () => {
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
@@ -43,6 +43,7 @@ export { default as SectionLabel } from './SectionLabel'
4343
export { default as BuyMeChuanChuan } from './BuyMeChuanChuan'
4444
export { default as VideoSourceInfo } from './VideoSourceInfo'
4545

46+
export { default as ContributorList } from './ContributorList'
4647
export { default as GithubRepoPage } from './GithubRepoPage'
4748
export { default as GithubUserCard } from './GithubUserCard'
4849

containers/AvatarAdder/AdderPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from 'react'
22

33
import { ICON_CMD } from '../../config'
44

5-
import { GithubUserCard, Maybe } from '../../components'
5+
import Maybe from '../../components/Maybe'
6+
import GithubUserCard from '../../components/GithubUserCard'
67

78
import {
89
Wrapper,

containers/AvatarAdder/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
* AvatarAdder
44
*
55
*/
6-
76
import React from 'react'
87
import { inject, observer } from 'mobx-react'
98
import PropTypes from 'prop-types'
109

11-
import { Popover } from '../../components'
10+
import Popover from '../../components/Popover'
1211

1312
import { Wrapper, AddText } from './styles'
14-
1513
import AdderPanel from './AdderPanel'
1614

1715
import { makeDebugger, storePlug } from '../../utils'

containers/AvatarAdder/styles/adder_panel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import styled from 'styled-components'
22

3-
// import { Input } from 'antd'
43
import Img from '../../../components/Img'
54
import { theme } from '../../../utils'
65

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react'
2+
import Masonry from 'react-masonry-component'
3+
import Remarkable from 'remarkable'
4+
import remarkableemoj from 'remarkable-emoji'
5+
// import Prism from 'mastani-codehighlight'
6+
7+
import { Wrapper, CardWrapper } from './styles/cheatsheet'
8+
import CheatSheetStyle from './styles/CheatsheetMarkStyles'
9+
10+
import { uid } from '../../utils'
11+
12+
const md = new Remarkable()
13+
md.use(remarkableemoj)
14+
15+
const Cards = ({ cards }) =>
16+
cards.map(item => (
17+
<CardWrapper key={uid.gen()}>
18+
<CheatSheetStyle>
19+
<div
20+
className="cheatsheet-body"
21+
dangerouslySetInnerHTML={{
22+
__html: md.render(item),
23+
}}
24+
/>
25+
</CheatSheetStyle>
26+
</CardWrapper>
27+
))
28+
29+
const Cheatsheet = ({ source }) => (
30+
<Wrapper>
31+
{source.map(item => (
32+
<CheatSheetStyle key={uid.gen()}>
33+
<div
34+
className="cheatsheet-body"
35+
dangerouslySetInnerHTML={{
36+
__html: md.render(item.header),
37+
}}
38+
/>
39+
<Masonry>
40+
<Cards cards={item.cards} />
41+
</Masonry>
42+
</CheatSheetStyle>
43+
))}
44+
</Wrapper>
45+
)
46+
47+
export default Cheatsheet

containers/CheatsheetThread/Note.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
3+
import { DotDivider, ContributorList } from '../../components'
4+
5+
import {
6+
Wrapper,
7+
Divider,
8+
Text,
9+
Title,
10+
JoinText,
11+
ViewsText,
12+
} from './styles/note'
13+
14+
import fakeusers from './fakeusers'
15+
16+
const Note = () => (
17+
<Wrapper>
18+
<Divider />
19+
<Text>
20+
<Title>本页贡献者</Title> <DotDivider /> <JoinText>参与编辑</JoinText>
21+
<ViewsText>浏览: 244</ViewsText>
22+
</Text>
23+
<ContributorList users={fakeusers} showAdder />
24+
</Wrapper>
25+
)
26+
27+
export default Note
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fakeusers = [
2+
{
3+
avatar: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
4+
nickname: 'nickname',
5+
bio: 'bio',
6+
company: 'company',
7+
location: 'location',
8+
htmlUrl: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
9+
},
10+
{
11+
avatar: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
12+
nickname: 'nickname',
13+
bio: 'bio',
14+
company: 'company',
15+
location: 'location',
16+
htmlUrl: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
17+
},
18+
{
19+
avatar: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
20+
nickname: 'nickname',
21+
bio: 'bio',
22+
company: 'company',
23+
location: 'location',
24+
htmlUrl: 'https://avatars2.githubusercontent.com/u/6184465?v=4',
25+
},
26+
]
27+
28+
export default fakeusers

containers/CheatsheetThread/index.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
*
3+
* CheatsheetThread
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import { inject, observer } from 'mobx-react'
9+
import Prism from 'mastani-codehighlight'
10+
11+
import { Wrapper } from './styles'
12+
13+
// import { NotFound, CheatSheetLoading } from '../../components'
14+
15+
import Cheatsheet from './Cheatsheet'
16+
import Note from './Note'
17+
18+
import { makeDebugger, storePlug } from '../../utils'
19+
import * as logic from './logic'
20+
/* eslint-disable no-unused-vars */
21+
const debug = makeDebugger('C:CheatsheetThread')
22+
/* eslint-enable no-unused-vars */
23+
24+
/*
25+
const renderContent = (source, state, errMsg) => {
26+
switch (state) {
27+
case 'init': {
28+
return <div>init la</div>
29+
}
30+
case 'loading': {
31+
return <CheatSheetLoading />
32+
}
33+
case '404': {
34+
return <NotFound />
35+
}
36+
case 'empty': {
37+
return <div>isEmpty</div>
38+
}
39+
case 'loaded': {
40+
return <Cheatsheet source={source} />
41+
}
42+
case 'parse_error': {
43+
return <h3>parse error</h3>
44+
}
45+
default:
46+
return <div>default</div>
47+
}
48+
}
49+
*/
50+
51+
class CheatsheetThreadContainer extends React.Component {
52+
componentWillMount() {
53+
const { cheatsheetThread } = this.props
54+
logic.init(cheatsheetThread)
55+
}
56+
57+
componentDidMount() {
58+
Prism.highlightAll()
59+
}
60+
61+
render() {
62+
const { cheatsheetThread } = this.props
63+
const { sourceData /* state, errMsg */ } = cheatsheetThread
64+
65+
// console.log('sourceData --> ', sourceData)
66+
// <div>{renderContent(source, state, errMsg)}</div>
67+
68+
// <div>{renderContent(sourceData, state, errMsg)}</div>
69+
70+
return (
71+
<Wrapper>
72+
<Cheatsheet source={sourceData} />
73+
<Note />
74+
</Wrapper>
75+
)
76+
}
77+
}
78+
79+
export default inject(storePlug('cheatsheetThread'))(
80+
observer(CheatsheetThreadContainer)
81+
)

containers/CheatsheetThread/lang.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* CheatsheetThread Langs
3+
*
4+
* This contains all the text for the CheatsheetThread component.
5+
*/
6+
import { defineMessages } from 'react-intl'
7+
8+
export default defineMessages({
9+
header: {
10+
id: 'containers.CheatsheetThread.header',
11+
defaultMessage: 'This is the CheatsheetThread component !',
12+
},
13+
})

0 commit comments

Comments
 (0)