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

Commit 10cb079

Browse files
committed
refactor(sidebar): community & content workflow
1 parent d334e35 commit 10cb079

File tree

17 files changed

+280
-363
lines changed

17 files changed

+280
-363
lines changed

containers/CommunitiesContent/logic.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ const DataSolver = [
292292
match: asyncRes('pagedCategories'),
293293
action: ({ pagedCategories }) => {
294294
cancleLoading()
295+
debug('pagedCategories: ', pagedCategories)
295296
store.markState({ pagedCategories })
296297
},
297298
},
@@ -380,7 +381,6 @@ const DataSolver = [
380381
action: res => {
381382
const { mainPath, subPath } = res[EVENT.SIDEBAR_MENU_CHANGE].data
382383
if (mainPath !== ROUTE.COMMUNITIES) return false
383-
debug('unknow event: ', subPath)
384384

385385
switch (subPath) {
386386
case ROUTE.CATEGORIES: {
@@ -440,10 +440,8 @@ const ErrSolver = [
440440
export function init(_store) {
441441
store = _store
442442

443-
if (sub$) return // loadCommunities() // loadCategories()
443+
if (sub$) return false
444444
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
445-
446-
// loadCommunities() // loadCategories()
447445
}
448446

449447
export function uninit() {
Lines changed: 10 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,18 @@
11
import React from 'react'
2-
import TimeAgo from 'timeago-react'
32

4-
import { cutFrom } from '../../utils'
5-
import {
6-
Pagi,
7-
Table,
8-
TableLoading,
9-
Button,
10-
Space,
11-
UserCell,
12-
} from '../../components'
3+
import PostsTable from '../../components/PostsTable'
134

14-
import { OperationWrapper } from './styles'
5+
// import { OperationWrapper } from './styles'
156
import * as logic from './logic'
167

178
/* 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-
componentDidMount() {
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-
}
9+
const PostsContent = ({ data, restProps: { postsLoading } }) => (
10+
<PostsTable
11+
data={data}
12+
loading={postsLoading}
13+
onDelete={logic.onDelete}
14+
onEdit={logic.onEdit}
15+
/>
16+
)
16817

16918
export default PostsContent

containers/CommunityContent/index.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,28 @@ import * as logic from './logic'
2121
const debug = makeDebugger('C:CommunityContent')
2222
/* eslint-enable no-unused-vars */
2323

24-
const renderChildContent = (route, store, restProps) => {
24+
const renderChildContent = (curRoute, store, restProps) => {
2525
const { pagedPostsData, pagedTagsData } = store
26-
// return <IndexContent data={pagedCommunitiesData} restProps={restProps} />
27-
// return <PostsContent data={pagedPostsData} restProps={restProps} />
2826

29-
debug('current fucking: ', pagedPostsData)
30-
31-
switch (route.subPath) {
27+
switch (curRoute.subPath) {
28+
case ROUTE.POSTS: {
29+
return <PostsContent data={pagedPostsData} restProps={restProps} />
30+
}
31+
case ROUTE.JOBS: {
32+
return <h3>ROUTE.JOBS</h3>
33+
}
34+
case ROUTE.REPOS: {
35+
return <h3>ROUTE.REPOS</h3>
36+
}
37+
case ROUTE.VIDEOS: {
38+
return <h3>ROUTE.VIDEOS</h3>
39+
}
3240
case ROUTE.TAGS: {
3341
return <TagsContent data={pagedTagsData} restProps={restProps} />
3442
}
3543
case ROUTE.EDITORS: {
3644
return <h2>Editors Content</h2>
3745
}
38-
case ROUTE.POSTS: {
39-
return <PostsContent data={pagedPostsData} restProps={restProps} />
40-
}
4146
default: {
4247
return <h2>default</h2>
4348
}
@@ -56,12 +61,12 @@ class CommunityContentContainer extends React.Component {
5661

5762
render() {
5863
const { communityContent } = this.props
59-
const { route } = communityContent
64+
const { curRoute } = communityContent
6065
const restProps = { ...communityContent }
6166

6267
return (
6368
<Wrapper>
64-
{renderChildContent(route, communityContent, restProps)}
69+
{renderChildContent(curRoute, communityContent, restProps)}
6570
</Wrapper>
6671
)
6772
}

containers/CommunityContent/logic.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
$solver,
77
// ERR,
88
makeDebugger,
9-
// EVENT,
9+
EVENT,
10+
ROUTE,
1011
TYPE,
1112
scrollIntoEle,
1213
} from '../../utils'
@@ -16,7 +17,10 @@ import S from './schema'
1617

1718
import SR71 from '../../utils/network/sr71'
1819

19-
const sr71$ = new SR71()
20+
const sr71$ = new SR71({
21+
resv_event: [EVENT.SIDEBAR_MENU_CHANGE],
22+
})
23+
2024
let sub$ = null
2125

2226
/* eslint-disable no-unused-vars */
@@ -25,18 +29,20 @@ const debug = makeDebugger('L:CommunityContent')
2529

2630
let store = null
2731

28-
const commonFilter = page => {
32+
const commonFilter = (page, community = 'home') => {
2933
const size = PAGE_SIZE.D
3034
return {
31-
filter: { page, size },
35+
filter: { page, size, community },
3236
}
3337
}
3438

3539
export function loadPosts(page = 1) {
3640
scrollIntoEle(TYPE.APP_HEADER_ID)
3741
store.markState({ postsLoading: true })
3842

39-
sr71$.query(S.pagedPosts, commonFilter(page))
43+
const { mainPath: community } = store.curRoute
44+
45+
sr71$.query(S.pagedPosts, commonFilter(page, community))
4046
}
4147

4248
export function loadTags(page = 1) {
@@ -75,6 +81,40 @@ const DataSolver = [
7581
store.markState({ pagedTags })
7682
},
7783
},
84+
{
85+
match: asyncRes(EVENT.SIDEBAR_MENU_CHANGE),
86+
action: res => {
87+
const { /* mainPath */ subPath } = res[EVENT.SIDEBAR_MENU_CHANGE].data
88+
debug('SIDEBAR_MENU_CHANGE ', res[EVENT.SIDEBAR_MENU_CHANGE].data)
89+
90+
switch (subPath) {
91+
case ROUTE.CATEGORIES: {
92+
return console.log('todo')
93+
}
94+
case ROUTE.TAGS: {
95+
return loadTags()
96+
}
97+
case ROUTE.THREADS: {
98+
return console.log('todo')
99+
}
100+
case ROUTE.POSTS: {
101+
return loadPosts()
102+
}
103+
case ROUTE.JOBS: {
104+
return console.log('todo')
105+
}
106+
case ROUTE.REPOS: {
107+
return console.log('todo')
108+
}
109+
case ROUTE.VIDEOS: {
110+
return console.log('todo')
111+
}
112+
default: {
113+
return console.log('todo')
114+
}
115+
}
116+
},
117+
},
78118
]
79119
const ErrSolver = []
80120

0 commit comments

Comments
 (0)