From ea5ee96bdc68d507660e8532a3da1d0c8f887b67 Mon Sep 17 00:00:00 2001
From: zuiidea
Date: Sat, 6 Jul 2019 11:02:56 +0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=20Improving=20format=20of=20the?=
=?UTF-8?q?=20code.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/layouts/index.js | 6 +-
src/pages/dashboard/components/numberCard.js | 2 +-
src/pages/post/index.js | 35 +++++----
src/pages/user/index.js | 76 +++++++++++---------
4 files changed, 69 insertions(+), 50 deletions(-)
diff --git a/src/layouts/index.js b/src/layouts/index.js
index 8d075dd..55ea725 100644
--- a/src/layouts/index.js
+++ b/src/layouts/index.js
@@ -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: {
diff --git a/src/pages/dashboard/components/numberCard.js b/src/pages/dashboard/components/numberCard.js
index df1f811..8a9f578 100644
--- a/src/pages/dashboard/components/numberCard.js
+++ b/src/pages/dashboard/components/numberCard.js
@@ -22,7 +22,7 @@ function NumberCard({ icon, color, title, number, countUp }) {
useEasing
useGrouping
separator=","
- {...countUp || {}}
+ {...(countUp || {})}
/>
diff --git a/src/pages/post/index.js b/src/pages/post/index.js
index e71a90a..f51152d 100644
--- a/src/pages/post/index.js
+++ b/src/pages/post/index.js
@@ -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'],
@@ -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 (
@@ -56,19 +63,19 @@ class Post extends PureComponent {
? String(EnumPostStatus.UNPUBLISH)
: String(EnumPostStatus.PUBLISHED)
}
- onTabClick={handleTabClick}
+ onTabClick={this.handleTabClick}
>
-
+
-
+
diff --git a/src/pages/user/index.js b/src/pages/user/index.js
index f510fe6..003f7f5 100644
--- a/src/pages/user/index.js
+++ b/src/pages/user/index.js
@@ -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,
@@ -65,8 +76,13 @@ class User extends PureComponent {
})
},
}
+ }
- const listProps = {
+ get listProps() {
+ const { dispatch, user, loading } = this.props
+ const { list, pagination, selectedRowKeys } = user
+
+ return {
dataSource: list,
loading: loading.effects['user/query'],
pagination,
@@ -110,8 +126,13 @@ class User extends PureComponent {
},
},
}
+ }
- const filterProps = {
+ get filterProps() {
+ const { location, dispatch } = this.props
+ const { query } = location
+
+ return {
filter: {
...query,
},
@@ -129,26 +150,15 @@ 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 (
-
+
{selectedRowKeys.length > 0 && (
@@ -156,7 +166,7 @@ class User extends PureComponent {
)}
-
-
+
+
)
}