Skip to content

Commit

Permalink
🎨 Improving format of the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zuiidea committed Jul 6, 2019
1 parent fe95409 commit ea5ee96
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 50 deletions.
6 changes: 4 additions & 2 deletions src/layouts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ class Layout extends Component {
}

loadCatalog = async language => {
const catalog = await import(/* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */
`@lingui/loader!../locales/${language}/messages.json`)
const catalog = await import(
/* webpackMode: "lazy", webpackChunkName: "i18n-[index]" */
`@lingui/loader!../locales/${language}/messages.json`
)

this.setState(state => ({
catalogs: {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/dashboard/components/numberCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function NumberCard({ icon, color, title, number, countUp }) {
useEasing
useGrouping
separator=","
{...countUp || {}}
{...(countUp || {})}
/>
</p>
</div>
Expand Down
35 changes: 21 additions & 14 deletions src/pages/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ const EnumPostStatus = {
@withI18n()
@connect(({ post, loading }) => ({ post, loading }))
class Post extends PureComponent {
render() {
const { post, loading, location, i18n } = this.props
handleTabClick = key => {
const { pathname } = this.props.location

router.push({
pathname,
search: stringify({
status: key,
}),
})
}

get listProps() {
const { post, loading, location } = this.props
const { list, pagination } = post
const { query, pathname } = location

const listProps = {
return {
pagination,
dataSource: list,
loading: loading.effects['post/query'],
Expand All @@ -38,15 +49,11 @@ class Post extends PureComponent {
})
},
}
}

const handleTabClick = key => {
router.push({
pathname,
search: stringify({
status: key,
}),
})
}
render() {
const { location, i18n } = this.props
const { query } = location

return (
<Page inner>
Expand All @@ -56,19 +63,19 @@ class Post extends PureComponent {
? String(EnumPostStatus.UNPUBLISH)
: String(EnumPostStatus.PUBLISHED)
}
onTabClick={handleTabClick}
onTabClick={this.handleTabClick}
>
<TabPane
tab={i18n.t`Publised`}
key={String(EnumPostStatus.PUBLISHED)}
>
<List {...listProps} />
<List {...this.listProps} />
</TabPane>
<TabPane
tab={i18n.t`Unpublished`}
key={String(EnumPostStatus.UNPUBLISH)}
>
<List {...listProps} />
<List {...this.listProps} />
</TabPane>
</Tabs>
</Page>
Expand Down
76 changes: 43 additions & 33 deletions src/pages/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,30 @@ class User extends PureComponent {
})
}

render() {
const { location, dispatch, user, loading, i18n } = this.props
const { query } = location
const {
list,
pagination,
currentItem,
modalVisible,
modalType,
selectedRowKeys,
} = user
handleDeleteItems = () => {
const { dispatch, user } = this.props
const { list, pagination, selectedRowKeys } = user

const modalProps = {
dispatch({
type: 'user/multiDelete',
payload: {
ids: selectedRowKeys,
},
}).then(() => {
this.handleRefresh({
page:
list.length === selectedRowKeys.length && pagination.current > 1
? pagination.current - 1
: pagination.current,
})
})
}

get modalProps() {
const { dispatch, user, loading, i18n } = this.props
const { currentItem, modalVisible, modalType } = user

return {
item: modalType === 'create' ? {} : currentItem,
visible: modalVisible,
destroyOnClose: true,
Expand All @@ -65,8 +76,13 @@ class User extends PureComponent {
})
},
}
}

get listProps() {
const { dispatch, user, loading } = this.props
const { list, pagination, selectedRowKeys } = user

const listProps = {
return {
dataSource: list,
loading: loading.effects['user/query'],
pagination,
Expand Down Expand Up @@ -110,8 +126,13 @@ class User extends PureComponent {
},
},
}
}

get filterProps() {
const { location, dispatch } = this.props
const { query } = location

const filterProps = {
return {
filter: {
...query,
},
Expand All @@ -129,34 +150,23 @@ class User extends PureComponent {
})
},
}
}

const handleDeleteItems = () => {
dispatch({
type: 'user/multiDelete',
payload: {
ids: selectedRowKeys,
},
}).then(() => {
this.handleRefresh({
page:
list.length === selectedRowKeys.length && pagination.current > 1
? pagination.current - 1
: pagination.current,
})
})
}
render() {
const { user } = this.props
const { selectedRowKeys } = user

return (
<Page inner>
<Filter {...filterProps} />
<Filter {...this.filterProps} />
{selectedRowKeys.length > 0 && (
<Row style={{ marginBottom: 24, textAlign: 'right', fontSize: 13 }}>
<Col>
{`Selected ${selectedRowKeys.length} items `}
<Popconfirm
title="Are you sure delete these items?"
placement="left"
onConfirm={handleDeleteItems}
onConfirm={this.handleDeleteItems}
>
<Button type="primary" style={{ marginLeft: 8 }}>
Remove
Expand All @@ -165,8 +175,8 @@ class User extends PureComponent {
</Col>
</Row>
)}
<List {...listProps} />
<Modal {...modalProps} />
<List {...this.listProps} />
<Modal {...this.modalProps} />
</Page>
)
}
Expand Down

0 comments on commit ea5ee96

Please sign in to comment.