Skip to content

Commit acdcaab

Browse files
committed
tag set/unset && refactor
1 parent 857021b commit acdcaab

File tree

20 files changed

+447
-45
lines changed

20 files changed

+447
-45
lines changed

components/TagsCell/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ class TagsCell extends React.Component {
5050
{R.isEmpty(tags) ? (
5151
<AddWrapper>
5252
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
53-
<AddText onClick={onAdd.bind(this, [])}>添加</AddText>
53+
<AddText onClick={onAdd.bind(this, partId, [])}>添加</AddText>
5454
</AddWrapper>
5555
) : (
5656
<Wrapper>
5757
<TagsList tags={tags} partId={partId} onDelete={onDelete} />
58-
<div onClick={onAdd.bind(this, tags)}>
58+
<div onClick={onAdd.bind(this, partId, tags)}>
5959
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
6060
</div>
6161
</Wrapper>

containers/CategorySetter/logic.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ const DataSolver = [
5656
},
5757
{
5858
match: asyncRes('setCategory'),
59-
action: () => {
60-
closePreviewer(TYPE.COMMUNITIES_REFRESH)
61-
},
59+
action: () => closePreviewer(TYPE.COMMUNITIES_REFRESH),
6260
},
6361
]
6462

containers/CommunitiesBanner/logic.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,20 @@ const DataSolver = [
9595
match: asyncRes(EVENT.PREVIEW_CLOSE),
9696
action: res => {
9797
const closeType = res[EVENT.PREVIEW_CLOSE].type
98-
if (closeType === TYPE.COMMUNITIES_REFRESH) {
99-
loadCommunities()
100-
} else if (closeType === TYPE.TAGS_REFRESH) {
101-
loadTags()
102-
} else if (closeType === TYPE.GATEGORIES_REFRESH) {
103-
loadCategories()
98+
switch (closeType) {
99+
case TYPE.COMMUNITIES_REFRESH: {
100+
return loadCommunities()
101+
}
102+
case TYPE.TAGS_REFRESH: {
103+
return loadTags()
104+
}
105+
case TYPE.GATEGORIES_REFRESH: {
106+
return loadCategories()
107+
}
108+
default: {
109+
debug('unknow event')
110+
return loadPosts()
111+
}
104112
}
105113
},
106114
},

containers/CommunitiesContent/PostsContent.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ const columns = [
2525
width: 80,
2626
fixed: 'left',
2727
},
28+
{
29+
title: '标题',
30+
width: 300,
31+
dataIndex: 'title',
32+
align: 'center',
33+
fixed: 'left',
34+
render: text => {
35+
return <div>{cutFrom(text, 15)}</div>
36+
},
37+
},
38+
{
39+
title: '摘要',
40+
width: 400,
41+
dataIndex: 'digest',
42+
align: 'center',
43+
render: text => {
44+
return <div>{cutFrom(text, 10)}</div>
45+
},
46+
},
2847
{
2948
title: '作者',
3049
width: 200,
@@ -53,30 +72,12 @@ const columns = [
5372
<TagsCell
5473
tags={tags}
5574
partId={record.id}
56-
onAdd={console.log}
5775
onDelete={logic.unsetTag}
76+
onAdd={logic.setTag}
5877
/>
5978
)
6079
},
6180
},
62-
{
63-
title: '标题',
64-
width: 300,
65-
dataIndex: 'title',
66-
align: 'center',
67-
render: text => {
68-
return <div>{cutFrom(text, 15)}</div>
69-
},
70-
},
71-
{
72-
title: '摘要',
73-
width: 400,
74-
dataIndex: 'digest',
75-
align: 'center',
76-
render: text => {
77-
return <div>{cutFrom(text, 10)}</div>
78-
},
79-
},
8081
{
8182
title: '浏览',
8283
width: 100,
@@ -171,10 +172,7 @@ class PostsContent extends React.Component {
171172
*/
172173

173174
render() {
174-
const {
175-
data,
176-
restProps: { communitiesLoading },
177-
} = this.props
175+
const { data, restProps: { communitiesLoading } } = this.props
178176
return (
179177
<div>
180178
{data ? (

containers/CommunitiesContent/logic.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ export function setCategory(communityId, categories) {
105105
})
106106
}
107107

108+
export function setTag(partId, tags) {
109+
dispatchEvent(EVENT.NAV_SET_TAG, {
110+
type: TYPE.PREVIEW_SET_TAG,
111+
data: {
112+
partId,
113+
tags,
114+
},
115+
})
116+
}
117+
108118
export function unsetTag(partId, tag) {
109119
const args = {
110120
part: R.toUpper(tag.part),
@@ -147,7 +157,6 @@ const DataSolver = [
147157
{
148158
match: asyncRes('pagedPosts'),
149159
action: ({ pagedPosts }) => {
150-
console.log('pagedPosts --> ', pagedPosts)
151160
cancleLoading()
152161
communitiesContent.markState({
153162
pagedPosts,
@@ -187,12 +196,23 @@ const DataSolver = [
187196
match: asyncRes(EVENT.PREVIEW_CLOSE),
188197
action: res => {
189198
const closeType = res[EVENT.PREVIEW_CLOSE].type
190-
if (closeType === TYPE.COMMUNITIES_REFRESH) {
191-
loadCommunities()
192-
} else if (closeType === TYPE.TAGS_REFRESH) {
193-
loadTags()
194-
} else if (closeType === TYPE.GATEGORIES_REFRESH) {
195-
loadCategories()
199+
switch (closeType) {
200+
case TYPE.COMMUNITIES_REFRESH: {
201+
return loadCommunities()
202+
}
203+
case TYPE.TAGS_REFRESH: {
204+
return loadTags()
205+
}
206+
case TYPE.GATEGORIES_REFRESH: {
207+
return loadCategories()
208+
}
209+
case TYPE.POSTS_TAG_REFRESH: {
210+
return loadPosts()
211+
}
212+
default: {
213+
debug('unknow event')
214+
return loadPosts()
215+
}
196216
}
197217
},
198218
},

containers/Preview/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
TagEditor,
2525
CategoryEditor,
2626
CategorySetter,
27+
TagSetter,
2728
} from '../../containers'
2829

2930
import {
@@ -57,7 +58,13 @@ const CloseBtn = ({ type }) => (
5758
// <AccountViewer2 themeKeys={themeKeys} curTheme={curTheme} />
5859

5960
// TODO: post edit viewer
60-
const Viewer = ({ type, root, editingCommunity, editingCategory }) => {
61+
const Viewer = ({
62+
type,
63+
root,
64+
editingCommunity,
65+
editingCategory,
66+
editingTag,
67+
}) => {
6168
switch (type) {
6269
case TYPE.PREVIEW_ACCOUNT_VIEW: {
6370
return <AccountViewer />
@@ -89,6 +96,9 @@ const Viewer = ({ type, root, editingCommunity, editingCategory }) => {
8996
case TYPE.PREVIEW_SET_CATEGORY: {
9097
return <CategorySetter editData={editingCommunity} />
9198
}
99+
case TYPE.PREVIEW_SET_TAG: {
100+
return <TagSetter editData={editingTag} />
101+
}
92102
default: {
93103
return <StateTree json={root.toJSON()} />
94104
}
@@ -109,6 +119,7 @@ class PreviewContainer extends React.Component {
109119
root,
110120
editingCommunity,
111121
editingCategory,
122+
editingTag,
112123
} = this.props.preview
113124

114125
return (
@@ -124,6 +135,7 @@ class PreviewContainer extends React.Component {
124135
curTheme={curTheme}
125136
editingCommunity={editingCommunity}
126137
editingCategory={editingCategory}
138+
editingTag={editingTag}
127139
/>
128140
</PreviewContent>
129141
</PreviewWrapper>

containers/Preview/logic.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const sr71$ = new SR71({
2323
EVENT.NAV_CREATE_CATEGORY,
2424
EVENT.NAV_SET_CATEGORY,
2525
EVENT.NAV_UPDATE_CATEGORY,
26+
// tag
27+
EVENT.NAV_SET_TAG,
2628
],
2729
})
2830

@@ -148,6 +150,24 @@ const DataResolver = [
148150
preview.open(event.type)
149151
},
150152
},
153+
{
154+
match: asyncRes(EVENT.NAV_SET_TAG),
155+
action: res => {
156+
const event = res[EVENT.NAV_SET_TAG]
157+
console.log('res -> ', {
158+
partId: event.data.partId,
159+
tags: event.data.tags,
160+
})
161+
preview.markState({
162+
editTag: {
163+
partId: event.data.partId,
164+
tags: event.data.tags,
165+
},
166+
})
167+
holdPage()
168+
preview.open(event.type)
169+
},
170+
},
151171
]
152172

153173
export function init(selectedStore) {

containers/TagSetter/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
*
3+
* TagSetter
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import { inject, observer } from 'mobx-react'
9+
import R from 'ramda'
10+
11+
import shortid from 'shortid'
12+
// import Link from 'next/link'
13+
14+
import { makeDebugger, storePlug } from '../../utils'
15+
import * as logic from './logic'
16+
17+
import {
18+
Wrapper,
19+
Divider,
20+
CategoryWrapper,
21+
CategoryTag,
22+
CommunityLogo,
23+
PartText,
24+
} from './styles'
25+
26+
/* eslint-disable no-unused-vars */
27+
const debug = makeDebugger('C:TagSetter')
28+
/* eslint-enable no-unused-vars */
29+
30+
const TagsList = ({ tags, partId, selectedTids }) => {
31+
return (
32+
<CategoryWrapper>
33+
{tags.map(c => (
34+
<CategoryTag
35+
key={shortid.generate()}
36+
active={R.contains(c.id, selectedTids)}
37+
onClick={logic.onAdd.bind(
38+
this,
39+
c.part,
40+
partId,
41+
c.id,
42+
c.community.id,
43+
selectedTids
44+
)}
45+
>
46+
<CommunityLogo src={c.community.logo} />
47+
<PartText>({c.part})</PartText>
48+
{c.title}
49+
</CategoryTag>
50+
))}
51+
</CategoryWrapper>
52+
)
53+
}
54+
55+
class TagSetterContainer extends React.Component {
56+
componentWillMount() {
57+
logic.init(this.props.tagSetter)
58+
}
59+
60+
render() {
61+
const { tagSetter, editData } = this.props
62+
const { pagedTagsData } = tagSetter
63+
64+
const selectedTids = R.pluck('id', editData.tags)
65+
const { partId } = editData
66+
67+
return (
68+
<Wrapper>
69+
coderplanets
70+
<h2>设置标签</h2>
71+
<Divider />
72+
{pagedTagsData ? (
73+
<TagsList
74+
tags={pagedTagsData.entries}
75+
partId={partId}
76+
selectedTids={selectedTids}
77+
/>
78+
) : (
79+
<div />
80+
)}
81+
</Wrapper>
82+
)
83+
}
84+
}
85+
86+
export default inject(storePlug('tagSetter'))(observer(TagSetterContainer))

0 commit comments

Comments
 (0)