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

Commit 4a2f381

Browse files
committed
refactor(misc): communitiesContent & basic repo
1 parent ec43456 commit 4a2f381

File tree

24 files changed

+650
-257
lines changed

24 files changed

+650
-257
lines changed

components/UserCell/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import PropTypes from 'prop-types'
99

1010
import { UserCellWrapper, Avatar, NickName } from './styles'
1111

12-
import { makeDebugger } from '../../utils'
12+
import { makeDebugger, cutFrom } from '../../utils'
1313
/* eslint-disable no-unused-vars */
1414
const debug = makeDebugger('c:UserCell:index')
1515
/* eslint-enable no-unused-vars */
@@ -18,7 +18,7 @@ const UserCell = ({ user, align, left, small }) => (
1818
<div>
1919
<UserCellWrapper align={align} left={left}>
2020
<Avatar src={user.avatar} alt={user.nickname} small={small} />
21-
<NickName>{user.nickname}</NickName>
21+
<NickName>{cutFrom(user.nickname, 15)}</NickName>
2222
</UserCellWrapper>
2323
</div>
2424
)

containers/CommunitiesBanner/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ const ChildBanner = ({
5454
/>
5555
)
5656
}
57-
5857
case ROUTE.TAGS: {
5958
return (
6059
<TagsBanner
@@ -90,6 +89,12 @@ const ChildBanner = ({
9089
/>
9190
)
9291
}
92+
case ROUTE.REPOS: {
93+
return <h3>REPOS Banner</h3>
94+
}
95+
case ROUTE.VIDEOS: {
96+
return <h3>VIDEOS Banner</h3>
97+
}
9398
default: {
9499
return (
95100
<IndexBanner

containers/CommunitiesContent/IndexContent.js

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,40 +155,27 @@ const columns = [
155155
},
156156
]
157157

158-
class IndexContent extends React.Component {
159-
componentDidMount() {
160-
logic.loadCommunitiesIfOnClient()
161-
}
162-
163-
render() {
164-
const {
165-
data,
166-
restProps: { communitiesLoading },
167-
} = this.props
168-
169-
return (
158+
const IndexContent = ({ data, restProps: { communitiesLoading } }) => (
159+
<React.Fragment>
160+
{data ? (
170161
<React.Fragment>
171-
{data ? (
172-
<React.Fragment>
173-
<Table
174-
columns={columns}
175-
dataSource={data.entries}
176-
scroll={{ x: 1800 }}
177-
loading={TableLoading(communitiesLoading)}
178-
pagination={false}
179-
/>
180-
<Pagi
181-
left="-10px"
182-
pageNumber={data.pageNumber}
183-
pageSize={data.pageSize}
184-
totalCount={data.totalCount}
185-
onChange={logic.loadCommunities}
186-
/>
187-
</React.Fragment>
188-
) : null}
162+
<Table
163+
columns={columns}
164+
dataSource={data.entries}
165+
scroll={{ x: 1800 }}
166+
loading={TableLoading(communitiesLoading)}
167+
pagination={false}
168+
/>
169+
<Pagi
170+
left="-10px"
171+
pageNumber={data.pageNumber}
172+
pageSize={data.pageSize}
173+
totalCount={data.totalCount}
174+
onChange={logic.loadCommunities}
175+
/>
189176
</React.Fragment>
190-
)
191-
}
192-
}
177+
) : null}
178+
</React.Fragment>
179+
)
193180

194181
export default IndexContent

containers/CommunitiesContent/PostsContent.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -164,41 +164,27 @@ const columns = [
164164
},
165165
]
166166

167-
class PostsContent extends React.Component {
168-
componentDidMount() {
169-
logic.loadPosts()
170-
}
171-
172-
render() {
173-
const {
174-
data,
175-
restProps: { communitiesLoading },
176-
} = this.props
177-
return (
167+
const PostsContent = ({ data, restProps: { communitiesLoading } }) => (
168+
<React.Fragment>
169+
{data ? (
178170
<div>
179-
{data ? (
180-
<div>
181-
<Table
182-
columns={columns}
183-
dataSource={data.entries}
184-
scroll={{ x: 2000 }}
185-
loading={TableLoading(communitiesLoading)}
186-
pagination={false}
187-
/>
188-
<Pagi
189-
left="-10px"
190-
pageNumber={data.pageNumber}
191-
pageSize={data.pageSize}
192-
totalCount={data.totalCount}
193-
onChange={logic.loadPosts}
194-
/>
195-
</div>
196-
) : (
197-
<div />
198-
)}
171+
<Table
172+
columns={columns}
173+
dataSource={data.entries}
174+
scroll={{ x: 2000 }}
175+
loading={TableLoading(communitiesLoading)}
176+
pagination={false}
177+
/>
178+
<Pagi
179+
left="-10px"
180+
pageNumber={data.pageNumber}
181+
pageSize={data.pageSize}
182+
totalCount={data.totalCount}
183+
onChange={logic.loadPosts}
184+
/>
199185
</div>
200-
)
201-
}
202-
}
186+
) : null}
187+
</React.Fragment>
188+
)
203189

204190
export default PostsContent
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import React from 'react'
2+
import TimeAgo from 'timeago-react'
3+
4+
import {
5+
Pagi,
6+
Table,
7+
TableLoading,
8+
Button,
9+
Space,
10+
UserCell,
11+
CommunityCell,
12+
TagsCell,
13+
} from '../../components'
14+
15+
import { OperationWrapper } from './styles'
16+
import * as logic from './logic'
17+
18+
/* eslint-disable react/display-name */
19+
const columns = [
20+
{
21+
title: 'id',
22+
dataIndex: 'id',
23+
align: 'center',
24+
width: 80,
25+
fixed: 'left',
26+
},
27+
{
28+
title: '标题',
29+
width: 300,
30+
align: 'left',
31+
fixed: 'left',
32+
render: (text, record) => (
33+
<div>
34+
<div>{record.ownerName}</div>
35+
<div>{record.title}</div>
36+
</div>
37+
),
38+
},
39+
{
40+
title: '作者',
41+
width: 200,
42+
dataIndex: 'author',
43+
align: 'center',
44+
render: author => {
45+
return <UserCell user={author} />
46+
},
47+
},
48+
{
49+
title: '社区',
50+
width: 150,
51+
dataIndex: 'communities',
52+
align: 'center',
53+
render: (communities, record) => {
54+
return (
55+
<CommunityCell
56+
array={communities}
57+
source={record}
58+
thread="POST"
59+
onDelete={logic.unsetCommunity}
60+
onAdd={logic.setCommunity}
61+
withSetter
62+
/>
63+
)
64+
},
65+
},
66+
{
67+
title: '标签',
68+
width: 250,
69+
dataIndex: 'tags',
70+
align: 'center',
71+
render: (tags, record) => (
72+
<TagsCell
73+
thread="POST"
74+
source={record}
75+
onDelete={logic.unsetTag}
76+
onAdd={logic.setTag}
77+
/>
78+
),
79+
},
80+
{
81+
title: '浏览',
82+
width: 100,
83+
dataIndex: 'views',
84+
align: 'center',
85+
},
86+
{
87+
title: '评论数',
88+
width: 100,
89+
dataIndex: 'commentsCount',
90+
align: 'center',
91+
},
92+
{
93+
title: '评论参与',
94+
width: 150,
95+
dataIndex: 'commentsParticipatorsCount',
96+
align: 'center',
97+
},
98+
{
99+
title: '创建时间',
100+
width: 150,
101+
dataIndex: 'insertedAt',
102+
align: 'center',
103+
render: text => {
104+
return <TimeAgo datetime={text} locale="zh_CN" />
105+
},
106+
},
107+
{
108+
title: '上次更新',
109+
width: 150,
110+
dataIndex: 'updatedAt',
111+
align: 'center',
112+
render: text => {
113+
return <TimeAgo datetime={text} locale="zh_CN" />
114+
},
115+
},
116+
{
117+
title: '操作',
118+
width: 200,
119+
dataIndex: '',
120+
align: 'center',
121+
render: (text, record) => {
122+
return (
123+
<OperationWrapper>
124+
<Button
125+
size="small"
126+
type="primary"
127+
ghost
128+
onClick={logic.onEdit.bind(this, record)}
129+
>
130+
编辑
131+
</Button>
132+
<Space right="10px" />
133+
<Button
134+
size="small"
135+
type="red"
136+
ghost
137+
onClick={logic.onDelete.bind(this, record)}
138+
>
139+
删除
140+
</Button>
141+
</OperationWrapper>
142+
)
143+
},
144+
},
145+
]
146+
147+
const ReposContent = ({ data, restProps: { communitiesLoading } }) => (
148+
<React.Fragment>
149+
{data ? (
150+
<div>
151+
<Table
152+
columns={columns}
153+
dataSource={data.entries}
154+
scroll={{ x: 2000 }}
155+
loading={TableLoading(communitiesLoading)}
156+
pagination={false}
157+
/>
158+
<Pagi
159+
left="-10px"
160+
pageNumber={data.pageNumber}
161+
pageSize={data.pageSize}
162+
totalCount={data.totalCount}
163+
onChange={logic.loadPosts}
164+
/>
165+
</div>
166+
) : null}
167+
</React.Fragment>
168+
)
169+
170+
export default ReposContent

containers/CommunitiesContent/TagsContent.js

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -118,42 +118,29 @@ const columns = [
118118
},
119119
]
120120

121-
class TagsContent extends React.Component {
122-
componentDidMount() {
123-
logic.loadTagsIfOnClient()
124-
}
125-
126-
render() {
127-
const {
128-
data,
129-
restProps: { tagsLoading },
130-
} = this.props
131-
132-
return (
121+
const TagsContent = ({ data, restProps: { tagsLoading } }) => (
122+
<React.Fragment>
123+
{data ? (
133124
<div>
134-
{data ? (
135-
<div>
136-
<Table
137-
columns={columns}
138-
dataSource={data.entries}
139-
scroll={{ x: 1500 }}
140-
loading={TableLoading(tagsLoading)}
141-
pagination={false}
142-
/>
143-
<Pagi
144-
left="-10px"
145-
pageNumber={data.pageNumber}
146-
pageSize={data.pageSize}
147-
totalCount={data.totalCount}
148-
onChange={logic.loadTags}
149-
/>
150-
</div>
151-
) : (
152-
<div />
153-
)}
125+
<Table
126+
columns={columns}
127+
dataSource={data.entries}
128+
scroll={{ x: 1500 }}
129+
loading={TableLoading(tagsLoading)}
130+
pagination={false}
131+
/>
132+
<Pagi
133+
left="-10px"
134+
pageNumber={data.pageNumber}
135+
pageSize={data.pageSize}
136+
totalCount={data.totalCount}
137+
onChange={logic.loadTags}
138+
/>
154139
</div>
155-
)
156-
}
157-
}
140+
) : (
141+
<div />
142+
)}
143+
</React.Fragment>
144+
)
158145

159146
export default TagsContent

0 commit comments

Comments
 (0)