|
| 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 | +} |
0 commit comments