Skip to content

Commit aff95b5

Browse files
committed
use table record as source to simplfy set/unset categories
1 parent 23629b2 commit aff95b5

File tree

4 files changed

+35
-62
lines changed

4 files changed

+35
-62
lines changed

components/CategoriesCell/index.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import {
2424
// import { inject, observer } from 'mobx-react'
2525
// import Link from 'next/link'
2626

27-
const CategoriesList = ({ categories, communityId, onDelete }) => (
27+
const CategoriesList = ({ source, onDelete }) => (
2828
<CategoryWrapper>
29-
{categories.map(c => (
29+
{source.categories.map(c => (
3030
<CategoryTag
3131
key={shortid.generate()}
32-
onClick={onDelete.bind(this, communityId, c)}
32+
onClick={onDelete.bind(this, source.id, c)}
3333
>
3434
{c.title}
3535
<DeleteCross>x</DeleteCross>
@@ -44,23 +44,19 @@ class CategoriesCell extends React.Component {
4444
componentWillUnmount() {}
4545

4646
render() {
47-
const { communityId, categories, onDelete, onAdd } = this.props
47+
const { source, onDelete, onAdd } = this.props
4848

4949
return (
5050
<div>
51-
{R.isEmpty(categories) ? (
51+
{R.isEmpty(source.categories) ? (
5252
<AddWrapper>
5353
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
54-
<AddText onClick={onAdd.bind(this, communityId, [])}>添加</AddText>
54+
<AddText onClick={onAdd.bind(this, source)}>添加</AddText>
5555
</AddWrapper>
5656
) : (
5757
<Wrapper>
58-
<CategoriesList
59-
categories={categories}
60-
onDelete={onDelete}
61-
communityId={communityId}
62-
/>
63-
<div onClick={onAdd.bind(this, communityId, categories)}>
58+
<CategoriesList source={source} onDelete={onDelete} />
59+
<div onClick={onAdd.bind(this, source)}>
6460
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
6561
</div>
6662
</Wrapper>
@@ -74,13 +70,7 @@ export default CategoriesCell
7470

7571
CategoriesCell.propTypes = {
7672
// https://www.npmjs.com/package/prop-types
77-
categories: PropTypes.arrayOf(
78-
PropTypes.shape({
79-
id: PropTypes.string,
80-
title: PropTypes.string,
81-
})
82-
),
83-
communityId: PropTypes.number.isRequired,
73+
source: PropTypes.object.isRequired,
8474
onDelete: PropTypes.func.isRequired,
8575
onAdd: PropTypes.func.isRequired,
8676
}

containers/CommunitiesContent/IndexContent.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const columns = [
7070
render: (categoriesArray, record) => {
7171
return (
7272
<CategoriesCell
73+
source={record}
7374
categories={categoriesArray}
7475
communityId={record.id}
7576
onDelete={logic.unsetCategory}
@@ -154,10 +155,7 @@ class IndexContent extends React.Component {
154155
}
155156

156157
render() {
157-
const {
158-
data,
159-
restProps: { communitiesLoading },
160-
} = this.props
158+
const { data, restProps: { communitiesLoading } } = this.props
161159

162160
return (
163161
<div>

containers/CommunitiesContent/logic.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,10 @@ export function unsetCategory(communityId, category) {
9595
})
9696
}
9797

98-
export function setCategory(communityId, categories) {
98+
export function setCategory(source) {
9999
dispatchEvent(EVENT.NAV_SET_CATEGORY, {
100100
type: TYPE.PREVIEW_SET_CATEGORY,
101-
data: {
102-
communityId,
103-
categories,
104-
},
101+
data: source,
105102
})
106103
}
107104

containers/Preview/logic.js

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ const DataResolver = [
5959
match: asyncRes(EVENT.PREVIEW),
6060
action: res => {
6161
const event = res[EVENT.PREVIEW]
62-
holdPage()
62+
6363
preview.open(event.type)
64+
holdPage()
6465
},
6566
},
6667
{
@@ -71,99 +72,86 @@ const DataResolver = [
7172
match: asyncRes(EVENT.NAV_EDIT),
7273
action: res => {
7374
const event = res[EVENT.NAV_EDIT]
74-
holdPage()
7575

76-
debug('EVENT.NAV_EDIT: ', res)
7776
preview.open(event.type)
7877
loadDataForPreview(res[EVENT.NAV_EDIT])
78+
holdPage()
7979
},
8080
},
8181
{
8282
match: asyncRes(EVENT.NAV_CREATE_POST),
8383
action: res => {
8484
const event = res[EVENT.NAV_CREATE_POST]
85-
holdPage()
85+
8686
preview.open(event.type)
87+
holdPage()
8788
},
8889
},
8990
{
9091
match: asyncRes(EVENT.NAV_CREATE_COMMUNITY),
9192
action: res => {
9293
const event = res[EVENT.NAV_CREATE_COMMUNITY]
93-
holdPage()
94+
9495
preview.open(event.type)
96+
holdPage()
9597
},
9698
},
9799
{
98100
match: asyncRes(EVENT.NAV_UPDATE_COMMUNITY),
99101
action: res => {
100102
const event = res[EVENT.NAV_UPDATE_COMMUNITY]
101-
debug('get ', EVENT.NAV_UPDATE_COMMUNITY)
102103

103-
preview.markState({
104-
editCommunity: event.data,
105-
})
106-
holdPage()
104+
preview.markState({ editCommunity: event.data })
107105
preview.open(event.type)
106+
holdPage()
108107
},
109108
},
110109
{
111110
match: asyncRes(EVENT.NAV_CREATE_TAG),
112111
action: res => {
113-
debug('get ', EVENT.NAV_CREATE_TAG)
114112
const event = res[EVENT.NAV_CREATE_TAG]
115-
holdPage()
113+
116114
preview.open(event.type)
115+
holdPage()
117116
},
118117
},
119118
{
120119
match: asyncRes(EVENT.NAV_CREATE_CATEGORY),
121120
action: res => {
122-
debug('get ', EVENT.NAV_CREATE_CATEGORY)
123121
const event = res[EVENT.NAV_CREATE_CATEGORY]
124-
holdPage()
122+
125123
preview.open(event.type)
124+
holdPage()
126125
},
127126
},
128127
{
129128
match: asyncRes(EVENT.NAV_UPDATE_CATEGORY),
130129
action: res => {
131130
const event = res[EVENT.NAV_UPDATE_CATEGORY]
132-
holdPage()
133-
preview.markState({
134-
editCategory: event.data,
135-
})
131+
132+
preview.markState({ editCategory: event.data })
136133
preview.open(event.type)
134+
holdPage()
137135
},
138136
},
139137
{
140138
match: asyncRes(EVENT.NAV_SET_CATEGORY),
141139
action: res => {
142140
const event = res[EVENT.NAV_SET_CATEGORY]
143-
preview.markState({
144-
editCommunity: {
145-
id: event.data.communityId,
146-
categories: event.data.categories,
147-
},
148-
})
149-
holdPage()
141+
142+
preview.markState({ editCommunity: event.data })
150143
preview.open(event.type)
144+
holdPage()
151145
},
152146
},
153147
{
154148
match: asyncRes(EVENT.NAV_SET_TAG),
155149
action: res => {
156150
const event = res[EVENT.NAV_SET_TAG]
157-
console.log('res -> ', {
158-
partId: event.data.partId,
159-
/* source: event.data.source, */
160-
tags: event.data.tags,
161-
})
162-
preview.markState({
163-
editTag: event.data,
164-
})
165-
holdPage()
151+
152+
preview.markState({ editTag: event.data })
166153
preview.open(event.type)
154+
holdPage()
167155
},
168156
},
169157
]

0 commit comments

Comments
 (0)