Skip to content

Commit 299cdff

Browse files
committed
refactor(cell): add timestamp cell
1 parent 1cb4923 commit 299cdff

File tree

6 files changed

+87
-17
lines changed

6 files changed

+87
-17
lines changed

components/ContentsCountCell/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const ContentsCountCell = ({
4040
}
4141

4242
ContentsCountCell.propTypes = {
43-
// https://www.npmjs.com/package/prop-types
4443
data: PropTypes.shape({
4544
postsCount: PropTypes.number,
4645
jobsCount: PropTypes.number,

components/TimeStampCell/index.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
*
3+
* TimeStampCell
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import PropTypes from 'prop-types'
9+
import TimeAgo from 'timeago-react'
10+
11+
import { Wrapper, Content, Label, Count } from './styles'
12+
13+
import { makeDebugger } from '../../utils'
14+
15+
/* eslint-disable no-unused-vars */
16+
const debug = makeDebugger('c:TimeStampCell:index')
17+
/* eslint-enable no-unused-vars */
18+
19+
const TimeStampCell = ({ data: { insertedAt, updatedAt } }) => (
20+
<Wrapper>
21+
<Content>
22+
<Label>创建 /</Label>
23+
<Count same>
24+
<TimeAgo datetime={insertedAt} locale="zh_CN" />
25+
</Count>
26+
</Content>
27+
<Content>
28+
<Label>更新 /</Label>
29+
<Count same={insertedAt === updatedAt}>
30+
<TimeAgo datetime={updatedAt} locale="zh_CN" />
31+
</Count>
32+
</Content>
33+
</Wrapper>
34+
)
35+
36+
TimeStampCell.propTypes = {
37+
data: PropTypes.shape({
38+
insertedAt: PropTypes.string,
39+
updatedAt: PropTypes.string,
40+
}),
41+
}
42+
43+
TimeStampCell.defaultProps = {
44+
data: {
45+
insertedAt: '',
46+
updatedAt: '',
47+
},
48+
}
49+
50+
export default React.memo(TimeStampCell)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import styled from 'styled-components'
2+
3+
// import Img from '../../Img'
4+
// import { theme } from '../../../utils'
5+
6+
export const Wrapper = styled.div`
7+
display: flex;
8+
flex-direction: column;
9+
`
10+
export const Content = styled.div`
11+
display: flex;
12+
align-items: center;
13+
`
14+
15+
export const Label = styled.div`
16+
font-size: 0.7rem;
17+
margin-right: 5px;
18+
`
19+
export const Count = styled.div`
20+
color: ${({ same }) => (same ? 'grey' : 'yellowgreen')};
21+
font-size: 0.8rem;
22+
`
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 TimeStampCell from '../index'
5+
6+
describe('TODO <TimeStampCell />', () => {
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
@@ -41,6 +41,7 @@ export { default as PermissionCell } from './PermissionCell'
4141
export { default as ThreadsCell } from './ThreadsCell'
4242

4343
export { default as ContentsCountCell } from './ContentsCountCell'
44+
export { default as TimeStampCell } from './TimeStampCell'
4445
// form
4546
export { default as FormItem } from './FormItem'
4647
export { default as FormInputer } from './FormInputer'

containers/CommunitiesContent/IndexContent.js

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import React from 'react'
2-
import TimeAgo from 'timeago-react'
3-
4-
/* import { Pagination } from 'antd' */
52

63
import { cutFrom } from '../../utils'
74
import {
@@ -14,6 +11,7 @@ import {
1411
CategoriesCell,
1512
ThreadsCell,
1613
ContentsCountCell,
14+
TimeStampCell,
1715
} from '../../components'
1816

1917
import { CommunityIcon, OperationWrapper } from './styles'
@@ -118,21 +116,11 @@ const columns = [
118116
},
119117
},
120118
{
121-
title: '创建时间',
119+
title: '时间戳',
122120
width: 150,
123-
dataIndex: 'insertedAt',
124121
align: 'center',
125-
render: text => {
126-
return <TimeAgo datetime={text} locale="zh_CN" />
127-
},
128-
},
129-
{
130-
title: '上次更新',
131-
width: 150,
132-
dataIndex: 'updatedAt',
133-
align: 'center',
134-
render: text => {
135-
return <TimeAgo datetime={text} locale="zh_CN" />
122+
render: (text, record) => {
123+
return <TimeStampCell data={record} />
136124
},
137125
},
138126
{

0 commit comments

Comments
 (0)