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

Commit 84f8d09

Browse files
committed
clean up
1 parent 2df7db7 commit 84f8d09

File tree

10 files changed

+400
-21
lines changed

10 files changed

+400
-21
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
22

33
node_js:
4+
- 10
45
- 9
56
- 8
67
- 7

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
<br/><br/>
88

99
<a href="https://travis-ci.org/mydearxym/coderplanets_admin" target="_blank">
10-
<img src="https://api.travis-ci.org/mydearxym/coderplanets_admin.svg?branch=dev" alt="Build Status" />
10+
<img src="https://travis-ci.org/mydearxym/coderplanets_admin.svg?branch=dev" alt="Build Status" />
1111
</a>
1212

13-
<a href='https://coveralls.io/github/mydearxym/coderplanets_admin_web?branch=master' target="_blank">
13+
<a href='https://coveralls.io/github/mydearxym/coderplanets_admin?branch=master' target="_blank">
1414
<img
15-
src='https://coveralls.io/repos/github/mydearxym/coderplanets_admin_web/badge.svg?branch=master'
15+
src='https://coveralls.io/repos/github/mydearxym/coderplanets_admin/badge.svg?branch=master'
1616
alt='Coverage Status' />
1717
</a>
1818

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

containers/CommunityContent/index.js

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,61 @@
11
/*
2-
*
3-
* CommunityContent
4-
*
5-
*/
2+
*
3+
* CommunityContent
4+
*
5+
*/
66

77
import React from 'react'
88
import { inject, observer } from 'mobx-react'
99

1010
// import Link from 'next/link'
1111

12-
import { makeDebugger, storePlug } from '../../utils'
12+
import { makeDebugger, storePlug, ROUTE } from '../../utils'
13+
14+
import PostsContent from './PostsContent'
15+
16+
import { Wrapper } from './styles'
1317
import * as logic from './logic'
1418

1519
/* eslint-disable no-unused-vars */
1620
const debug = makeDebugger('C:CommunityContent')
1721
/* eslint-enable no-unused-vars */
1822

23+
const renderChildContent = (route, store, restProps) => {
24+
const { pagedPostsData } = store
25+
// return <IndexContent data={pagedCommunitiesData} restProps={restProps} />
26+
// return <PostsContent data={pagedPostsData} restProps={restProps} />
27+
28+
switch (route.subQuery) {
29+
case ROUTE.TAGS: {
30+
return <h2>Tags</h2>
31+
}
32+
case ROUTE.EDITORS: {
33+
return <h2>Editors Content</h2>
34+
}
35+
case ROUTE.POSTS: {
36+
return <PostsContent data={pagedPostsData} restProps={restProps} />
37+
}
38+
default: {
39+
return <h2>default</h2>
40+
}
41+
}
42+
}
43+
1944
class CommunityContentContainer extends React.Component {
2045
componentWillMount() {
2146
logic.init(this.props.communityContent)
2247
}
2348

2449
render() {
25-
return <div>CommunityContent container!</div>
50+
const { communityContent } = this.props
51+
const { route } = communityContent
52+
const restProps = { ...this.props.communityContent }
53+
54+
return (
55+
<Wrapper>
56+
{renderChildContent(route, communityContent, restProps)}
57+
</Wrapper>
58+
)
2659
}
2760
}
2861

containers/CommunityContent/logic.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
// import R from 'ramda'
22

3-
import { makeDebugger, $solver } from '../../utils'
3+
import {
4+
gqRes,
5+
// gqErr,
6+
$solver,
7+
// ERR,
8+
makeDebugger,
9+
// EVENT,
10+
TYPE,
11+
scrollIntoEle,
12+
} from '../../utils'
13+
import { PAGE_SIZE } from '../../config'
14+
15+
import S from './schema'
16+
417
import SR71 from '../../utils/network/sr71'
518

619
const sr71$ = new SR71()
@@ -12,13 +25,46 @@ const debug = makeDebugger('L:CommunityContent')
1225

1326
let communityContent = null
1427

15-
export function someMethod() {}
28+
const commonFilter = page => {
29+
const size = PAGE_SIZE.COMMON
30+
return {
31+
filter: { page, size },
32+
}
33+
}
34+
35+
export function loadPosts(page = 1) {
36+
scrollIntoEle(TYPE.APP_HEADER_ID)
37+
communityContent.markState({
38+
postsLoading: true,
39+
})
40+
sr71$.query(S.pagedPosts, commonFilter(page))
41+
}
42+
43+
export function onEdit() {}
44+
export function onDelete() {}
1645

1746
// ###############################
1847
// Data & Error handlers
1948
// ###############################
49+
const cancleLoading = () => {
50+
communityContent.markState({
51+
// communitiesLoading: false,
52+
postsLoading: false,
53+
// tagsLoading: false,
54+
})
55+
}
2056

21-
const DataSolver = []
57+
const DataSolver = [
58+
{
59+
match: gqRes('pagedPosts'),
60+
action: ({ pagedPosts }) => {
61+
cancleLoading()
62+
communityContent.markState({
63+
pagedPosts,
64+
})
65+
},
66+
},
67+
]
2268
const ErrSolver = []
2369

2470
export function init(selectedStore) {

0 commit comments

Comments
 (0)