From f52dd6c747f04a731381eac088c5051b01d1e918 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 14 Feb 2018 14:09:28 +0100 Subject: [PATCH 1/2] Speed up accounts order dropdown by caching value --- src/components/DashboardPage/AccountsOrder.js | 100 ++++++++++++++++++ src/components/DashboardPage/index.js | 48 +-------- 2 files changed, 104 insertions(+), 44 deletions(-) create mode 100644 src/components/DashboardPage/AccountsOrder.js diff --git a/src/components/DashboardPage/AccountsOrder.js b/src/components/DashboardPage/AccountsOrder.js new file mode 100644 index 00000000..4d6b3e5b --- /dev/null +++ b/src/components/DashboardPage/AccountsOrder.js @@ -0,0 +1,100 @@ +// @flow + +import React, { Component } from 'react' +import { compose } from 'redux' +import { translate } from 'react-i18next' +import { connect } from 'react-redux' + +import type { MapStateToProps } from 'react-redux' + +import type { T } from 'types/common' + +import { getOrderAccounts } from 'reducers/settings' + +import { updateOrderAccounts } from 'actions/accounts' +import { saveSettings } from 'actions/settings' + +import Box from 'components/base/Box' +import DropDown from 'components/base/DropDown' +import Text from 'components/base/Text' +import IconAngleDown from 'icons/AngleDown' + +const mapStateToProps: MapStateToProps<*, *, *> = state => ({ + orderAccounts: getOrderAccounts(state), +}) + +const mapDispatchToProps = { + updateOrderAccounts, + saveSettings, +} + +type Props = { + t: T, + orderAccounts: string, + updateOrderAccounts: Function, + saveSettings: Function, +} + +type State = { + cachedValue: string | null, +} + +class AccountsOrder extends Component { + state = { + cachedValue: null, + } + + componentWillMount() { + this.setState({ cachedValue: this.props.orderAccounts }) + } + + setAccountOrder = order => { + const { updateOrderAccounts, saveSettings } = this.props + this.setState({ cachedValue: order }, () => { + window.requestIdleCallback(() => { + updateOrderAccounts(order) + saveSettings({ orderAccounts: order }) + }) + }) + } + + render() { + const { t } = this.props + const { cachedValue } = this.state + + if (!cachedValue) { + return null + } + + const sortItems = [ + { + key: 'name', + label: t('orderAccounts.name'), + }, + { + key: 'balance', + label: t('orderAccounts.balance'), + }, + { + key: 'type', + label: t('orderAccounts.type'), + }, + ] + + return ( + this.setAccountOrder(item.key)} + items={sortItems} + ff="Open Sans|SemiBold" + fontSize={4} + > + + {t(`orderAccounts.${cachedValue}`)} + + + + ) + } +} + +export default compose(connect(mapStateToProps, mapDispatchToProps), translate())(AccountsOrder) diff --git a/src/components/DashboardPage/index.js b/src/components/DashboardPage/index.js index 31465fd4..3e4dedfe 100644 --- a/src/components/DashboardPage/index.js +++ b/src/components/DashboardPage/index.js @@ -13,12 +13,11 @@ import sortBy from 'lodash/sortBy' import takeRight from 'lodash/takeRight' import type { MapStateToProps } from 'react-redux' -import type { Accounts, T } from 'types/common' +import type { Accounts } from 'types/common' import { space } from 'styles/theme' import { getVisibleAccounts } from 'reducers/accounts' -import { getOrderAccounts } from 'reducers/settings' import { updateOrderAccounts } from 'actions/accounts' import { saveSettings } from 'actions/settings' @@ -28,16 +27,13 @@ import Box, { Card } from 'components/base/Box' import Pills from 'components/base/Pills' import Text from 'components/base/Text' import TransactionsList from 'components/TransactionsList' -import DropDown from 'components/base/DropDown' - -import IconAngleDown from 'icons/AngleDown' import AccountCard from './AccountCard' import BalanceInfos from './BalanceInfos' +import AccountsOrder from './AccountsOrder' const mapStateToProps: MapStateToProps<*, *, *> = state => ({ accounts: getVisibleAccounts(state), - orderAccounts: getOrderAccounts(state), }) const mapDispatchToProps = { @@ -49,10 +45,6 @@ const mapDispatchToProps = { type Props = { accounts: Accounts, push: Function, - t: T, - updateOrderAccounts: Function, - saveSettings: Function, - orderAccounts: string, } type State = { @@ -136,12 +128,6 @@ class DashboardPage extends PureComponent { return chunk(listAccounts, ACCOUNTS_BY_LINE) } - setAccountOrder = order => { - const { updateOrderAccounts, saveSettings } = this.props - updateOrderAccounts(order) - saveSettings({ orderAccounts: order }) - } - addFakeDatasOnAccounts = () => { const { accounts } = this.props @@ -167,26 +153,11 @@ class DashboardPage extends PureComponent { _timeout = undefined render() { - const { push, accounts, t, orderAccounts } = this.props + const { push, accounts } = this.props const { selectedTime, fakeDatas } = this.state const totalAccounts = accounts.length - const sortItems = [ - { - key: 'name', - label: t('orderAccounts.name'), - }, - { - key: 'balance', - label: t('orderAccounts.balance'), - }, - { - key: 'type', - label: t('orderAccounts.type'), - }, - ] - return ( @@ -249,18 +220,7 @@ class DashboardPage extends PureComponent { {'Sort by'} - this.setAccountOrder(item.key)} - items={sortItems} - ff="Open Sans|SemiBold" - fontSize={4} - value={sortItems.find(s => s.key === orderAccounts)} - > - - {t(`orderAccounts.${orderAccounts}`)} - - - + From 5ba9ed44f7251faabfdb8e79c8345e22f634afe0 Mon Sep 17 00:00:00 2001 From: meriadec Date: Wed, 14 Feb 2018 14:48:54 +0100 Subject: [PATCH 2/2] Fix font sizes and padding on various places --- src/components/AccountPage.js | 49 ++++++++++------------- src/components/Breadcrumb/index.js | 3 +- src/components/SettingsPage/Profile.js | 2 +- src/components/SettingsPage/index.js | 4 +- src/components/base/Button/index.js | 2 +- src/components/base/Label.js | 2 +- src/components/base/Modal/index.js | 8 ++-- src/components/base/Tabs/index.js | 2 +- src/components/modals/AddAccount/index.js | 2 +- src/components/modals/Send.js | 4 +- 10 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/components/AccountPage.js b/src/components/AccountPage.js index 31fb102b..6158c4b8 100644 --- a/src/components/AccountPage.js +++ b/src/components/AccountPage.js @@ -52,36 +52,31 @@ class AccountPage extends PureComponent { - {account.name} + {account.name} - - - - - - + - - - +