Skip to content

Commit 72f454d

Browse files
committed
unset category
1 parent 459ef2b commit 72f454d

File tree

10 files changed

+220
-17
lines changed

10 files changed

+220
-17
lines changed

components/CategoriesCell/index.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
*
3+
* CategoriesCell
4+
*
5+
*/
6+
7+
import React from 'react'
8+
import PropTypes from 'prop-types'
9+
import R from 'ramda'
10+
11+
import shortid from 'shortid'
12+
13+
import {
14+
Wrapper,
15+
CategoryWrapper,
16+
CategoryTag,
17+
AddWrapper,
18+
DeleteCross,
19+
AddIcon,
20+
AddText,
21+
} from './styles'
22+
import { ICON_ASSETS } from '../../config'
23+
24+
// import { inject, observer } from 'mobx-react'
25+
// import Link from 'next/link'
26+
27+
const CategoriesList = ({ categories, communityId, onDelete }) => {
28+
return (
29+
<CategoryWrapper>
30+
{categories.map(c => (
31+
<CategoryTag
32+
key={shortid.generate()}
33+
onClick={onDelete.bind(this, communityId, c)}
34+
>
35+
{c.title}
36+
<DeleteCross>x</DeleteCross>
37+
</CategoryTag>
38+
))}
39+
</CategoryWrapper>
40+
)
41+
}
42+
43+
class CategoriesCell extends React.Component {
44+
componentDidMount() {}
45+
46+
componentWillUnmount() {}
47+
48+
render() {
49+
const { communityId, categories, onDelete } = this.props
50+
51+
return (
52+
<div>
53+
{R.isEmpty(categories) ? (
54+
<AddWrapper>
55+
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
56+
<AddText>添加</AddText>
57+
</AddWrapper>
58+
) : (
59+
<Wrapper>
60+
<CategoriesList
61+
categories={categories}
62+
onDelete={onDelete}
63+
communityId={communityId}
64+
/>
65+
<AddIcon src={`${ICON_ASSETS}/cmd/plus.svg`} />
66+
</Wrapper>
67+
)}
68+
</div>
69+
)
70+
}
71+
}
72+
73+
export default CategoriesCell
74+
75+
CategoriesCell.propTypes = {
76+
// 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,
84+
onDelete: PropTypes.func.isRequired,
85+
}
86+
87+
CategoriesCell.defaultProps = {
88+
categories: [],
89+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import styled from 'styled-components'
2+
3+
import { Animate } from '../../../utils'
4+
5+
import { Img } from '../../../components'
6+
7+
export const UnsetText = styled.div`
8+
color: tomato;
9+
`
10+
export const Wrapper = styled.div`
11+
display: flex;
12+
justify-content: center;
13+
align-items: center;
14+
`
15+
export const CategoryWrapper = styled.div`
16+
display: flex;
17+
`
18+
19+
export const CategoryTag = styled.div`
20+
display: flex;
21+
align-items: center;
22+
background: #e4f7fe;
23+
border: 1px dashed #97dbfc;
24+
color: #0692fa;
25+
padding: 0 10px;
26+
padding-right: 6px;
27+
border-radius: 3px;
28+
margin-right: 7px;
29+
&:hover {
30+
border: 1px solid #97dbfc;
31+
}
32+
`
33+
34+
export const DeleteCross = styled.div`
35+
margin-left: 8px;
36+
&:hover {
37+
cursor: pointer;
38+
animation: ${Animate.pulse} 0.3s linear;
39+
}
40+
`
41+
42+
export const AddWrapper = Wrapper.extend``
43+
44+
export const AddIcon = styled(Img)`
45+
width: 15px;
46+
height: 15px;
47+
display: block;
48+
fill: lightgrey;
49+
&:hover {
50+
cursor: pointer;
51+
fill: #646479;
52+
}
53+
${AddWrapper}:hover & {
54+
cursor: pointer;
55+
fill: #646479;
56+
animation: ${Animate.pulse} 0.3s linear;
57+
}
58+
`
59+
60+
export const AddText = styled.div`
61+
margin-left: 5px;
62+
color: lightgrey;
63+
${AddWrapper}:hover & {
64+
cursor: pointer;
65+
color: #646479;
66+
}
67+
transition: color 0.2s linear;
68+
`
69+
70+
export const Holder = styled.div``
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// import React from 'react'
2+
// import { shallow } from 'enzyme'
3+
4+
// import CategoriesCell from '../index'
5+
6+
describe('TODO <CategoriesCell />', () => {
7+
it('Expect to have unit tests specified', () => {
8+
expect(true).toEqual(true)
9+
})
10+
})

components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export { default as SexCell } from './SexCell'
2828
export { default as FormInputer } from './FormInputer'
2929
export { default as FormSelector } from './FormSelector'
3030
export { default as TagColorSelector } from './TagColorSelector'
31+
export { default as CategoriesCell } from './CategoriesCell'
3132

3233
// loading component
3334
export {

containers/CommunitiesContent/IndexContent.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
Button,
1010
Space,
1111
Popconfirm,
12+
CategoriesCell,
1213
} from '../../components'
1314

1415
import { CommunityIcon, OperationWrapper } from './styles'
@@ -61,14 +62,21 @@ const columns = [
6162
return <div>{cutFrom(text, 10)}</div>
6263
},
6364
},
64-
/*
65-
{
66-
title: '类别',
67-
width: 150,
68-
align: 'center',
69-
dataIndex: 'category',
70-
},
71-
*/
65+
{
66+
title: '类别',
67+
width: 350,
68+
align: 'center',
69+
dataIndex: 'categories',
70+
render: (categoriesArray, record) => {
71+
return (
72+
<CategoriesCell
73+
categories={categoriesArray}
74+
communityId={record.id}
75+
onDelete={logic.unsetCategory}
76+
/>
77+
)
78+
},
79+
},
7280
{
7381
title: '订阅人数',
7482
width: 150,

containers/CommunitiesContent/logic.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ export function onDelete(record) {
8888
sr71$.mutate(S.deleteCommunity, { id: record.id })
8989
}
9090

91+
export function unsetCategory(communityId, category) {
92+
sr71$.mutate(S.unsetCategory, {
93+
communityId,
94+
categoryId: category.id,
95+
})
96+
}
97+
9198
/* when error occured cancle all the loading state */
9299
const cancleLoading = () => {
93100
communitiesContent.markState({
@@ -141,7 +148,12 @@ const DataSolver = [
141148
closePreviewer(TYPE.COMMUNITIES_REFRESH)
142149
},
143150
},
144-
151+
{
152+
match: asyncRes('unsetCategory'),
153+
action: () => {
154+
loadCommunities()
155+
},
156+
},
145157
{
146158
match: asyncRes(EVENT.LOGOUT),
147159
action: () => loadCommunities(),

containers/CommunitiesContent/schema.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,21 @@ const deleteCommunity = gql`
111111
}
112112
}
113113
`
114+
const unsetCategory = gql`
115+
mutation($categoryId: ID!, $communityId: ID!) {
116+
unsetCategory(categoryId: $categoryId, communityId: $communityId) {
117+
id
118+
}
119+
}
120+
`
114121

115122
const schema = {
116123
pagedCommunities,
117124
pagedTags,
118125
pagedCategories,
119126
pagedPosts,
120127
deleteCommunity,
128+
unsetCategory,
121129
}
122130

123131
export default schema

containers/CommunityEditor/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ class CommunityEditorContainer extends React.Component {
4646
error,
4747
warn,
4848
statusMsg,
49+
isEdit,
4950
} = communityEditor
5051

5152
return (
5253
<Wrapper>
5354
coderplanets
54-
<h2>创建社区</h2>
55+
<h2>
56+
{isEdit ? '编辑' : '创建'}
57+
社区
58+
</h2>
5559
<Divider />
5660
<div>
5761
{communityData.logo ? (

containers/ThemeWrapper/AntOverWrite.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ const AntOverWrite = styled.div`
363363
border: 1px solid #707084;
364364
background: #707084;
365365
}
366+
.ant-tag .anticon-cross {
367+
color: gold;
368+
}
366369
`
367370

368371
export default AntOverWrite

utils/scripts/generators/component/class.js.hbs

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

1010
// import { inject, observer } from 'mobx-react'
1111
// import Link from 'next/link'
12-
// import styled from 'styled-components'
1312

1413
{{#if wantMessages}}
1514
import { FormattedMessage } from 'react-intl'
1615
import messages from './messages'
1716
{{/if}}
1817

19-
// @inject('')
20-
// @observer
2118
class {{ properCase name }} extends React.Component {
2219
componentDidMount() {}
2320

@@ -26,17 +23,18 @@ class {{ properCase name }} extends React.Component {
2623
render() {
2724
return (
2825
<div>
29-
{{#if wantMessages}}
30-
<FormattedMessage {...messages.header} />
31-
{{/if}}
26+
<h3>{{ properCase name }} class component!</h3>
27+
{{#if wantMessages}}
28+
<FormattedMessage {...messages.header} />
29+
{{/if}}
3230
</div>
3331
)
3432
}
3533
}
3634

3735
export default {{ properCase name }}
3836

39-
Index.propTypes = {
37+
{{ properCase name }}.propTypes = {
4038
// https://www.npmjs.com/package/prop-types
4139
}
4240

0 commit comments

Comments
 (0)